Skip to content

Commit d99d06b

Browse files
committed
Add multi-master-no-forward command to reduce bus traffic with multi-master
1 parent 1b9ade7 commit d99d06b

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

keydb.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,12 @@ jemalloc-bg-thread yes
18151815
# Tuning this parameter is a tradeoff between locking overhead and distributing the workload over multiple cores
18161816
# min-clients-per-thread 50
18171817

1818+
# Avoid forwarding RREPLAY messages to other masters?
1819+
# WARNING: This setting is dangerous! You must be certain all masters are connected to each
1820+
# other in a true mesh topology or data loss will occur!
1821+
# This command can be used to reduce multimaster bus traffic
1822+
# multi-master-no-forward no
1823+
18181824
# Path to directory for file backed scratchpad. The file backed scratchpad
18191825
# reduces memory requirements by storing rarely accessed data on disk
18201826
# instead of RAM. A temporary file will be created in this directory.

src/config.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,13 @@ static int updateMaxclients(long long val, long long prev, const char **err) {
21672167
return 1;
21682168
}
21692169

2170+
static int validateMultiMasterNoForward(int val, const char **) {
2171+
if (val) {
2172+
serverLog(LL_WARNING, "WARNING: multi-master-no-forward is set, you *must* use a mesh topology or dataloss will occur");
2173+
}
2174+
return 1;
2175+
}
2176+
21702177
#ifdef USE_OPENSSL
21712178
static int updateTlsCfg(char *val, char *prev, const char **err) {
21722179
UNUSED(val);
@@ -2222,6 +2229,7 @@ standardConfig configs[] = {
22222229
createBoolConfig("cluster-enabled", NULL, IMMUTABLE_CONFIG, g_pserver->cluster_enabled, 0, NULL, NULL),
22232230
createBoolConfig("appendonly", NULL, MODIFIABLE_CONFIG, g_pserver->aof_enabled, 0, NULL, updateAppendonly),
22242231
createBoolConfig("cluster-allow-reads-when-down", NULL, MODIFIABLE_CONFIG, g_pserver->cluster_allow_reads_when_down, 0, NULL, NULL),
2232+
createBoolConfig("multi-master-no-forward", NULL, MODIFIABLE_CONFIG, cserver.multimaster_no_forward, 0, validateMultiMasterNoForward, NULL),
22252233

22262234
/* String Configs */
22272235
createStringConfig("aclfile", NULL, IMMUTABLE_CONFIG, ALLOW_EMPTY_STRING, g_pserver->acl_filename, "", NULL, NULL),

src/replication.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4251,7 +4251,7 @@ void replicaReplayCommand(client *c)
42514251
serverTL->current_client = current_clientSave;
42524252

42534253
// call() will not propogate this for us, so we do so here
4254-
if (!s_pstate->FCancelled() && s_pstate->FFirst())
4254+
if (!s_pstate->FCancelled() && s_pstate->FFirst() && !cserver.multimaster_no_forward)
42554255
alsoPropagate(cserver.rreplayCommand,c->db->id,c->argv,c->argc,PROPAGATE_AOF|PROPAGATE_REPL);
42564256

42574257
s_pstate->Pop();

src/server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,7 @@ struct redisServerConst {
16481648
unsigned char uuid[UUID_BINARY_LEN]; /* This server's UUID - populated on boot */
16491649
bool fUsePro = false;
16501650
int thread_min_client_threshold = 50;
1651+
int multimaster_no_forward;
16511652
};
16521653

16531654
struct redisServer {

tests/integration/replication-multimaster.tcl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
foreach topology {mesh ring} {
2+
3+
foreach noforward [expr {[string equal $topology "mesh"] ? {no yes} : {no}}] {
24
start_server {tags {"multi-master"} overrides {hz 500 active-replica yes multi-master yes}} {
35
start_server {overrides {hz 500 active-replica yes multi-master yes}} {
46
start_server {overrides {hz 500 active-replica yes multi-master yes}} {
@@ -8,8 +10,12 @@ start_server {overrides {hz 500 active-replica yes multi-master yes}} {
810
set R($j) [srv [expr 0-$j] client]
911
set R_host($j) [srv [expr 0-$j] host]
1012
set R_port($j) [srv [expr 0-$j] port]
13+
14+
$R($j) config set multi-master-no-forward $noforward
1115
}
1216

17+
set topology_name "$topology[expr {[string equal $noforward "yes"] ? " no-forward" : ""}]"
18+
1319
# Initialize as mesh
1420
if [string equal $topology "mesh"] {
1521
for {set j 0} {$j < 4} {incr j} {
@@ -31,7 +37,7 @@ start_server {overrides {hz 500 active-replica yes multi-master yes}} {
3137
$R(3) replicaof $R_host(2) $R_port(2)
3238
}
3339

34-
test "$topology all nodes up" {
40+
test "$topology_name all nodes up" {
3541
for {set j 0} {$j < 4} {incr j} {
3642
wait_for_condition 50 100 {
3743
[string match {*master_global_link_status:up*} [$R($j) info replication]]
@@ -41,7 +47,7 @@ start_server {overrides {hz 500 active-replica yes multi-master yes}} {
4147
}
4248
}
4349

44-
test "$topology replicates to all nodes" {
50+
test "$topology_name replicates to all nodes" {
4551
$R(0) set testkey foo
4652
after 500
4753
for {set n 0} {$n < 4} {incr n} {
@@ -53,7 +59,7 @@ start_server {overrides {hz 500 active-replica yes multi-master yes}} {
5359
}
5460
}
5561

56-
test "$topology replicates only once" {
62+
test "$topology_name replicates only once" {
5763
$R(0) set testkey 1
5864
after 500
5965
#wait_for_condition 50 100 {
@@ -74,7 +80,7 @@ start_server {overrides {hz 500 active-replica yes multi-master yes}} {
7480
}
7581
}
7682

77-
test "$topology transaction replicates only once" {
83+
test "$topology_name transaction replicates only once" {
7884
for {set j 0} {$j < 1000} {incr j} {
7985
$R(0) set testkey 1
8086
$R(0) multi
@@ -95,3 +101,4 @@ start_server {overrides {hz 500 active-replica yes multi-master yes}} {
95101
}
96102
}
97103
}
104+
}

0 commit comments

Comments
 (0)