diff options
author | Subhi Al Hasan <jodevsa@gmail.com> | 2023-04-04 10:53:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-04 11:53:57 +0300 |
commit | 74b29985ced0d185dd15bde9888f93608ba57c14 (patch) | |
tree | 5c0d7382224469f4cef4faa25cee7c5821ab6b61 /src/sentinel.c | |
parent | e1da724117bb842c383e227e57b9c45331f430db (diff) | |
download | redis-74b29985ced0d185dd15bde9888f93608ba57c14.tar.gz |
check for known-slave in sentinel rewrite config (#11775)
Fix the following config file error
```
*** FATAL CONFIG FILE ERROR (Redis 6.2.7) ***
Reading the configuration file, at line 152
>>> 'sentinel known-replica XXXX 127.0.0.1 5001'
Duplicate hostname and port for replica.
```
that is happening when a user uses the legacy key "known-slave" in
the config file and a config rewrite occurs. The config rewrite logic won't
replace the old line "sentinel known-slave XXXX 127.0.0.1 5001" and
would add a new line with "sentinel known-replica XXXX 127.0.0.1 5001"
which results in the error above "Duplicate hostname and port for replica."
example:
Current sentinal.conf
```
...
sentinel known-slave XXXX 127.0.0.1 5001
sentinel example-random-option X
...
```
after the config rewrite logic runs:
```
....
sentinel known-slave XXXX 127.0.0.1 5001
sentinel example-random-option X
# Generated by CONFIG REWRITE
sentinel known-replica XXXX 127.0.0.1 5001
```
This bug only exists in Redis versions >=6.2 because prior to that it was hidden
by the effects of this bug https://github.com/redis/redis/issues/5388 that was fixed
in https://github.com/redis/redis/pull/8271 and was released in versions >=6.2
Diffstat (limited to 'src/sentinel.c')
-rw-r--r-- | src/sentinel.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/sentinel.c b/src/sentinel.c index b4dead7de..03482fdd2 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -2176,7 +2176,12 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state) { line = sdscatprintf(sdsempty(), "sentinel known-replica %s %s %d", master->name, announceSentinelAddr(slave_addr), slave_addr->port); - rewriteConfigRewriteLine(state,"sentinel known-replica",line,1); + /* try to replace any known-slave option first if found */ + if (rewriteConfigRewriteLine(state, "sentinel known-slave", sdsdup(line), 0) == 0) { + rewriteConfigRewriteLine(state, "sentinel known-replica", line, 1); + } else { + sdsfree(line); + } /* rewriteConfigMarkAsProcessed is handled after the loop */ } dictReleaseIterator(di2); |