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

Fix unexpected behavior when turning appendonly on and off within a transaction #826

Merged
merged 3 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
20 changes: 13 additions & 7 deletions src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,18 +931,23 @@ void killAppendOnlyChild(void) {
* at runtime using the CONFIG command. */
void stopAppendOnly(void) {
serverAssert(server.aof_state != AOF_OFF);
flushAppendOnlyFile(1);
if (valkey_fsync(server.aof_fd) == -1) {
serverLog(LL_WARNING, "Fail to fsync the AOF file: %s", strerror(errno));
} else {
server.aof_last_fsync = server.mstime;
if (server.aof_fd != -1) {
flushAppendOnlyFile(1);
if (valkey_fsync(server.aof_fd) == -1) {
serverLog(LL_WARNING, "Fail to fsync the AOF file: %s", strerror(errno));
} else {
server.aof_last_fsync = server.mstime;
}
close(server.aof_fd);
}
close(server.aof_fd);
zuiderkwast marked this conversation as resolved.
Show resolved Hide resolved

server.aof_fd = -1;
server.aof_selected_db = -1;
server.aof_state = AOF_OFF;
server.aof_rewrite_scheduled = 0;
if (server.aof_rewrite_scheduled) {
server.aof_rewrite_scheduled = 0;
serverLog(LL_NOTICE, "AOF was disabled but there is a scheduled AOF background, cancel it.");
}
server.aof_last_incr_size = 0;
server.aof_last_incr_fsync_offset = 0;
server.fsynced_reploff = -1;
Expand Down Expand Up @@ -2453,6 +2458,7 @@ void bgrewriteaofCommand(client *c) {
/* When manually triggering AOFRW we reset the count
* so that it can be executed immediately. */
server.stat_aofrw_consecutive_failures = 0;
serverLog(LL_NOTICE, "Background append only file rewriting scheduled.");
zuiderkwast marked this conversation as resolved.
Show resolved Hide resolved
addReplyStatus(c, "Background append only file rewriting scheduled");
} else if (rewriteAppendOnlyFileBackground() == C_OK) {
addReplyStatus(c, "Background append only file rewriting started");
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/aof.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -655,4 +655,21 @@ tags {"aof external:skip"} {
}
}
}

start_server {} {
# This test is just a coverage test, it does not check anything。
enjoy-binbin marked this conversation as resolved.
Show resolved Hide resolved
test {Turning appendonly on and off within a transaction} {
r config set appendonly no
r multi
r config set appendonly yes
r config set appendonly no
r exec

r config set appendonly yes
r multi
r config set appendonly no
r config set appendonly yes
r exec
zuiderkwast marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Loading