mirror of
https://github.com/fluencelabs/redis
synced 2025-03-30 22:31:03 +00:00
Sentinel: announce ip/port changes + rewrite.
The original implementation was modified in order to allow to selectively announce a different IP or port, and to rewrite the two options in the config file after a rewrite.
This commit is contained in:
parent
3d939266be
commit
cd576a1aab
@ -1415,7 +1415,7 @@ void rewriteConfigStringOption(struct rewriteConfigState *state, char *option, c
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compare the strings as sds strings to have a binary safe comparison. */
|
/* Set force to zero if the value is set to its default. */
|
||||||
if (defvalue && strcmp(value,defvalue) == 0) force = 0;
|
if (defvalue && strcmp(value,defvalue) == 0) force = 0;
|
||||||
|
|
||||||
line = sdsnew(option);
|
line = sdsnew(option);
|
||||||
|
@ -203,7 +203,10 @@ struct sentinelState {
|
|||||||
mstime_t tilt_start_time; /* When TITL started. */
|
mstime_t tilt_start_time; /* When TITL started. */
|
||||||
mstime_t previous_time; /* Last time we ran the time handler. */
|
mstime_t previous_time; /* Last time we ran the time handler. */
|
||||||
list *scripts_queue; /* Queue of user scripts to execute. */
|
list *scripts_queue; /* Queue of user scripts to execute. */
|
||||||
sentinelAddr *announce_addr; /* Address that is gossiped to other sentinels. */
|
char *announce_ip; /* IP addr that is gossiped to other sentinels if
|
||||||
|
not NULL. */
|
||||||
|
int announce_port; /* Port that is gossiped to other sentinels if
|
||||||
|
non zero. */
|
||||||
} sentinel;
|
} sentinel;
|
||||||
|
|
||||||
/* A script execution job. */
|
/* A script execution job. */
|
||||||
@ -426,7 +429,8 @@ void initSentinel(void) {
|
|||||||
sentinel.previous_time = mstime();
|
sentinel.previous_time = mstime();
|
||||||
sentinel.running_scripts = 0;
|
sentinel.running_scripts = 0;
|
||||||
sentinel.scripts_queue = listCreate();
|
sentinel.scripts_queue = listCreate();
|
||||||
sentinel.announce_addr = NULL;
|
sentinel.announce_ip = NULL;
|
||||||
|
sentinel.announce_port = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function gets called when the server is in Sentinel mode, started,
|
/* This function gets called when the server is in Sentinel mode, started,
|
||||||
@ -1427,12 +1431,12 @@ char *sentinelHandleConfiguration(char **argv, int argc) {
|
|||||||
return "Wrong hostname or port for sentinel.";
|
return "Wrong hostname or port for sentinel.";
|
||||||
}
|
}
|
||||||
if (argc == 5) si->runid = sdsnew(argv[4]);
|
if (argc == 5) si->runid = sdsnew(argv[4]);
|
||||||
} else if (!strcasecmp(argv[0],"announce") && argc == 2) {
|
} else if (!strcasecmp(argv[0],"announce-ip") && argc == 2) {
|
||||||
/* announce <host> */
|
/* announce-ip <ip-address> */
|
||||||
sentinel.announce_addr = createSentinelAddr(argv[1], server.port);
|
sentinel.announce_ip = sdsnew(argv[1]);
|
||||||
if (sentinel.announce_addr == NULL) {
|
} else if (!strcasecmp(argv[0],"announce-port") && argc == 2) {
|
||||||
return "Unable to resolve host.";
|
/* announce-port <port> */
|
||||||
}
|
sentinel.announce_port = atoi(argv[1]);
|
||||||
} else {
|
} else {
|
||||||
return "Unrecognized sentinel configuration statement.";
|
return "Unrecognized sentinel configuration statement.";
|
||||||
}
|
}
|
||||||
@ -1564,6 +1568,20 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state) {
|
|||||||
"sentinel current-epoch %llu", (unsigned long long) sentinel.current_epoch);
|
"sentinel current-epoch %llu", (unsigned long long) sentinel.current_epoch);
|
||||||
rewriteConfigRewriteLine(state,"sentinel",line,1);
|
rewriteConfigRewriteLine(state,"sentinel",line,1);
|
||||||
|
|
||||||
|
/* sentinel announce-ip. */
|
||||||
|
if (sentinel.announce_ip) {
|
||||||
|
line = sdsnew("sentinel announce-ip ");
|
||||||
|
line = sdscatrepr(line, sentinel.announce_ip, sdslen(sentinel.announce_ip));
|
||||||
|
rewriteConfigRewriteLine(state,"sentinel",line,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* sentinel announce-port. */
|
||||||
|
if (sentinel.announce_port) {
|
||||||
|
line = sdscatprintf(sdsempty(),"sentinel announce-port %d",
|
||||||
|
sentinel.announce_port);
|
||||||
|
rewriteConfigRewriteLine(state,"sentinel",line,1);
|
||||||
|
}
|
||||||
|
|
||||||
dictReleaseIterator(di);
|
dictReleaseIterator(di);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2221,8 +2239,8 @@ int sentinelSendHello(sentinelRedisInstance *ri) {
|
|||||||
char ip[REDIS_IP_STR_LEN];
|
char ip[REDIS_IP_STR_LEN];
|
||||||
char payload[REDIS_IP_STR_LEN+1024];
|
char payload[REDIS_IP_STR_LEN+1024];
|
||||||
int retval;
|
int retval;
|
||||||
char *announceIP;
|
char *announce_ip;
|
||||||
int port;
|
int announce_port;
|
||||||
sentinelRedisInstance *master = (ri->flags & SRI_MASTER) ? ri : ri->master;
|
sentinelRedisInstance *master = (ri->flags & SRI_MASTER) ? ri : ri->master;
|
||||||
sentinelAddr *master_addr = sentinelGetCurrentMasterAddress(master);
|
sentinelAddr *master_addr = sentinelGetCurrentMasterAddress(master);
|
||||||
|
|
||||||
@ -2230,21 +2248,21 @@ int sentinelSendHello(sentinelRedisInstance *ri) {
|
|||||||
|
|
||||||
/* Use the specified announce address if specified, otherwise try to
|
/* Use the specified announce address if specified, otherwise try to
|
||||||
* obtain our own IP address. */
|
* obtain our own IP address. */
|
||||||
if (sentinel.announce_addr) {
|
if (sentinel.announce_ip) {
|
||||||
announceIP = sentinel.announce_addr->ip;
|
announce_ip = sentinel.announce_ip;
|
||||||
port = sentinel.announce_addr->port;
|
|
||||||
} else {
|
} else {
|
||||||
if (anetSockName(ri->cc->c.fd,ip,sizeof(ip),NULL) == -1)
|
if (anetSockName(ri->cc->c.fd,ip,sizeof(ip),NULL) == -1)
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
announceIP = ip;
|
announce_ip = ip;
|
||||||
port = server.port;
|
|
||||||
}
|
}
|
||||||
|
announce_port = sentinel.announce_port ?
|
||||||
|
sentinel.announce_port : server.port;
|
||||||
|
|
||||||
/* Format and send the Hello message. */
|
/* Format and send the Hello message. */
|
||||||
snprintf(payload,sizeof(payload),
|
snprintf(payload,sizeof(payload),
|
||||||
"%s,%d,%s,%llu," /* Info about this sentinel. */
|
"%s,%d,%s,%llu," /* Info about this sentinel. */
|
||||||
"%s,%s,%d,%llu", /* Info about current master. */
|
"%s,%s,%d,%llu", /* Info about current master. */
|
||||||
announceIP, port, server.runid,
|
announce_ip, announce_port, server.runid,
|
||||||
(unsigned long long) sentinel.current_epoch,
|
(unsigned long long) sentinel.current_epoch,
|
||||||
/* --- */
|
/* --- */
|
||||||
master->name,master_addr->ip,master_addr->port,
|
master->name,master_addr->ip,master_addr->port,
|
||||||
@ -2253,8 +2271,6 @@ int sentinelSendHello(sentinelRedisInstance *ri) {
|
|||||||
sentinelPublishReplyCallback, NULL, "PUBLISH %s %s",
|
sentinelPublishReplyCallback, NULL, "PUBLISH %s %s",
|
||||||
SENTINEL_HELLO_CHANNEL,payload);
|
SENTINEL_HELLO_CHANNEL,payload);
|
||||||
if (retval != REDIS_OK) return REDIS_ERR;
|
if (retval != REDIS_OK) return REDIS_ERR;
|
||||||
redisLog(REDIS_DEBUG, "Sentinel Send Hello ip=%s, port=%d, id=%s, epoch=%llu",
|
|
||||||
announceIP, port, server.runid, (unsigned long long) sentinel.current_epoch);
|
|
||||||
ri->pending_commands++;
|
ri->pending_commands++;
|
||||||
return REDIS_OK;
|
return REDIS_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user