Fix config rewrite with an empty "save" parameter. (#8719)

This commit is contained in:
Yossi Gottlieb 2021-03-29 18:53:20 +03:00 committed by GitHub
parent 315df9ada0
commit 65311a3360
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 7 deletions

View File

@ -1381,14 +1381,19 @@ void rewriteConfigSaveOption(struct rewriteConfigState *state) {
return; return;
} }
/* Note that if there are no save parameters at all, all the current /* Rewrite save parameters, or an empty 'save ""' line to avoid the
* config line with "save" will be detected as orphaned and deleted, * defaults from being used.
* resulting into no RDB persistence as expected. */ */
for (j = 0; j < server.saveparamslen; j++) { if (!server.saveparamslen) {
line = sdscatprintf(sdsempty(),"save %ld %d", rewriteConfigRewriteLine(state,"save",sdsnew("save \"\""),0);
(long) server.saveparams[j].seconds, server.saveparams[j].changes); } else {
rewriteConfigRewriteLine(state,"save",line,1); for (j = 0; j < server.saveparamslen; j++) {
line = sdscatprintf(sdsempty(),"save %ld %d",
(long) server.saveparams[j].seconds, server.saveparams[j].changes);
rewriteConfigRewriteLine(state,"save",line,1);
}
} }
/* Mark "save" as processed in case server.saveparamslen is zero. */ /* Mark "save" as processed in case server.saveparamslen is zero. */
rewriteConfigMarkAsProcessed(state,"save"); rewriteConfigMarkAsProcessed(state,"save");
} }

View File

@ -180,6 +180,18 @@ start_server {tags {"introspection"}} {
} }
} }
test {CONFIG REWRITE handles save properly} {
r config set save "3600 1 300 100 60 10000"
r config rewrite
restart_server 0 true false
assert_equal [r config get save] {save {3600 1 300 100 60 10000}}
r config set save ""
r config rewrite
restart_server 0 true false
assert_equal [r config get save] {save {}}
}
# Config file at this point is at a wierd state, and includes all # Config file at this point is at a wierd state, and includes all
# known keywords. Might be a good idea to avoid adding tests here. # known keywords. Might be a good idea to avoid adding tests here.
} }