Skip to content

Commit

Permalink
feature: modify sentinel elect logic, make epoch private for each master
Browse files Browse the repository at this point in the history
  • Loading branch information
hany_li committed Jul 15, 2024
1 parent 2dac4cc commit 816b4bd
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 44 deletions.
4 changes: 4 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ test-modules: $(REDIS_SERVER_NAME)
test-sentinel: $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME)
@(cd ..; ./runtest-sentinel)

unit-test-sentinel:
$(MAKE) CFLAGS="-DREDIS_TEST" OPTIMIZATION="-O0"
@(./$(REDIS_SERVER_NAME) test sentinel)

check: test

lcov:
Expand Down
38 changes: 29 additions & 9 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,18 @@ void rewriteConfigMarkAsProcessed(struct rewriteConfigState *state, const char *
if (dictAdd(state->rewritten,opt,NULL) != DICT_OK) sdsfree(opt);
}

/* Init rewriteConfigState */
struct rewriteConfigState *initRewriteConfigState(void) {
struct rewriteConfigState *state = zmalloc(sizeof(*state));
state->option_to_line = dictCreate(&optionToLineDictType,NULL);
state->rewritten = dictCreate(&optionSetDictType,NULL);
state->numlines = 0;
state->lines = NULL;
state->has_tail = 0;
state->force_all = 0;
return state;
}

/* Read the old file, split it into lines to populate a newly created
* config rewrite state, and return it to the caller.
*
Expand All @@ -1146,13 +1158,7 @@ struct rewriteConfigState *rewriteConfigReadOldFile(char *path) {

char buf[CONFIG_MAX_LINE+1];
int linenum = -1;
struct rewriteConfigState *state = zmalloc(sizeof(*state));
state->option_to_line = dictCreate(&optionToLineDictType,NULL);
state->rewritten = dictCreate(&optionSetDictType,NULL);
state->numlines = 0;
state->lines = NULL;
state->has_tail = 0;
state->force_all = 0;
struct rewriteConfigState *state = initRewriteConfigState();
if (fp == NULL) return state;

/* Read the old file line by line, populate the state. */
Expand Down Expand Up @@ -1683,13 +1689,27 @@ int rewriteConfigOverwriteFile(char *configfile, sds content) {
* written. This is currently only used for testing purposes.
*
* On error -1 is returned and errno is set accordingly, otherwise 0. */

int rewriteConfig(char *path, int force_all) {
return rewriteConfigOptional(path, force_all, 1);
}

int rewriteConfigNotReadOld(char *path, int force_all) {
return rewriteConfigOptional(path, force_all, 0);
}

int rewriteConfigOptional(char *path, int force_all, int read_old_file) {
struct rewriteConfigState *state;
sds newcontent;
int retval;

/* Step 1: read the old config into our rewrite state. */
if ((state = rewriteConfigReadOldFile(path)) == NULL) return -1;
/* Step 1: read the old config into our rewrite state. Or just init state.*/
if (read_old_file) {
state = rewriteConfigReadOldFile(path);
} else {
state = initRewriteConfigState();
}
if (state == NULL) return -1;
if (force_all) state->force_all = 1;

/* Step 2: rewrite every single option, replacing or appending it inside
Expand Down
Loading

0 comments on commit 816b4bd

Please sign in to comment.