diff --git a/src/config.c b/src/config.c index 1be88f5a..04f3dea7 100644 --- a/src/config.c +++ b/src/config.c @@ -333,6 +333,8 @@ void loadServerConfig(char *filename) { server.slowlog_log_slower_than = strtoll(argv[1],NULL,10); } else if (!strcasecmp(argv[0],"slowlog-max-len") && argc == 2) { server.slowlog_max_len = strtoll(argv[1],NULL,10); + } else if (!strcasecmp(argv[0],"slave-priority") && argc == 2) { + server.slave_priority = atoi(argv[1]); } else { err = "Bad directive or wrong number of arguments"; goto loaderr; } @@ -531,6 +533,10 @@ void configSetCommand(redisClient *c) { } else { goto badfmt; } + } else if (!strcasecmp(c->argv[2]->ptr,"slave-priority")) { + if (getLongLongFromObject(o,&ll) == REDIS_ERR || + ll <= 0) goto badfmt; + server.slave_priority = ll; } else { addReplyErrorFormat(c,"Unsupported CONFIG parameter: %s", (char*)c->argv[2]->ptr); @@ -711,6 +717,11 @@ void configGetCommand(redisClient *c) { addReplyBulkLongLong(c,server.slowlog_max_len); matches++; } + if (stringmatch(pattern,"slave-priority",0)) { + addReplyBulkCString(c,"slave-priority"); + addReplyBulkLongLong(c,server.slave_priority); + matches++; + } if (stringmatch(pattern,"loglevel",0)) { char *s; diff --git a/src/redis.c b/src/redis.c index f4355544..1211fd18 100644 --- a/src/redis.c +++ b/src/redis.c @@ -877,6 +877,7 @@ void initServerConfig() { server.repl_syncio_timeout = REDIS_REPL_SYNCIO_TIMEOUT; server.repl_serve_stale_data = 1; server.repl_down_since = time(NULL); + server.slave_priority = REDIS_DEFAULT_SLAVE_PRIORITY; /* Double constants initialization */ R_Zero = 0.0; @@ -1440,6 +1441,8 @@ sds genRedisInfoString(void) { "master_link_down_since_seconds:%ld\r\n", (long)time(NULL)-server.repl_down_since); } + info = sdscatprintf(info, + "slave_priority:%d\r\n", server.slave_priority); } if (server.vm_enabled) { diff --git a/src/redis.h b/src/redis.h index 5eb67adf..27062504 100644 --- a/src/redis.h +++ b/src/redis.h @@ -62,6 +62,7 @@ #define REDIS_REPL_PING_SLAVE_PERIOD 10 #define REDIS_RUN_ID_SIZE 40 +#define REDIS_DEFAULT_SLAVE_PRIORITY 100 /* Hash table parameters */ #define REDIS_HT_MINFILL 10 /* Minimal hash table fill 10% */ @@ -479,6 +480,7 @@ struct redisServer { time_t repl_transfer_lastio; /* unix time of the latest read, for timeout */ int repl_serve_stale_data; /* Serve stale data when link is down? */ time_t repl_down_since; /* unix time at which link with master went down */ + int slave_priority; /* Reported in INFO and used by Sentinel. */ /* Limits */ unsigned int maxclients; unsigned long long maxmemory;