Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/optimize sentinel elect #266

Open
wants to merge 163 commits into
base: xredis_2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 98 commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
6e476aa
change elect logic
Feb 18, 2024
65c0ba4
test
Feb 18, 2024
0a185f5
test down after
Feb 18, 2024
2f71b4b
fix down-after unit
Feb 18, 2024
641cd89
add tilt log
Feb 20, 2024
1024a4b
remove log
Feb 20, 2024
b08b870
add mstime
Feb 20, 2024
d1a0c74
add times
Feb 20, 2024
699fb3c
redo time
Feb 20, 2024
aff579b
flushConfig time
Feb 21, 2024
035e28e
add test
Feb 22, 2024
b6c32c1
abory test
Feb 22, 2024
21847b5
assert.h
Feb 22, 2024
150044c
serverassert
Feb 22, 2024
f75d8ab
test
Feb 22, 2024
6607e32
ip
Feb 22, 2024
78261e4
init
Feb 22, 2024
ab5c0dc
sentinel.masteres
Feb 22, 2024
e6c4fe6
add flag
Feb 22, 2024
f182bbe
init
Feb 22, 2024
b554263
init
Feb 22, 2024
ac13cd8
addsub
Feb 22, 2024
d5770ac
clients
Feb 22, 2024
5231774
pub channel
Feb 22, 2024
872789e
channel
Feb 22, 2024
d0c39c5
init
Feb 22, 2024
f0a2680
test
Feb 22, 2024
0d6aa1a
initserver
Feb 22, 2024
8d357c4
add ;
Feb 22, 2024
7c55e66
dict
Feb 22, 2024
588affd
add dict
Feb 22, 2024
5cfbd91
add dict.h
Feb 22, 2024
debc6de
sentinel h
Feb 22, 2024
9760c33
server.h
Feb 22, 2024
da2564d
dup
Feb 22, 2024
0c01101
initserver
Feb 23, 2024
338e82d
init
Feb 23, 2024
4cb29bf
robj
Feb 23, 2024
34b5992
patterns
Feb 23, 2024
500f336
progress
Feb 23, 2024
2dda6b8
add time
Feb 23, 2024
d31a916
log
Feb 23, 2024
73781dd
state
Feb 23, 2024
4ea0bc3
config.c
Feb 25, 2024
edf1c44
count
Feb 25, 2024
ee09075
count
Feb 25, 2024
df881c7
time
Feb 25, 2024
4c42cf3
handle
Feb 25, 2024
457cb9c
test flushconfig not in voteLeader
Feb 27, 2024
1daa10e
no split
Feb 27, 2024
35a354e
02271822
Feb 27, 2024
e4062d8
untracklog
Feb 28, 2024
593a583
merge
Feb 28, 2024
ce3e5a0
unit
Feb 28, 2024
1ee8f44
return 0
Feb 28, 2024
f4f0f6d
flushconfig
Feb 28, 2024
0aa46d4
sentinelCheckFlush
Feb 29, 2024
263b782
test config epoch
Feb 29, 2024
a337a2a
c_err
Feb 29, 2024
9f72b8f
unit
Mar 1, 2024
b6b2deb
test
Mar 1, 2024
53727b3
elect abort
Mar 1, 2024
e021df3
dict
Mar 1, 2024
6466501
dictrelease
Mar 1, 2024
5d960bf
voteleader
Mar 1, 2024
cc75118
ledaer_epoch
Mar 1, 2024
f097ea4
leader
Mar 1, 2024
ca1c9ef
sdsnew
Mar 1, 2024
c6f125c
myod
Mar 1, 2024
3ee7c93
release
Mar 3, 2024
f897835
myid
Mar 4, 2024
308c318
print
Mar 4, 2024
7c7dbb1
sds
Mar 4, 2024
fb7a226
myid
Mar 4, 2024
52dd37f
len
Mar 4, 2024
44d7134
cmp
Mar 4, 2024
ea7f9b9
ans
Mar 4, 2024
cf230c3
sdsnew
Mar 4, 2024
c3e8676
geetleader
Mar 4, 2024
cd504e2
di
Mar 4, 2024
aa63ed3
getleader
Mar 4, 2024
a4e0452
getleader
Mar 4, 2024
3a1135f
quorum
Mar 4, 2024
d5d0bcc
quorum;
Mar 4, 2024
dd0079c
other
Mar 4, 2024
4e6f3d5
epoch 2 3
Mar 4, 2024
2af4939
leader
Mar 4, 2024
a49d5fe
other_id
Mar 4, 2024
18897f2
;
Mar 4, 2024
d56ed4d
sdsnew
Mar 4, 2024
5b891e1
if needed
Mar 4, 2024
9a1aec1
if neded
Mar 4, 2024
61b9d89
delay log
Mar 4, 2024
f448269
log
Mar 4, 2024
716e65f
log
Mar 4, 2024
85240e3
log
Mar 4, 2024
b44c2ea
redefine
Mar 4, 2024
1a75965
sentinel.c unit test
Mar 4, 2024
4c03a27
flush
Mar 4, 2024
48e15d5
flush
Mar 4, 2024
675897e
config
Mar 4, 2024
1c21dc8
defalu
Mar 4, 2024
848fe3c
flush
Mar 4, 2024
f836c9b
temp.conf
Mar 4, 2024
db1ffd7
mstime
Mar 4, 2024
f06ad29
fstat
Mar 4, 2024
2cf8731
stat
Mar 4, 2024
331dc27
user
Mar 4, 2024
8279792
flushifneed
Mar 5, 2024
ee1f4bf
fstat
Mar 5, 2024
fca6d16
fstat
Mar 5, 2024
9d4232b
fd
Mar 5, 2024
8e3c9fa
fd
Mar 5, 2024
c6b9990
fopen
Mar 5, 2024
409ae81
close
Mar 5, 2024
e86ea55
close
Mar 5, 2024
2f4ddcb
\n
Mar 5, 2024
fb76cea
here
Mar 5, 2024
b7bab3b
mstime
Mar 5, 2024
77115b9
newfileinfo
Mar 5, 2024
d50f9ea
werr2
Mar 5, 2024
88a9e17
return 0
Mar 5, 2024
2032e8f
now
Mar 5, 2024
263b504
needed
Mar 5, 2024
3cc4729
finish
Mar 5, 2024
c60fc44
fix flush
Mar 5, 2024
f351e09
reverse
Mar 5, 2024
15c0082
flush logic
Mar 5, 2024
aa5f404
werr
Mar 5, 2024
799639d
read
Mar 5, 2024
a8a21ae
spac
Mar 5, 2024
1e39128
revert
Mar 5, 2024
9d8743c
space
Mar 5, 2024
41135e7
space
Mar 5, 2024
f060cde
space
Mar 5, 2024
cbdf75e
revert
Mar 5, 2024
6013e88
return NULL
Mar 5, 2024
9fc9479
redo fix
Mar 5, 2024
983ab0e
fix arg
Mar 5, 2024
d7f8211
force all
Mar 5, 2024
327b271
tcl
Mar 12, 2024
307b38a
tcl
Mar 12, 2024
76f1adc
tcl
Mar 12, 2024
d136f91
tcl
Mar 12, 2024
1803cad
tcl
Mar 12, 2024
aaa6f65
tcl
Mar 12, 2024
91059bd
tcl
Mar 12, 2024
c6e1a39
tcl
Mar 12, 2024
8e36fac
tcl
Mar 12, 2024
1479fbc
tcl
Mar 12, 2024
9a06586
tcl
Mar 12, 2024
2405244
tcl
Mar 12, 2024
06afd0b
tcl
Mar 12, 2024
949a7ec
tcl
Mar 12, 2024
1c50481
tcl
Mar 12, 2024
cbc204d
tcl
Mar 12, 2024
ce04623
tcl
Mar 12, 2024
3784730
oom-score-adj
Mar 12, 2024
58485ee
oom-score-adj revert
Mar 12, 2024
8a379b1
revert
Mar 12, 2024
39b1ca7
revert
Mar 12, 2024
5a21a62
revert
Mar 12, 2024
3979a1d
fix tcl
Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
133 changes: 68 additions & 65 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1141,80 +1141,83 @@ void rewriteConfigMarkAsProcessed(struct rewriteConfigState *state, const char *
* If it is impossible to read the old file, NULL is returned.
* If the old file does not exist at all, an empty state is returned. */
struct rewriteConfigState *rewriteConfigReadOldFile(char *path) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

尽快定稿。当前改法影响server。


FILE *fp = fopen(path,"r");
if (fp == NULL && errno != ENOENT) return NULL;

char buf[CONFIG_MAX_LINE+1];
int linenum = -1;
// 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;
if (fp == NULL) return state;

/* Read the old file line by line, populate the state. */
while(fgets(buf,CONFIG_MAX_LINE+1,fp) != NULL) {
int argc;
sds *argv;
sds line = sdstrim(sdsnew(buf),"\r\n\t ");

linenum++; /* Zero based, so we init at -1 */

/* Handle comments and empty lines. */
if (line[0] == '#' || line[0] == '\0') {
if (!state->has_tail && !strcmp(line,REDIS_CONFIG_REWRITE_SIGNATURE))
state->has_tail = 1;
rewriteConfigAppendLine(state,line);
continue;
}

/* Not a comment, split into arguments. */
argv = sdssplitargs(line,&argc);
if (argv == NULL) {
/* Apparently the line is unparsable for some reason, for
* instance it may have unbalanced quotes. Load it as a
* comment. */
sds aux = sdsnew("# ??? ");
aux = sdscatsds(aux,line);
sdsfree(line);
rewriteConfigAppendLine(state,aux);
continue;
}

sdstolower(argv[0]); /* We only want lowercase config directives. */

/* Now we populate the state according to the content of this line.
* Append the line and populate the option -> line numbers map. */
rewriteConfigAppendLine(state,line);

/* Translate options using the word "slave" to the corresponding name
* "replica", before adding such option to the config name -> lines
* mapping. */
char *p = strstr(argv[0],"slave");
if (p) {
sds alt = sdsempty();
alt = sdscatlen(alt,argv[0],p-argv[0]);
alt = sdscatlen(alt,"replica",7);
alt = sdscatlen(alt,p+5,strlen(p+5));
sdsfree(argv[0]);
argv[0] = alt;
}
/* If this is sentinel config, we use sentinel "sentinel <config>" as option
to avoid messing up the sequence. */
if (server.sentinel_mode && argc > 1 && !strcasecmp(argv[0],"sentinel")) {
sds sentinelOption = sdsempty();
sentinelOption = sdscatfmt(sentinelOption,"%S %S",argv[0],argv[1]);
rewriteConfigAddLineNumberToOption(state,sentinelOption,linenum);
sdsfree(sentinelOption);
} else {
rewriteConfigAddLineNumberToOption(state,argv[0],linenum);
}
sdsfreesplitres(argv,argc);
}
fclose(fp);
// Note: do not reload from disk to reduce time consumption
// if (fp == NULL) return state;

// /* Read the old file line by line, populate the state. */
// while(fgets(buf,CONFIG_MAX_LINE+1,fp) != NULL) {
// int argc;
// sds *argv;
// sds line = sdstrim(sdsnew(buf),"\r\n\t ");

// linenum++; /* Zero based, so we init at -1 */

// /* Handle comments and empty lines. */
// if (line[0] == '#' || line[0] == '\0') {
// if (!state->has_tail && !strcmp(line,REDIS_CONFIG_REWRITE_SIGNATURE))
// state->has_tail = 1;
// rewriteConfigAppendLine(state,line);
// continue;
// }

// /* Not a comment, split into arguments. */
// argv = sdssplitargs(line,&argc);

// if (argv == NULL) {
// /* Apparently the line is unparsable for some reason, for
// * instance it may have unbalanced quotes. Load it as a
// * comment. */
// sds aux = sdsnew("# ??? ");
// aux = sdscatsds(aux,line);
// sdsfree(line);
// rewriteConfigAppendLine(state,aux);
// continue;
// }

// sdstolower(argv[0]); /* We only want lowercase config directives. */

// /* Now we populate the state according to the content of this line.
// * Append the line and populate the option -> line numbers map. */
// rewriteConfigAppendLine(state,line);

// /* Translate options using the word "slave" to the corresponding name
// * "replica", before adding such option to the config name -> lines
// * mapping. */
// char *p = strstr(argv[0],"slave");
// if (p) {
// sds alt = sdsempty();
// alt = sdscatlen(alt,argv[0],p-argv[0]);
// alt = sdscatlen(alt,"replica",7);
// alt = sdscatlen(alt,p+5,strlen(p+5));
// sdsfree(argv[0]);
// argv[0] = alt;
// }
// /* If this is sentinel config, we use sentinel "sentinel <config>" as option
// to avoid messing up the sequence. */
// if (server.sentinel_mode && argc > 1 && !strcasecmp(argv[0],"sentinel")) {
// sds sentinelOption = sdsempty();
// sentinelOption = sdscatfmt(sentinelOption,"%S %S",argv[0],argv[1]);
// rewriteConfigAddLineNumberToOption(state,sentinelOption,linenum);
// sdsfree(sentinelOption);
// } else {
// rewriteConfigAddLineNumberToOption(state,argv[0],linenum);
// }
// sdsfreesplitres(argv,argc);
// }
// fclose(fp);
return state;
}

Expand Down Expand Up @@ -1645,7 +1648,7 @@ int rewriteConfigOverwriteFile(char *configfile, sds content) {
serverLog(LL_WARNING, "Could not create tmp config file (%s)", strerror(errno));
return retval;
}

while (offset < sdslen(content)) {
written_bytes = write(fd, content + offset, sdslen(content) - offset);
if (written_bytes <= 0) {
Expand Down