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