From 7b1127ee56f2ab244f260107da1c121260f6e0de Mon Sep 17 00:00:00 2001 From: "lvyanqi.lyq" Date: Wed, 13 Nov 2024 11:13:20 +0800 Subject: [PATCH] import-mode only takes effect on primary Signed-off-by: lvyanqi.lyq --- src/cluster_legacy.c | 5 ----- src/config.c | 15 +-------------- src/evict.c | 2 +- src/replication.c | 5 ----- src/server.c | 6 ++++-- 5 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index 6ce5967cbe..14f8a6bd1e 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -6648,11 +6648,6 @@ int clusterCommandSpecial(client *c) { return 1; } - if (server.import_mode) { - addReplyError(c, "CLUSTER REPLICATE not allowed in import mode."); - return 1; - } - /* If the instance is currently a primary, it should have no assigned * slots nor keys to accept to replicate some other node. * Replicas can switch to another primary without issues. */ diff --git a/src/config.c b/src/config.c index bdbbbe5891..01795258b1 100644 --- a/src/config.c +++ b/src/config.c @@ -2331,14 +2331,6 @@ static int isValidActiveDefrag(int val, const char **err) { return 1; } -static int isValidImportMode(int val, const char **err) { - if (server.primary_host && val) { - *err = "Server is already in replica mode"; - return 0; - } - return 1; -} - static int isValidClusterConfigFile(char *val, const char **err) { if (!strcmp(val, "")) { *err = "cluster-config-file can't be empty"; @@ -2957,11 +2949,6 @@ static int setConfigReplicaOfOption(standardConfig *config, sds *argv, int argc, return 0; } - if (server.import_mode) { - *err = "REPLICAOF not allowed in import mode"; - return 0; - } - sdsfree(server.primary_host); server.primary_host = NULL; if (!strcasecmp(argv[0], "no") && !strcasecmp(argv[1], "one")) { @@ -3149,7 +3136,7 @@ standardConfig static_configs[] = { createBoolConfig("enable-debug-assert", NULL, IMMUTABLE_CONFIG | HIDDEN_CONFIG, server.enable_debug_assert, 0, NULL, NULL), createBoolConfig("cluster-slot-stats-enabled", NULL, MODIFIABLE_CONFIG, server.cluster_slot_stats_enabled, 0, NULL, NULL), createBoolConfig("hide-user-data-from-log", NULL, MODIFIABLE_CONFIG, server.hide_user_data_from_log, 1, NULL, NULL), - createBoolConfig("import-mode", NULL, MODIFIABLE_CONFIG, server.import_mode, 0, isValidImportMode, NULL), + createBoolConfig("import-mode", NULL, MODIFIABLE_CONFIG, server.import_mode, 0, NULL, NULL), /* String Configs */ createStringConfig("aclfile", NULL, IMMUTABLE_CONFIG, ALLOW_EMPTY_STRING, server.acl_filename, "", NULL, NULL), diff --git a/src/evict.c b/src/evict.c index 0eaacfb62c..5208328b32 100644 --- a/src/evict.c +++ b/src/evict.c @@ -546,7 +546,7 @@ int performEvictions(void) { goto update_metrics; } - if (server.maxmemory_policy == MAXMEMORY_NO_EVICTION || server.import_mode) { + if (server.maxmemory_policy == MAXMEMORY_NO_EVICTION || (iAmPrimary() && server.import_mode)) { result = EVICT_FAIL; /* We need to free memory, but policy forbids or we are in import mode. */ goto update_metrics; } diff --git a/src/replication.c b/src/replication.c index 0f582ba726..63433de865 100644 --- a/src/replication.c +++ b/src/replication.c @@ -3961,11 +3961,6 @@ void replicaofCommand(client *c) { return; } - if (server.import_mode) { - addReplyError(c, "REPLICAOF not allowed in import mode."); - return; - } - if (server.failover_state != NO_FAILOVER) { addReplyError(c, "REPLICAOF not allowed while failing over."); return; diff --git a/src/server.c b/src/server.c index c34d95bd21..3c23bde71b 100644 --- a/src/server.c +++ b/src/server.c @@ -1054,9 +1054,11 @@ void clientsCron(void) { void databasesCron(void) { /* Expire keys by random sampling. Not required for replicas * as primary will synthesize DELs for us. */ - if (server.active_expire_enabled && !server.import_mode) { + if (server.active_expire_enabled) { if (iAmPrimary()) { - activeExpireCycle(ACTIVE_EXPIRE_CYCLE_SLOW); + if (!server.import_mode) { + activeExpireCycle(ACTIVE_EXPIRE_CYCLE_SLOW); + } } else { expireReplicaKeys(); }