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