Fix module RdbLoad wrongly disable the AOF (#1001)

In RdbLoad, we disable AOF before emptyData and rdbLoad to prevent copy-on-write issues. After rdbLoad completes, AOF should be re-enabled, but the code incorrectly checks server.aof_state, which has been reset to AOF_OFF in stopAppendOnly. This leads to AOF not being re-enabled after being disabled.
---------

Signed-off-by: Binbin <binloveplay1314@qq.com>
This commit is contained in:
Binbin 2024-09-11 12:00:08 +08:00 committed by GitHub
parent 1b24168450
commit 4033c99ef5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -12965,6 +12965,9 @@ int VM_RdbLoad(ValkeyModuleCtx *ctx, ValkeyModuleRdbStream *stream, int flags) {
disconnectReplicas();
freeReplicationBacklog();
/* Stop and kill existing AOF rewriting fork as it is saving outdated data,
* we will re-enable it after the rdbLoad. Also killing it will prevent COW
* memory issue. */
if (server.aof_state != AOF_OFF) stopAppendOnly();
/* Kill existing RDB fork as it is saving outdated data. Also killing it
@ -12983,7 +12986,10 @@ int VM_RdbLoad(ValkeyModuleCtx *ctx, ValkeyModuleRdbStream *stream, int flags) {
int ret = rdbLoad(stream->data.filename, NULL, RDBFLAGS_NONE);
if (server.current_client) unprotectClient(server.current_client);
if (server.aof_state != AOF_OFF) startAppendOnly();
/* Here we need to decide whether to enable the AOF based on the aof_enabled,
* since the previous stopAppendOnly sets aof_state to AOF_OFF. */
if (server.aof_enabled) startAppendOnly();
if (ret != RDB_OK) {
errno = (ret == RDB_NOT_EXIST) ? ENOENT : EIO;

View File

@ -80,6 +80,9 @@ start_server {tags {"modules"}} {
fail "Can't find 'Killing AOF child' in recent log lines"
}
# Verify that AOF is active.
assert_equal 1 [s aof_enabled]
# Verify the value in the loaded rdb
assert_equal v1 [r get k]