mirror of
https://github.com/fluencelabs/redis
synced 2025-03-17 16:10:50 +00:00
Sentinel: CONFIG REWRITE support for Sentinel config.
This commit is contained in:
parent
47df12d5d9
commit
5998769c28
@ -1162,6 +1162,10 @@ int dictSdsKeyCompare(void *privdata, const void *key1, const void *key2);
|
||||
void dictSdsDestructor(void *privdata, void *val);
|
||||
void dictListDestructor(void *privdata, void *val);
|
||||
|
||||
/* Sentinel config rewriting is implemented inside sentinel.c by
|
||||
* rewriteConfigSentinelOption(). */
|
||||
void rewriteConfigSentinelOption(struct rewriteConfigState *state);
|
||||
|
||||
dictType optionToLineDictType = {
|
||||
dictSdsHash, /* hash function */
|
||||
NULL, /* key dup */
|
||||
@ -1735,6 +1739,7 @@ int rewriteConfig(char *path) {
|
||||
rewriteConfigClientoutputbufferlimitOption(state);
|
||||
rewriteConfigNumericalOption(state,"hz",server.hz,REDIS_DEFAULT_HZ);
|
||||
rewriteConfigYesNoOption(state,"aof-rewrite-incremental-fsync",server.aof_rewrite_incremental_fsync,REDIS_DEFAULT_AOF_REWRITE_INCREMENTAL_FSYNC);
|
||||
if (server.sentinel_mode) rewriteConfigSentinelOption(state);
|
||||
|
||||
/* Step 3: remove all the orphaned lines in the old file, that is, lines
|
||||
* that were used by a config option and are no longer used, like in case
|
||||
|
@ -1169,6 +1169,8 @@ sds keyspaceEventsFlagsToString(int flags);
|
||||
void loadServerConfig(char *filename, char *options);
|
||||
void appendServerSaveParams(time_t seconds, int changes);
|
||||
void resetServerSaveParams();
|
||||
struct rewriteConfigState; /* Forward declaration to export API. */
|
||||
void rewriteConfigRewriteLine(struct rewriteConfigState *state, char *option, sds line, int force);
|
||||
|
||||
/* db.c -- Keyspace access API */
|
||||
int removeExpire(redisDb *db, robj *key);
|
||||
|
109
src/sentinel.c
109
src/sentinel.c
@ -1303,10 +1303,10 @@ char *sentinelHandleConfiguration(char **argv, int argc) {
|
||||
ri->config_epoch = strtoull(argv[2],NULL,10);
|
||||
if (ri->config_epoch > sentinel.current_epoch)
|
||||
sentinel.current_epoch = ri->config_epoch;
|
||||
} else if (!strcasecmp(argv[0],"slave") && argc == 3) {
|
||||
} else if (!strcasecmp(argv[0],"known-slave") && argc == 3) {
|
||||
sentinelRedisInstance *slave;
|
||||
|
||||
/* slave <name> <ip> <port> */
|
||||
/* known-slave <name> <ip> <port> */
|
||||
ri = sentinelGetMasterByName(argv[1]);
|
||||
if (!ri) return "No such master with specified name.";
|
||||
if ((slave = createSentinelRedisInstance(NULL,SRI_SLAVE,argv[2],
|
||||
@ -1314,10 +1314,10 @@ char *sentinelHandleConfiguration(char **argv, int argc) {
|
||||
{
|
||||
return "Wrong hostname or port for slave.";
|
||||
}
|
||||
} else if (!strcasecmp(argv[0],"sentinel") && argc == 3) {
|
||||
} else if (!strcasecmp(argv[0],"known-sentinel") && argc == 3) {
|
||||
sentinelRedisInstance *si;
|
||||
|
||||
/* sentinel <name> <ip> <port> */
|
||||
/* known-sentinel <name> <ip> <port> */
|
||||
ri = sentinelGetMasterByName(argv[1]);
|
||||
if (!ri) return "No such master with specified name.";
|
||||
if ((si = createSentinelRedisInstance(NULL,SRI_SENTINEL,argv[2],
|
||||
@ -1331,6 +1331,107 @@ char *sentinelHandleConfiguration(char **argv, int argc) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Implements CONFIG REWRITE for "sentinel" option.
|
||||
* This is used not just to rewrite the configuration given by the user
|
||||
* (the configured masters) but also in order to retain the state of
|
||||
* Sentinel across restarts: config epoch of masters, associated slaves
|
||||
* and sentinel instances, and so forth. */
|
||||
void rewriteConfigSentinelOption(struct rewriteConfigState *state) {
|
||||
dictIterator *di, *di2;
|
||||
dictEntry *de;
|
||||
|
||||
/* For every master emit a "sentinel monitor" config entry. */
|
||||
di = dictGetIterator(sentinel.masters);
|
||||
while((de = dictNext(di)) != NULL) {
|
||||
sentinelRedisInstance *master, *ri;
|
||||
sds line;
|
||||
|
||||
/* sentinel monitor */
|
||||
master = dictGetVal(de);
|
||||
line = sdscatprintf(sdsempty(),"sentinel monitor %s %s %d %d",
|
||||
master->name, master->addr->ip, master->addr->port,
|
||||
master->quorum);
|
||||
rewriteConfigRewriteLine(state,"sentinel",line,1);
|
||||
|
||||
/* sentinel down-after-milliseconds */
|
||||
if (master->down_after_period != SENTINEL_DEFAULT_DOWN_AFTER) {
|
||||
line = sdscatprintf(sdsempty(),
|
||||
"sentinel down-after-milliseconds %s %ld",
|
||||
master->name, (long) master->down_after_period);
|
||||
rewriteConfigRewriteLine(state,"sentinel",line,1);
|
||||
}
|
||||
|
||||
/* sentinel failover-timeout */
|
||||
if (master->failover_timeout != SENTINEL_DEFAULT_FAILOVER_TIMEOUT) {
|
||||
line = sdscatprintf(sdsempty(),
|
||||
"sentinel failover-timeout %s %ld",
|
||||
master->name, (long) master->failover_timeout);
|
||||
rewriteConfigRewriteLine(state,"sentinel",line,1);
|
||||
}
|
||||
|
||||
/* sentinel parallel-syncs */
|
||||
if (master->parallel_syncs != SENTINEL_DEFAULT_PARALLEL_SYNCS) {
|
||||
line = sdscatprintf(sdsempty(),
|
||||
"sentinel parallel-syncs %s %d",
|
||||
master->name, master->parallel_syncs);
|
||||
rewriteConfigRewriteLine(state,"sentinel",line,1);
|
||||
}
|
||||
|
||||
/* sentinel notification-script */
|
||||
if (master->notification_script) {
|
||||
line = sdscatprintf(sdsempty(),
|
||||
"sentinel notification-script %s %s",
|
||||
master->name, master->notification_script);
|
||||
rewriteConfigRewriteLine(state,"sentinel",line,1);
|
||||
}
|
||||
|
||||
/* sentinel client-reconfig-script */
|
||||
if (master->client_reconfig_script) {
|
||||
line = sdscatprintf(sdsempty(),
|
||||
"sentinel client-reconfig-script %s %s",
|
||||
master->name, master->client_reconfig_script);
|
||||
rewriteConfigRewriteLine(state,"sentinel",line,1);
|
||||
}
|
||||
|
||||
/* sentinel auth-pass */
|
||||
if (master->auth_pass) {
|
||||
line = sdscatprintf(sdsempty(),
|
||||
"sentinel auth-pass %s %s",
|
||||
master->name, master->auth_pass);
|
||||
rewriteConfigRewriteLine(state,"sentinel",line,1);
|
||||
}
|
||||
|
||||
/* sentinel config-epoch */
|
||||
line = sdscatprintf(sdsempty(),
|
||||
"sentinel config-epoch %s %llu",
|
||||
master->name, (unsigned long long) master->config_epoch);
|
||||
rewriteConfigRewriteLine(state,"sentinel",line,1);
|
||||
|
||||
/* sentinel known-slave */
|
||||
di2 = dictGetIterator(master->slaves);
|
||||
while((de = dictNext(di)) != NULL) {
|
||||
ri = dictGetVal(de);
|
||||
line = sdscatprintf(sdsempty(),
|
||||
"sentinel known-slave %s %s %d",
|
||||
master->name, ri->addr->ip, ri->addr->port);
|
||||
rewriteConfigRewriteLine(state,"sentinel",line,1);
|
||||
}
|
||||
dictReleaseIterator(di2);
|
||||
|
||||
/* sentinel known-sentinel */
|
||||
di2 = dictGetIterator(master->sentinels);
|
||||
while((de = dictNext(di)) != NULL) {
|
||||
ri = dictGetVal(de);
|
||||
line = sdscatprintf(sdsempty(),
|
||||
"sentinel known-sentinel %s %s %d",
|
||||
master->name, ri->addr->ip, ri->addr->port);
|
||||
rewriteConfigRewriteLine(state,"sentinel",line,1);
|
||||
}
|
||||
dictReleaseIterator(di2);
|
||||
}
|
||||
dictReleaseIterator(di);
|
||||
}
|
||||
|
||||
/* ====================== hiredis connection handling ======================= */
|
||||
|
||||
/* Completely disconnect an hiredis link from an instance. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user