diff --git a/src/module.c b/src/module.c index e45b8f418..24cc6a42e 100644 --- a/src/module.c +++ b/src/module.c @@ -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; diff --git a/tests/unit/moduleapi/rdbloadsave.tcl b/tests/unit/moduleapi/rdbloadsave.tcl index 37841aa9a..6e2fadc60 100644 --- a/tests/unit/moduleapi/rdbloadsave.tcl +++ b/tests/unit/moduleapi/rdbloadsave.tcl @@ -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]