Commit c517f723 authored by antirez's avatar antirez
Browse files

CONFIG REWRITE: don't add the signature if it already exists.

At the end of the file, CONFIG REWRITE adds a comment line that:

    # Generated by CONFIG REWRITE

Followed by the additional config options required. However this was
added again and again at every rewrite in praticular conditions (when a
given set of options change in a given time during the time).

Now if it was alrady encountered, it is not added a second time.

This is especially important for Sentinel that rewrites the config at
every state change.
parent 812f76a8
...@@ -1102,6 +1102,8 @@ void configGetCommand(redisClient *c) { ...@@ -1102,6 +1102,8 @@ void configGetCommand(redisClient *c) {
* CONFIG REWRITE implementation * CONFIG REWRITE implementation
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
#define REDIS_CONFIG_REWRITE_SIGNATURE "# Generated by CONFIG REWRITE"
/* We use the following dictionary type to store where a configuration /* We use the following dictionary type to store where a configuration
* option is mentioned in the old configuration file, so it's * option is mentioned in the old configuration file, so it's
* like "maxmemory" -> list of line numbers (first line is zero). */ * like "maxmemory" -> list of line numbers (first line is zero). */
...@@ -1178,6 +1180,8 @@ struct rewriteConfigState *rewriteConfigReadOldFile(char *path) { ...@@ -1178,6 +1180,8 @@ struct rewriteConfigState *rewriteConfigReadOldFile(char *path) {
/* Handle comments and empty lines. */ /* Handle comments and empty lines. */
if (line[0] == '#' || line[0] == '\0') { if (line[0] == '#' || line[0] == '\0') {
if (!state->has_tail && !strcmp(line,REDIS_CONFIG_REWRITE_SIGNATURE))
state->has_tail = 1;
rewriteConfigAppendLine(state,line); rewriteConfigAppendLine(state,line);
continue; continue;
} }
...@@ -1249,7 +1253,7 @@ void rewriteConfigRewriteLine(struct rewriteConfigState *state, char *option, sd ...@@ -1249,7 +1253,7 @@ void rewriteConfigRewriteLine(struct rewriteConfigState *state, char *option, sd
/* Append a new line. */ /* Append a new line. */
if (!state->has_tail) { if (!state->has_tail) {
rewriteConfigAppendLine(state, rewriteConfigAppendLine(state,
sdsnew("# Generated by CONFIG REWRITE")); sdsnew(REDIS_CONFIG_REWRITE_SIGNATURE));
state->has_tail = 1; state->has_tail = 1;
} }
rewriteConfigAppendLine(state,line); rewriteConfigAppendLine(state,line);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment