Apply Sentinel runtime configuration API introduced on Redis 2.8.4

* Implements new sentinel commands (failover, monitor, remove, set) 
* unit test included
** added 2 redis-server and 1 sentinel for failover test
* with some refactoring
** SentinelCommands : refactor to have interface
** HostAndPortUtil : same format to cluster setup
This commit is contained in:
Jungtaek Lim
2014-01-22 00:23:40 +09:00
parent 01842e4731
commit a50cf3b15e
8 changed files with 244 additions and 65 deletions

View File

@@ -65,6 +65,29 @@ appendonly no
slaveof localhost 6379
endef
define REDIS7_CONF
daemonize yes
port 6385
requirepass foobared
masterauth foobared
pidfile /tmp/redis7.pid
logfile /tmp/redis7.log
save ""
appendonly no
endef
define REDIS8_CONF
daemonize yes
port 6386
requirepass foobared
masterauth foobared
pidfile /tmp/redis8.pid
logfile /tmp/redis8.log
save ""
appendonly no
slaveof localhost 6385
endef
# SENTINELS
define REDIS_SENTINEL1
port 26379
@@ -102,6 +125,18 @@ pidfile /tmp/sentinel3.pid
logfile /tmp/sentinel3.log
endef
define REDIS_SENTINEL4
port 26382
daemonize yes
sentinel monitor mymasterfailover 127.0.0.1 6385 1
sentinel auth-pass mymasterfailover foobared
sentinel down-after-milliseconds mymasterfailover 3000
sentinel failover-timeout mymasterfailover 900000
sentinel parallel-syncs mymasterfailover 1
pidfile /tmp/sentinel4.pid
logfile /tmp/sentinel4.log
endef
# CLUSTER REDIS NODES
define REDIS_CLUSTER_NODE1_CONF
daemonize yes
@@ -142,9 +177,12 @@ export REDIS3_CONF
export REDIS4_CONF
export REDIS5_CONF
export REDIS6_CONF
export REDIS7_CONF
export REDIS8_CONF
export REDIS_SENTINEL1
export REDIS_SENTINEL2
export REDIS_SENTINEL3
export REDIS_SENTINEL4
export REDIS_CLUSTER_NODE1_CONF
export REDIS_CLUSTER_NODE2_CONF
export REDIS_CLUSTER_NODE3_CONF
@@ -156,17 +194,22 @@ start: cleanup
echo "$$REDIS4_CONF" | redis-server -
echo "$$REDIS5_CONF" | redis-server -
echo "$$REDIS6_CONF" | redis-server -
echo "$$REDIS7_CONF" | redis-server -
echo "$$REDIS8_CONF" | redis-server -
echo "$$REDIS_SENTINEL1" > /tmp/sentinel1.conf && redis-server /tmp/sentinel1.conf --sentinel
@sleep 0.5
echo "$$REDIS_SENTINEL2" > /tmp/sentinel2.conf && redis-server /tmp/sentinel2.conf --sentinel
@sleep 0.5
echo "$$REDIS_SENTINEL3" > /tmp/sentinel3.conf && redis-server /tmp/sentinel3.conf --sentinel
@sleep 0.5
echo "$$REDIS_SENTINEL4" > /tmp/sentinel4.conf && redis-server /tmp/sentinel4.conf --sentinel
echo "$$REDIS_CLUSTER_NODE1_CONF" | redis-server -
echo "$$REDIS_CLUSTER_NODE2_CONF" | redis-server -
echo "$$REDIS_CLUSTER_NODE3_CONF" | redis-server -
cleanup:
rm -vf /tmp/redis_cluster_node*.conf
rm -vf /tmp/sentinel*.conf
stop:
kill `cat /tmp/redis1.pid`
@@ -176,12 +219,19 @@ stop:
kill `cat /tmp/redis4.pid` || true
kill `cat /tmp/redis5.pid` || true
kill `cat /tmp/redis6.pid` || true
kill `cat /tmp/redis7.pid`
kill `cat /tmp/redis8.pid`
kill `cat /tmp/sentinel1.pid`
kill `cat /tmp/sentinel2.pid`
kill `cat /tmp/sentinel3.pid`
kill `cat /tmp/sentinel4.pid`
kill `cat /tmp/redis_cluster_node1.pid` || true
kill `cat /tmp/redis_cluster_node2.pid` || true
kill `cat /tmp/redis_cluster_node3.pid` || true
rm -f /tmp/sentinel1.conf
rm -f /tmp/sentinel2.conf
rm -f /tmp/sentinel3.conf
rm -f /tmp/sentinel4.conf
rm -f /tmp/redis_cluster_node1.conf
rm -f /tmp/redis_cluster_node2.conf
rm -f /tmp/redis_cluster_node3.conf