Sentinel: Redis-side support for slave priority.
A Redis slave can now be configured with a priority, that is an integer number that is shown in INFO output and can be get and set using the redis.conf file or the CONFIG GET/SET command. This field is used by Sentinel during slave election. A slave with lower priority is preferred. A slave with priority zero is never elected (and is considered to be impossible to elect even if it is the only slave available). A next commit will add support in the Sentinel side as well.
This commit is contained in:
parent
96fbd4333f
commit
dfdbb2272d
11
src/config.c
11
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;
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user