fup
This commit is contained in:
@ -9,12 +9,13 @@
|
||||
{{- $fqdn := printf "%s.%s" $hostname $domain }}
|
||||
{{- $hostid := sha1sum $hostname }}
|
||||
{{- $quorum := env "VALKEY_QUORUM" }}
|
||||
{{- $master_name := env "VALKEY_MASTER_NAME" }}
|
||||
#-REPLICAS:{{ $replicas }}
|
||||
|
||||
dir "/tmp"
|
||||
port {{ $sentinel_port }}
|
||||
sentinel monitor mymaster SENTINEL_MASTER {{ $port }} {{ $quorum }}
|
||||
sentinel down-after-milliseconds mymaster 60000
|
||||
sentinel monitor {{ $master_name }} SENTINEL_MASTER {{ $port }} {{ $quorum }}
|
||||
sentinel down-after-milliseconds {{ $master_name }} 60000
|
||||
|
||||
# User-supplied sentinel configuration:
|
||||
# End of sentinel configuration
|
||||
@ -32,8 +33,8 @@ protected-mode no
|
||||
# gotemplate-pause!
|
||||
user default on nopass sanitize-payload ~* &* +@all
|
||||
# gotemplate-resume!
|
||||
sentinel config-epoch mymaster 0
|
||||
sentinel leader-epoch mymaster 0
|
||||
sentinel config-epoch {{ $master_name }} 0
|
||||
sentinel leader-epoch {{ $master_name }} 0
|
||||
sentinel current-epoch 0
|
||||
|
||||
{{- range $i, $e := until ( int $replicas ) }}
|
||||
@ -41,7 +42,7 @@ sentinel current-epoch 0
|
||||
{{- $ndeFQDN := printf "%s.%s" $ndeHostname $domain }}
|
||||
{{- $nodeID := sha1sum $ndeHostname }}
|
||||
{{- if (ne $fqdn $ndeFQDN) }}
|
||||
sentinel {{ printf "known-sentinel mymaster %s %s %s" $ndeFQDN $sentinel_port $nodeID }}
|
||||
sentinel {{ printf "known-replica mymaster %s %s" $ndeFQDN $port }}
|
||||
sentinel {{ printf "known-sentinel {{ $master_name }} %s %s %s" $ndeFQDN $sentinel_port $nodeID }}
|
||||
sentinel {{ printf "known-replica {{ $master_name }} %s %s" $ndeFQDN $port }}
|
||||
{{- end}}
|
||||
{{- end}}
|
@ -15,7 +15,8 @@ pingSentinel() {
|
||||
}
|
||||
|
||||
getPrimaryInfo() {
|
||||
valkey-cli --csv -h ${VALKEY_HEADLESS_SERVICE} -p ${VALKEY_SENTINEL_PORT} sentinel get-primary-addr-by-name "mymaster"| \
|
||||
VALKEY_MASTER_NAME=${VALKEY_PRIMARY_NAME:-"mymaster"}
|
||||
valkey-cli --csv -h ${VALKEY_HEADLESS_SERVICE} -p ${VALKEY_SENTINEL_PORT} sentinel get-primary-addr-by-name "${VALKEY_MASTER_NAME}"| \
|
||||
awk -F ',' '{ gsub(/"/,"",$0); print $1 " " $2 }'
|
||||
return ${?}
|
||||
}
|
||||
|
@ -15,7 +15,8 @@ vcli-sentinel() {
|
||||
getFailOverStatus() {
|
||||
# Check if the failover is finished
|
||||
local failoverStatus
|
||||
primaryInfo=$(vcli-sentinel get-primary-addr-by-name "mymaster")
|
||||
sentinelMasterName="${VALKEY_MASTER_NAME:-"mymaster"}"
|
||||
primaryInfo=$(vcli-sentinel get-primary-addr-by-name "${sentinelMasterName}")
|
||||
primaryHost=$(echo ${primaryInfo} | awk -F ' ' '{print $1}')
|
||||
currentHost=$(hostname -f)
|
||||
if [[ "${primaryHost}" != "${currentHost}" ]]; then
|
||||
@ -44,12 +45,13 @@ isPrimary() {
|
||||
}
|
||||
|
||||
if isPrimary && ! getFailOverStatus; then
|
||||
sentinelMasterName="${VALKEY_MASTER_NAME}"
|
||||
echo "I'm the primary and you are stopping me, pausing client connections"
|
||||
#Pausing write connections to avoid data loss"
|
||||
vcli CLIENT PAUSE "22000" WRITE
|
||||
|
||||
echo "Starting failover"
|
||||
vcli-sentinel failover "mymaster"
|
||||
vcli-sentinel failover "${sentinelMasterName}"
|
||||
echo "Waiting for sentinel to complete failover for up to 120s"
|
||||
tmout=120
|
||||
while true ; do
|
||||
|
@ -12,7 +12,8 @@ pingSentinel() {
|
||||
}
|
||||
|
||||
getPrimaryInfo() {
|
||||
valkey-cli -t 15 --csv -h ${VALKEY_HEADLESS_SERVICE} -p ${VALKEY_SENTINEL_PORT} sentinel get-primary-addr-by-name "mymaster"| \
|
||||
sentinelMasterName="${VALKEY_PRIMARY_NAME:-"mymaster"}"
|
||||
valkey-cli -t 15 --csv -h ${VALKEY_HEADLESS_SERVICE} -p ${VALKEY_SENTINEL_PORT} sentinel get-primary-addr-by-name "${sentinelMasterName}"| \
|
||||
awk -F ',' '{ gsub(/"/,"",$0); print $1 " " $2 }'
|
||||
return ${?}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ configMapGenerator:
|
||||
# - VALKEY_NAME="valkey-node"
|
||||
# - VALKEY_SERVICE="valkey-node"
|
||||
# - VALKEY_HEADLESS_SERVICE="valkey-node-headless"
|
||||
# - VALKEY_MASTER_NAME="vlmaster"
|
||||
# - VALKEY_REPLICAS="4"
|
||||
# - VALKEY_PORT="6379"
|
||||
# - VALKEY_SENTINEL_PORT="26379"
|
||||
|
Reference in New Issue
Block a user