summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-01-13 11:50:38 +0100
committerantirez <antirez@gmail.com>2014-01-13 16:39:51 +0100
commitb8db8a0c4812b5db9573b19a9b05b4182dc94561 (patch)
tree92ef7e59d80bb182d1bf942b6d31b0651c4f2122
parent8ed0b49525b8e0c790317b076330a8ead24f90c4 (diff)
downloadredis-b8db8a0c4812b5db9573b19a9b05b4182dc94561.tar.gz
SENTINEL SET implemented.
The new command allows to change master-specific configurations at runtime. All the settable parameters can be retrivied via the SENTINEL MASTER command, so there is no equivalent "GET" command.
-rw-r--r--src/sentinel.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/sentinel.c b/src/sentinel.c
index 940cc0b11..3658c6162 100644
--- a/src/sentinel.c
+++ b/src/sentinel.c
@@ -370,6 +370,7 @@ dictType leaderVotesDictType = {
void sentinelCommand(redisClient *c);
void sentinelInfoCommand(redisClient *c);
+void sentinelSetCommand(redisClient *c);
struct redisCommand sentinelcmds[] = {
{"ping",pingCommand,1,"",0,NULL,0,0,0,0,0},
@@ -2532,6 +2533,9 @@ void sentinelCommand(redisClient *c) {
dictDelete(sentinel.masters,c->argv[2]->ptr);
sentinelFlushConfig();
addReply(c,shared.ok);
+ } else if (!strcasecmp(c->argv[1]->ptr,"set")) {
+ if (c->argc < 3 || c->argc % 2 == 0) goto numargserr;
+ sentinelSetCommand(c);
} else {
addReplyErrorFormat(c,"Unknown sentinel subcommand '%s'",
(char*)c->argv[1]->ptr);
@@ -2543,6 +2547,7 @@ numargserr:
(char*)c->argv[1]->ptr);
}
+/* SENTINEL INFO [section] */
void sentinelInfoCommand(redisClient *c) {
char *section = c->argc == 2 ? c->argv[1]->ptr : "default";
sds info = sdsempty();
@@ -2602,6 +2607,79 @@ void sentinelInfoCommand(redisClient *c) {
addReply(c,shared.crlf);
}
+/* SENTINEL SET <mastername> [<option> <value> ...] */
+void sentinelSetCommand(redisClient *c) {
+ sentinelRedisInstance *ri;
+ int j, changes = 0;
+ char *option, *value;
+
+ if ((ri = sentinelGetMasterByNameOrReplyError(c,c->argv[2]))
+ == NULL) return;
+
+ /* Process option - value pairs. */
+ for (j = 3; j < c->argc; j += 2) {
+ option = c->argv[j]->ptr;
+ value = c->argv[j+1]->ptr;
+ robj *o = c->argv[j+1];
+ long long ll;
+
+ if (!strcasecmp(option,"down-after-milliseconds")) {
+ /* down-after-millisecodns <milliseconds> */
+ if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0)
+ goto badfmt;
+ ri->down_after_period = ll;
+ changes++;
+ } else if (!strcasecmp(option,"failover-timeout")) {
+ /* failover-timeout <milliseconds> */
+ if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0)
+ goto badfmt;
+ ri->failover_timeout = ll;
+ changes++;
+ } else if (!strcasecmp(option,"parallel-syncs")) {
+ /* parallel-syncs <milliseconds> */
+ if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0)
+ goto badfmt;
+ ri->parallel_syncs = ll;
+ changes++;
+ } else if (!strcasecmp(option,"notification-script")) {
+ /* notification-script <path> */
+ if (strlen(value) && access(value,X_OK) == -1) {
+ addReplyError(c,
+ "Notification script seems non existing or non executable");
+ return;
+ }
+ sdsfree(ri->notification_script);
+ ri->notification_script = strlen(value) ? sdsnew(value) : NULL;
+ changes++;
+ } else if (!strcasecmp(option,"client-reconfig-script")) {
+ /* client-reconfig-script <path> */
+ if (strlen(value) && access(value,X_OK) == -1) {
+ addReplyError(c,
+ "Client reconfiguration script seems non existing or "
+ "non executable");
+ return;
+ }
+ sdsfree(ri->client_reconfig_script);
+ ri->client_reconfig_script = strlen(value) ? sdsnew(value) : NULL;
+ changes++;
+ } else if (!strcasecmp(option,"auth-pass")) {
+ /* auth-pass <password> */
+ sdsfree(ri->auth_pass);
+ ri->auth_pass = strlen(value) ? sdsnew(value) : NULL;
+ changes++;
+ }
+ }
+
+ if (changes) sentinelFlushConfig();
+ addReply(c,shared.ok);
+ return;
+
+badfmt: /* Bad format errors */
+ if (changes) sentinelFlushConfig();
+ addReplyErrorFormat(c,"Invalid argument '%s' for SENTINEL SET '%s'",
+ value, option);
+}
+
/* ===================== SENTINEL availability checks ======================= */
/* Is this instance down from our point of view? */