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

Introduce bgsave cancel #757

Merged
merged 32 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bba9bfc
Introduce bgsave cancel
ranshid Jul 8, 2024
09ac835
clang format fix
ranshid Jul 8, 2024
7899fad
Update src/rdb.c
ranshid Jul 9, 2024
0572c7a
Update src/rdb.c
ranshid Jul 9, 2024
c25a85b
Update tests/integration/rdb.tcl
ranshid Jul 9, 2024
9f7f3aa
Update tests/integration/rdb.tcl
ranshid Jul 9, 2024
50bc3f0
change bgsave cancel to be a sub-command
ranshid Jul 9, 2024
8aff7ac
fix bad merge-stash
ranshid Jul 9, 2024
c7b71ec
Update src/rdb.c
ranshid Jul 9, 2024
6b823e3
some minor extra fixes
ranshid Jul 9, 2024
63f9529
fix rdb.tcl after error string change
ranshid Jul 9, 2024
1878f86
Update src/rdb.c
ranshid Jul 10, 2024
528038f
1. change bgsave schedule to be a sub-command
ranshid Jul 18, 2024
23bd3a2
format fixes
ranshid Jul 18, 2024
be0954a
remove bgsave kill subcommand and make all logic inside bgsave cancel
ranshid Jul 20, 2024
f662c69
make cancel and schedule command arguments
ranshid Jul 21, 2024
7ca2452
bring back some extra deleted lines
ranshid Jul 21, 2024
64b52d7
format fix
ranshid Jul 21, 2024
8ebca1a
1. marke all bgsave arguments as optional
ranshid Jul 21, 2024
9873d64
Update src/rdb.c
ranshid Jul 22, 2024
c1b6be7
Update src/rdb.c
ranshid Jul 22, 2024
e80173b
Update src/rdb.c
ranshid Jul 22, 2024
c2c09d3
Update src/commands/bgsave.json
ranshid Jul 22, 2024
a8a2c54
Update src/commands/bgsave.json
ranshid Jul 22, 2024
445ebe0
Update src/rdb.c
ranshid Jul 22, 2024
7ae21bb
Update tests/integration/rdb.tcl
ranshid Jul 22, 2024
ae9fff6
Update tests/integration/rdb.tcl
ranshid Jul 22, 2024
db9353e
Update tests/integration/rdb.tcl
ranshid Jul 22, 2024
6c0c855
Update tests/integration/rdb.tcl
ranshid Jul 22, 2024
0576254
Update src/rdb.c
ranshid Jul 22, 2024
71533de
Apply suggestions from code review
enjoy-binbin Jul 24, 2024
55a1541
add log msg for bgsave schedule
ranshid Jul 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/rdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3645,6 +3645,18 @@ void bgsaveCommand(client *c) {
if (c->argc > 1) {
if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr, "schedule")) {
schedule = 1;
} else if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr, "cancel")) {
ranshid marked this conversation as resolved.
Show resolved Hide resolved
/* BGSAVE CANCEL
* Terminates an in progress BGSAVE */
if (server.child_type == CHILD_TYPE_RDB) {
/* There is an ongoing save */
enjoy-binbin marked this conversation as resolved.
Show resolved Hide resolved
serverLog(LL_NOTICE, "Background save requested to be canceled by user");
killRDBChild();
addReply(c, shared.ok);
} else {
addReplyError(c, "background save is currently not in progress");
ranshid marked this conversation as resolved.
Show resolved Hide resolved
}
return;
} else {
addReplyErrorObject(c, shared.syntaxerr);
return;
Expand Down
40 changes: 40 additions & 0 deletions tests/integration/rdb.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,46 @@ start_server {} {
}
assert_equal [s rdb_changes_since_last_save] 0
}

test {bgsave cancel aborts save} {
r config set save ""
# Generating RDB will take some 100 seconds
r config set rdb-key-save-delay 1000000
populate 100 "" 16

r bgsave
wait_for_condition 50 100 {
[s rdb_bgsave_in_progress] == 1
} else {
fail "bgsave not done"
enjoy-binbin marked this conversation as resolved.
Show resolved Hide resolved
}
set fork_child_pid [get_child_pid 0]

assert {[r bgsave cancel] eq {OK}}
set temp_rdb [file join [lindex [r config get dir] 1] temp-${fork_child_pid}.rdb]
# Temp rdb must be existed
ranshid marked this conversation as resolved.
Show resolved Hide resolved
wait_for_condition 50 100 {
![file exists $temp_rdb]
} else {
fail "bgsave temp file was not deleted after cancel"
}
ranshid marked this conversation as resolved.
Show resolved Hide resolved
}

test {bgsave cancel response with error when no ongoing save} {
r config set save ""
# Generating RDB will take some 100 seconds
ranshid marked this conversation as resolved.
Show resolved Hide resolved
r config set rdb-key-save-delay 0

# Make sure no save is running and that bgsave return an error
wait_for_condition 50 100 {
[s rdb_bgsave_in_progress] == 0
} else {
fail "bgsave is currently running"
}
assert_error "ERR background save is currently not in progress" {r bgsave cancel}
ranshid marked this conversation as resolved.
Show resolved Hide resolved
}


}

test {client freed during loading} {
Expand Down
Loading