MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rewriteConfigSentinelOption

Function rewriteConfigSentinelOption

app/redis-6.2.6/src/sentinel.c:2066–2298  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

2064 * Sentinel across restarts: config epoch of masters, associated slaves
2065 * and sentinel instances, and so forth. */
2066void rewriteConfigSentinelOption(struct rewriteConfigState *state) {
2067 dictIterator *di, *di2;
2068 dictEntry *de;
2069 sds line;
2070
2071 /* sentinel unique ID. */
2072 line = sdscatprintf(sdsempty(), "sentinel myid %s", sentinel.myid);
2073 rewriteConfigRewriteLine(state,"sentinel myid",line,1);
2074
2075 /* sentinel deny-scripts-reconfig. */
2076 line = sdscatprintf(sdsempty(), "sentinel deny-scripts-reconfig %s",
2077 sentinel.deny_scripts_reconfig ? "yes" : "no");
2078 rewriteConfigRewriteLine(state,"sentinel deny-scripts-reconfig",line,
2079 sentinel.deny_scripts_reconfig != SENTINEL_DEFAULT_DENY_SCRIPTS_RECONFIG);
2080
2081 /* sentinel resolve-hostnames.
2082 * This must be included early in the file so it is already in effect
2083 * when reading the file.
2084 */
2085 line = sdscatprintf(sdsempty(), "sentinel resolve-hostnames %s",
2086 sentinel.resolve_hostnames ? "yes" : "no");
2087 rewriteConfigRewriteLine(state,"sentinel resolve-hostnames",line,
2088 sentinel.resolve_hostnames != SENTINEL_DEFAULT_RESOLVE_HOSTNAMES);
2089
2090 /* sentinel announce-hostnames. */
2091 line = sdscatprintf(sdsempty(), "sentinel announce-hostnames %s",
2092 sentinel.announce_hostnames ? "yes" : "no");
2093 rewriteConfigRewriteLine(state,"sentinel announce-hostnames",line,
2094 sentinel.announce_hostnames != SENTINEL_DEFAULT_ANNOUNCE_HOSTNAMES);
2095
2096 /* For every master emit a "sentinel monitor" config entry. */
2097 di = dictGetIterator(sentinel.masters);
2098 while((de = dictNext(di)) != NULL) {
2099 sentinelRedisInstance *master, *ri;
2100 sentinelAddr *master_addr;
2101
2102 /* sentinel monitor */
2103 master = dictGetVal(de);
2104 master_addr = sentinelGetCurrentMasterAddress(master);
2105 line = sdscatprintf(sdsempty(),"sentinel monitor %s %s %d %d",
2106 master->name, announceSentinelAddr(master_addr), master_addr->port,
2107 master->quorum);
2108 rewriteConfigRewriteLine(state,"sentinel monitor",line,1);
2109 /* rewriteConfigMarkAsProcessed is handled after the loop */
2110
2111 /* sentinel down-after-milliseconds */
2112 if (master->down_after_period != SENTINEL_DEFAULT_DOWN_AFTER) {
2113 line = sdscatprintf(sdsempty(),
2114 "sentinel down-after-milliseconds %s %ld",
2115 master->name, (long) master->down_after_period);
2116 rewriteConfigRewriteLine(state,"sentinel down-after-milliseconds",line,1);
2117 /* rewriteConfigMarkAsProcessed is handled after the loop */
2118 }
2119
2120 /* sentinel failover-timeout */
2121 if (master->failover_timeout != SENTINEL_DEFAULT_FAILOVER_TIMEOUT) {
2122 line = sdscatprintf(sdsempty(),
2123 "sentinel failover-timeout %s %ld",

Callers 1

rewriteConfigFunction · 0.85

Calls 13

sdscatprintfFunction · 0.85
sdsemptyFunction · 0.85
rewriteConfigRewriteLineFunction · 0.85
announceSentinelAddrFunction · 0.85
sentinelAddrIsEqualFunction · 0.85
sdsnewFunction · 0.85
sdscatreprFunction · 0.85
sdslenFunction · 0.85
dictGetIteratorFunction · 0.70
dictNextFunction · 0.70

Tested by

no test coverage detected