Skip to content

Commit

Permalink
import-mode only takes effect on primary
Browse files Browse the repository at this point in the history
Signed-off-by: lvyanqi.lyq <lvyanqi.lyq@alibaba-inc.com>
  • Loading branch information
lyq2333 committed Nov 13, 2024
1 parent be13edc commit 7b1127e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 27 deletions.
5 changes: 0 additions & 5 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
15 changes: 1 addition & 14 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/evict.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 0 additions & 5 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 7b1127e

Please sign in to comment.