Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ It uses a patched valkey version to make a cluster or sentinel-like setup less p

## Limitations and requirements

* Patched valkey (patches for valkey 9.0 are included in this repo)
* Patched valkey (patches for valkey 9.1 are included in this repo)
* ZooKeeper as DCS
* Single valkey instance per host
* In clustered setup each shard must have it's own DCS prefix
Expand Down
125 changes: 57 additions & 68 deletions valkey_patches/0001_Add_replication_pause.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/src/config.c b/src/config.c
index d0158b2c4..f788aef6f 100644
index fcbaee7e9..5c58b971f 100644
--- a/src/config.c
+++ b/src/config.c
@@ -2588,6 +2588,25 @@ static int updateExtendedRedisCompat(const char **err) {
@@ -2641,6 +2641,25 @@ static int updateExtendedRedisCompat(const char **err) {
return 1;
}

Expand All @@ -28,16 +28,16 @@ index d0158b2c4..f788aef6f 100644
static int updateSighandlerEnabled(const char **err) {
UNUSED(err);
if (server.crashlog_enabled)
@@ -3241,6 +3260,7 @@ standardConfig static_configs[] = {
createBoolConfig("hide-user-data-from-log", NULL, MODIFIABLE_CONFIG, server.hide_user_data_from_log, 1, NULL, NULL),
@@ -3312,6 +3331,7 @@ standardConfig static_configs[] = {
createBoolConfig("lua-enable-insecure-api", "lua-enable-deprecated-api", MODIFIABLE_CONFIG | HIDDEN_CONFIG | PROTECTED_CONFIG, server.lua_enable_insecure_api, 0, NULL, updateLuaEnableInsecureApi),
createBoolConfig("import-mode", NULL, DEBUG_CONFIG | MODIFIABLE_CONFIG, server.import_mode, 0, NULL, NULL),
createBoolConfig("io-threads-always-active", NULL, MODIFIABLE_CONFIG | HIDDEN_CONFIG, server.io_threads_always_active, 0, NULL, NULL),
+ createBoolConfig("repl-paused", NULL, MODIFIABLE_CONFIG, server.repl_paused, 0, NULL, updateReplPaused),

/* String Configs */
createStringConfig("aclfile", NULL, IMMUTABLE_CONFIG, ALLOW_EMPTY_STRING, server.acl_filename, "", NULL, NULL),
diff --git a/src/replication.c b/src/replication.c
index 82ee9450f..25726c542 100644
index 13cbc4183..c30560b3d 100644
--- a/src/replication.c
+++ b/src/replication.c
@@ -59,7 +59,6 @@ void replicationResurrectProvisionalPrimary(void);
Expand All @@ -48,7 +48,7 @@ index 82ee9450f..25726c542 100644
void replicationSteadyStateInit(void);
void dualChannelSetupMainConnForPsync(connection *conn);
void dualChannelSyncHandleRdbLoadCompletion(void);
@@ -1069,7 +1068,7 @@ void syncCommand(client *c) {
@@ -1115,7 +1114,7 @@ void syncCommand(client *c) {

/* Refuse SYNC requests if we are a replica but the link with our primary
* is not ok... */
Expand All @@ -57,7 +57,7 @@ index 82ee9450f..25726c542 100644
addReplyError(c, "-NOMASTERLINK Can't SYNC while not connected with my master");
return;
}
@@ -5150,7 +5149,7 @@ void replicationCron(void) {
@@ -5284,7 +5283,7 @@ void replicationCron(void) {
}

/* Check if we should connect to a PRIMARY */
Expand All @@ -67,80 +67,26 @@ index 82ee9450f..25726c542 100644
connectWithPrimary();
}
diff --git a/src/server.h b/src/server.h
index 25f01a31e..95d31758e 100644
index 351b1e43c..c8e03be25 100644
--- a/src/server.h
+++ b/src/server.h
@@ -2117,6 +2117,7 @@ struct valkeyServer {
@@ -2205,6 +2205,7 @@ struct valkeyServer {
/* Synchronous replication. */
list *clients_waiting_acks; /* Clients waiting in WAIT or WAITAOF. */
int get_ack_from_replicas; /* If true we send REPLCONF GETACK. */
+ int repl_paused; /* If true we don't try to connect to master */
/* Limits */
unsigned int maxclients; /* Max number of simultaneous clients */
unsigned long long maxmemory; /* Max number of memory bytes to use */
@@ -3116,6 +3117,8 @@ void updateFailoverStatus(void);
@@ -3240,6 +3241,8 @@ void updateFailoverStatus(void);
void abortFailover(const char *err);
const char *getFailoverStateString(void);
sds getReplicaPortString(void);
+int cancelReplicationHandshake(int reconnect);
+int replicaIsInHandshakeState(void);
int sendCurrentOffsetToReplica(client *replica);
int replicaRdbVersion(client *replica);
void addRdbReplicaToPsyncWait(client *replica);
void initClientReplicationData(client *c);
diff --git a/tests/cluster/tests/99-yandex-cloud-patches.tcl b/tests/cluster/tests/99-yandex-cloud-patches.tcl
new file mode 100644
index 000000000..6d0c1007b
--- /dev/null
+++ b/tests/cluster/tests/99-yandex-cloud-patches.tcl
@@ -0,0 +1,48 @@
+# Test Yandex Cloud patches on cluster
+
+source "../tests/includes/init-tests.tcl"
+
+proc kill_clustered_redis {id} {
+ set pid [get_instance_attrib redis $id pid]
+
+ stop_instance $pid
+ set_instance_attrib redis $id pid -1
+ set_instance_attrib redis $id link you_tried_to_talk_with_killed_instance
+
+ # Remove the PID from the list of pids to kill at exit.
+ set ::pids [lsearch -all -inline -not -exact $::pids $pid]
+}
+
+test "Create a 2 node cluster (1 master and 1 replica)" {
+ create_cluster 1 1
+}
+
+test "Cluster is up" {
+ assert_cluster_state ok
+}
+
+test "Instance #1 synced with the master" {
+ wait_for_condition 1000 50 {
+ [RI 1 master_link_status] eq {up}
+ } else {
+ fail "Instance #1 master link status is not up"
+ }
+}
+
+test "Replication pause on instance #1 works" {
+ assert {[R 1 config set repl-paused yes] eq {OK}}
+ wait_for_condition 1000 50 {
+ [RI 1 master_link_status] eq {down}
+ } else {
+ fail "Instance #1 master link status is not down"
+ }
+}
+
+test "Replication resume on instance #1 works" {
+ assert {[R 1 config set repl-paused no] eq {OK}}
+ wait_for_condition 1000 50 {
+ [RI 1 master_link_status] eq {up}
+ } else {
+ fail "Instance #1 master link status is not up"
+ }
+}
diff --git a/tests/integration/yandex-cloud-patches.tcl b/tests/integration/yandex-cloud-patches.tcl
new file mode 100644
index 000000000..a2c9bb949
Expand Down Expand Up @@ -203,6 +149,49 @@ index 000000000..a2c9bb949
+ }
+ }
+}
--
2.51.1

diff --git a/tests/unit/cluster/99-yandex-cloud-patches.tcl b/tests/unit/cluster/99-yandex-cloud-patches.tcl
new file mode 100644
index 000000000..ca4d2f5ec
--- /dev/null
+++ b/tests/unit/cluster/99-yandex-cloud-patches.tcl
@@ -0,0 +1,40 @@
+# Test Yandex Cloud patches on cluster
+
+start_cluster 1 2 {tags {external:skip cluster}} {
+
+test "Cluster is up" {
+ wait_for_cluster_state ok
+}
+
+test "Instance 0 is master and 1 is replica" {
+ assert {[s 0 role] eq {master}}
+ assert {[s -1 role] eq {slave}}
+}
+
+test "Instance 1 synced with the master" {
+ wait_for_condition 1000 50 {
+ [s -1 master_link_status] eq {up}
+ } else {
+ fail "Instance 1 master link status is not up"
+ }
+}
+
+test "Replication pause on instance 1 works" {
+ assert {[R 1 config set repl-paused yes] eq {OK}}
+ wait_for_condition 1000 50 {
+ [s -1 master_link_status] eq {down}
+ } else {
+ fail "Instance 1 master link status is not down"
+ }
+}
+
+test "Replication resume on instance 1 works" {
+ assert {[R 1 config set repl-paused no] eq {OK}}
+ wait_for_condition 1000 50 {
+ [s -1 master_link_status] eq {up}
+ } else {
+ fail "Instance 1 master link status is not up"
+ }
+}
+
+}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c
index ed4768bfe..cc6fb7d1d 100644
index 63cfc13a0..10adddf5c 100644
--- a/src/cluster_legacy.c
+++ b/src/cluster_legacy.c
@@ -7733,7 +7733,7 @@ int clusterCommandSpecial(client *c) {
@@ -8120,7 +8120,7 @@ int clusterCommandSpecial(client *c) {
}

/* Can't replicate a replica. */
Expand All @@ -11,38 +11,24 @@ index ed4768bfe..cc6fb7d1d 100644
addReplyError(c, "I can only replicate a master, not a replica.");
return 1;
}
diff --git a/tests/cluster/tests/99-yandex-cloud-patches.tcl b/tests/cluster/tests/99-yandex-cloud-patches.tcl
index 6d0c1007b..04b644128 100644
--- a/tests/cluster/tests/99-yandex-cloud-patches.tcl
+++ b/tests/cluster/tests/99-yandex-cloud-patches.tcl
@@ -13,8 +13,8 @@ proc kill_clustered_redis {id} {
set ::pids [lsearch -all -inline -not -exact $::pids $pid]
}

-test "Create a 2 node cluster (1 master and 1 replica)" {
- create_cluster 1 1
+test "Create a 3 node cluster (1 master and 2 replicas)" {
+ create_cluster 1 2
}

test "Cluster is up" {
@@ -38,6 +38,16 @@ test "Replication pause on instance #1 works" {
diff --git a/tests/unit/cluster/99-yandex-cloud-patches.tcl b/tests/unit/cluster/99-yandex-cloud-patches.tcl
index ca4d2f5ec..bb7844a92 100644
--- a/tests/unit/cluster/99-yandex-cloud-patches.tcl
+++ b/tests/unit/cluster/99-yandex-cloud-patches.tcl
@@ -28,6 +28,16 @@ test "Replication pause on instance 1 works" {
}
}

+test "Replication cascade with paused instance works" {
+ assert {[R 2 config set cluster-slave-no-failover yes] eq {OK}}
+ assert {[R 2 cluster replicate [R 1 CLUSTER MYID]] eq {OK}}
+ assert {[R 2 cluster replicate [R 1 cluster myid]] eq {OK}}
+ wait_for_condition 1000 50 {
+ [RI 2 master_link_status] eq {up}
+ [s -2 master_link_status] eq {up}
+ } else {
+ fail "Instance #2 master link status is not up"
+ fail "Instance 2 master link status is not up"
+ }
+}
+
test "Replication resume on instance #1 works" {
test "Replication resume on instance 1 works" {
assert {[R 1 config set repl-paused no] eq {OK}}
wait_for_condition 1000 50 {
--
2.51.1

30 changes: 9 additions & 21 deletions valkey_patches/0003_Add_offline_mode.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/src/config.c b/src/config.c
index f788aef6f..aafa0616a 100644
index 5c58b971f..0d852e730 100644
--- a/src/config.c
+++ b/src/config.c
@@ -623,6 +623,8 @@ void loadServerConfigFromString(sds config) {
@@ -631,6 +631,8 @@ void loadServerConfigFromString(sds config) {
if (server.hz < CONFIG_MIN_HZ) server.hz = CONFIG_MIN_HZ;
if (server.hz > CONFIG_MAX_HZ) server.hz = CONFIG_MAX_HZ;

Expand All @@ -11,7 +11,7 @@ index f788aef6f..aafa0616a 100644
sdsfreesplitres(lines, totlines);
reading_config_file = 0;
return;
@@ -3206,6 +3208,31 @@ static int applyClientMaxMemoryUsage(const char **err) {
@@ -3276,6 +3278,31 @@ static int isValidDbHashSeed(sds val, const char **err) {
return 1;
}

Expand Down Expand Up @@ -43,7 +43,7 @@ index f788aef6f..aafa0616a 100644
standardConfig static_configs[] = {
/* Bool configs */
createBoolConfig("rdbchecksum", NULL, IMMUTABLE_CONFIG, server.rdb_checksum, 1, NULL, NULL),
@@ -3461,6 +3488,7 @@ standardConfig static_configs[] = {
@@ -3536,6 +3563,7 @@ standardConfig static_configs[] = {
createSpecialConfig("rdma-bind", NULL, MODIFIABLE_CONFIG | MULTI_ARG_CONFIG, setConfigRdmaBindOption, getConfigRdmaBindOption, rewriteConfigRdmaBindOption, applyRdmaBind),
createSpecialConfig("replicaof", "slaveof", IMMUTABLE_CONFIG | MULTI_ARG_CONFIG, setConfigReplicaOfOption, getConfigReplicaOfOption, rewriteConfigReplicaOfOption, NULL),
createSpecialConfig("latency-tracking-info-percentiles", NULL, MODIFIABLE_CONFIG | MULTI_ARG_CONFIG, setConfigLatencyTrackingInfoPercentilesOutputOption, getConfigLatencyTrackingInfoPercentilesOutputOption, rewriteConfigLatencyTrackingInfoPercentilesOutputOption, NULL),
Expand All @@ -52,10 +52,10 @@ index f788aef6f..aafa0616a 100644
/* NULL Terminator, this is dropped when we convert to the runtime array. */
{NULL},
diff --git a/src/server.c b/src/server.c
index 46a20d1ae..860a3cb41 100644
index e018a6182..7594a672e 100644
--- a/src/server.c
+++ b/src/server.c
@@ -2664,9 +2664,15 @@ int listenToPort(connListener *sfd) {
@@ -2717,9 +2717,15 @@ int listenToPort(connListener *sfd) {
int j;
int port = sfd->port;
char **bindaddr = sfd->bindaddr;
Expand All @@ -72,7 +72,7 @@ index 46a20d1ae..860a3cb41 100644

for (j = 0; j < sfd->bindaddr_count; j++) {
char *addr = bindaddr[j];
@@ -6865,8 +6871,8 @@ void dismissMemoryInChild(void) {
@@ -7176,8 +7182,8 @@ void dismissMemoryInChild(void) {
/* madvise(MADV_DONTNEED) may not work if Transparent Huge Pages is enabled. */
if (server.thp_enabled) return;

Expand All @@ -83,20 +83,11 @@ index 46a20d1ae..860a3cb41 100644
#if defined(USE_JEMALLOC) && defined(__linux__)
listIter li;
listNode *ln;
@@ -7311,7 +7317,7 @@ __attribute__((weak)) int main(int argc, char **argv) {
}
if (server.sentinel_mode) sentinelCheckConfigFile();

- /* Do system checks */
+ /* Do system checks */
#ifdef __linux__
linuxMemoryWarnings();
sds err_msg = NULL;
diff --git a/src/server.h b/src/server.h
index 95d31758e..a82eabd26 100644
index c8e03be25..d941665ea 100644
--- a/src/server.h
+++ b/src/server.h
@@ -2118,6 +2118,9 @@ struct valkeyServer {
@@ -2206,6 +2206,9 @@ struct valkeyServer {
list *clients_waiting_acks; /* Clients waiting in WAIT or WAITAOF. */
int get_ack_from_replicas; /* If true we send REPLCONF GETACK. */
int repl_paused; /* If true we don't try to connect to master */
Expand Down Expand Up @@ -135,6 +126,3 @@ index 000000000..b8c3ba453
+ }
+ }
+}
--
2.51.1

Loading
Loading