From 5d70ccd70eb42db718e0176987891f91d21d29c8 Mon Sep 17 00:00:00 2001 From: Binbin Date: Wed, 23 Oct 2024 10:22:25 +0800 Subject: [PATCH] Make replica CLUSTER RESET flush async based on lazyfree-lazy-user-flush (#1190) Currently, if the replica has a lot of data, CLUSTER RESET will block for a while and report the slowlog, and it seems that there is no harm in making it async so external components can be easier when monitoring it. Signed-off-by: Binbin Co-authored-by: Ping Xie --- src/cluster_legacy.c | 2 +- valkey.conf | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index 14f8a6bd1e..4e21d1473d 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -1230,7 +1230,7 @@ void clusterReset(int hard) { if (nodeIsReplica(myself)) { clusterSetNodeAsPrimary(myself); replicationUnsetPrimary(); - emptyData(-1, EMPTYDB_NO_FLAGS, NULL); + emptyData(-1, server.lazyfree_lazy_user_flush ? EMPTYDB_ASYNC : EMPTYDB_NO_FLAGS, NULL); } /* Close slots, reset manual failover state. */ diff --git a/valkey.conf b/valkey.conf index f485b42b1a..5960feb1b6 100644 --- a/valkey.conf +++ b/valkey.conf @@ -1308,7 +1308,11 @@ lazyfree-lazy-user-del yes # deletion, which can be controlled by passing the [SYNC|ASYNC] flags into the # commands. When neither flag is passed, this directive will be used to determine # if the data should be deleted asynchronously. - +# +# When a replica performs a node reset via CLUSTER RESET, the entire +# database content is removed to allow the node to become an empty primary. +# This directive also determines whether the data should be deleted asynchronously. +# # There are many problems with running flush synchronously. Even in single CPU # environments, the thread managers should balance between the freeing and # serving incoming requests. The default value is yes.