From 3b7a7574685f184b9c88e8aed5f97e07265f21ec Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 24 Feb 2014 16:25:34 +0100 Subject: [PATCH] Sentinel: log +monitor and +set events. Now that we have a runtime configuration system, it is very important to be able to log how the Sentinel configuration changes over time because of API calls. --- src/sentinel.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/sentinel.c b/src/sentinel.c index 06f54b52..22fe7caf 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -2503,6 +2503,7 @@ void sentinelCommand(redisClient *c) { sentinelPendingScriptsCommand(c); } else if (!strcasecmp(c->argv[1]->ptr,"monitor")) { /* SENTINEL MONITOR */ + sentinelRedisInstance *ri; long quorum, port; char buf[32]; @@ -2518,9 +2519,11 @@ void sentinelCommand(redisClient *c) { addReplyError(c,"Invalid IP address specified"); return; } - if (createSentinelRedisInstance(c->argv[2]->ptr,SRI_MASTER, - c->argv[3]->ptr,port,quorum,NULL) == NULL) - { + + /* Parameters are valid. Try to create the master instance. */ + ri = createSentinelRedisInstance(c->argv[2]->ptr,SRI_MASTER, + c->argv[3]->ptr,port,quorum,NULL); + if (ri == NULL) { switch(errno) { case EBUSY: addReplyError(c,"Duplicated master name"); @@ -2534,6 +2537,7 @@ void sentinelCommand(redisClient *c) { } } else { sentinelFlushConfig(); + sentinelEvent(REDIS_WARNING,"+monitor",ri,"%@"); addReply(c,shared.ok); } } else if (!strcasecmp(c->argv[1]->ptr,"remove")) { @@ -2542,6 +2546,7 @@ void sentinelCommand(redisClient *c) { if ((ri = sentinelGetMasterByNameOrReplyError(c,c->argv[2])) == NULL) return; + sentinelEvent(REDIS_WARNING,"-monitor",ri,"%@"); dictDelete(sentinel.masters,c->argv[2]->ptr); sentinelFlushConfig(); addReply(c,shared.ok); @@ -2693,6 +2698,7 @@ void sentinelSetCommand(redisClient *c) { if (changes) sentinelFlushConfig(); return; } + sentinelEvent(REDIS_WARNING,"+set",ri,"%@ %s %s",option,value); } if (changes) sentinelFlushConfig();