summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarolyn Duan <carolyn.duan@mongodb.com>2021-06-17 20:20:02 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-07-21 17:55:20 +0000
commit8c84b30cb03a0091cc814e023ae2c050d5fb57ee (patch)
tree5ee7b510088eccf0f1289428664a85eba57a4e00
parenta7a1e979b0dc81a4194609a34a04b63fd37e165c (diff)
downloadmongo-8c84b30cb03a0091cc814e023ae2c050d5fb57ee.tar.gz
SERVER-37904 Add enableOverrideClusterChainingSetting server parameter
(cherry picked from commit 7422c1b638d2e4b200e7b72041d76f5702364d2b)
-rw-r--r--etc/backports_required_for_multiversion_tests.yml2
-rw-r--r--jstests/replsets/cluster_chaining_override.js40
-rw-r--r--src/mongo/db/repl/SConscript1
-rw-r--r--src/mongo/db/repl/repl_server_parameters.idl10
-rw-r--r--src/mongo/db/repl/topology_coordinator.cpp12
5 files changed, 60 insertions, 5 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml
index 572e3d98a42..da3236a4886 100644
--- a/etc/backports_required_for_multiversion_tests.yml
+++ b/etc/backports_required_for_multiversion_tests.yml
@@ -159,6 +159,8 @@ all:
test_file: jstests/sharding/cleanup_orphaned_cmd_during_movechunk.js
- ticket: SERVER-52906
test_file: jstests/sharding/cleanup_orphaned_cmd_during_movechunk_hashed.js
+ - ticket: SERVER-37904
+ test_file: jstests/replsets/cluster_chaining_override.js
suites:
diff --git a/jstests/replsets/cluster_chaining_override.js b/jstests/replsets/cluster_chaining_override.js
new file mode 100644
index 00000000000..5a913c3096e
--- /dev/null
+++ b/jstests/replsets/cluster_chaining_override.js
@@ -0,0 +1,40 @@
+/**
+ * Tests that if chaining is disabled, enabling the server parameter
+ * 'enableOverrideClusterChainingSetting' will allow the node to chain anyway.
+ */
+
+(function() {
+"use strict";
+load("jstests/replsets/rslib.js");
+
+let rst = new ReplSetTest({
+ nodes: {
+ n0: {},
+ n1: {rsConfig: {priority: 0}},
+ n2: {rsConfig: {priority: 0}, setParameter: {enableOverrideClusterChainingSetting: true}}
+ },
+ // Enable the periodic noop writer to aid sync source selection.
+ nodeOptions: {setParameter: {writePeriodicNoops: true}},
+ settings: {chainingAllowed: false},
+ useBridge: true
+});
+rst.startSet();
+rst.initiate();
+
+const primary = rst.getPrimary();
+rst.awaitSecondaryNodes();
+const [n1, n2] = rst.getSecondaries();
+
+// Create a network partition between n2 and the primary.
+n2.disconnect(primary);
+
+// Since n2 has enabled the parameter 'enableOverrideClusterChainingSetting', n2 should eventually
+// chain from n1.
+rst.awaitSyncSource(n2, n1);
+
+// A write with write concern {w:3} should still reach n2.
+var options = {writeConcern: {w: 3, wtimeout: ReplSetTest.kDefaultTimeoutMS}};
+assert.commandWorked(primary.getDB("admin").foo.insert({x: 1}, options));
+
+rst.stopSet();
+}()); \ No newline at end of file
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript
index dadd94cb10d..cda28665b2e 100644
--- a/src/mongo/db/repl/SConscript
+++ b/src/mongo/db/repl/SConscript
@@ -667,6 +667,7 @@ env.Library('topology_coordinator',
LIBDEPS_PRIVATE=[
'$BUILD_DIR/mongo/db/catalog/commit_quorum_options',
'$BUILD_DIR/mongo/idl/server_parameter',
+ 'repl_server_parameters'
])
env.Library(
diff --git a/src/mongo/db/repl/repl_server_parameters.idl b/src/mongo/db/repl/repl_server_parameters.idl
index befa9891c42..2e06b7101f7 100644
--- a/src/mongo/db/repl/repl_server_parameters.idl
+++ b/src/mongo/db/repl/repl_server_parameters.idl
@@ -307,6 +307,16 @@ server_parameters:
cpp_varname: assertStableTimestampEqualsAppliedThroughOnRecovery
default: false
+ enableOverrideClusterChainingSetting:
+ description: >-
+ When enabled, allows a node to override the cluster-wide chainingAllowed setting.
+ If chaining is disabled in the replica set, enabling this parameter allows the node
+ to chain regardless.
+ set_at: [ startup ]
+ cpp_vartype: AtomicWord<bool>
+ cpp_varname: enableOverrideClusterChainingSetting
+ default: false
+
startupRecoveryForRestore:
description: >-
When set, do startup recovery in such a way that the history of the recovered
diff --git a/src/mongo/db/repl/topology_coordinator.cpp b/src/mongo/db/repl/topology_coordinator.cpp
index ea679f51ba0..6dd1b2d6117 100644
--- a/src/mongo/db/repl/topology_coordinator.cpp
+++ b/src/mongo/db/repl/topology_coordinator.cpp
@@ -55,6 +55,7 @@
#include "mongo/db/repl/heartbeat_response_action.h"
#include "mongo/db/repl/isself.h"
#include "mongo/db/repl/member_data.h"
+#include "mongo/db/repl/repl_server_parameters_gen.h"
#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/oplog_query_metadata.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
@@ -213,7 +214,7 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now,
// If we are only allowed to sync from the primary, use it as the sync source if possible.
if (readPreference == ReadPreference::PrimaryOnly ||
(chainingPreference == ChainingPreference::kUseConfiguration &&
- !_rsConfig.isChainingAllowed())) {
+ !_rsConfig.isChainingAllowed() && !enableOverrideClusterChainingSetting.load())) {
if (readPreference == ReadPreference::SecondaryOnly) {
LOGV2_FATAL(
3873102,
@@ -2951,10 +2952,11 @@ bool TopologyCoordinator::shouldChangeSyncSource(const HostAndPort& currentSourc
bool sourceIsPrimary =
replMetadata.getIsPrimary().value_or(oqMetadata.getPrimaryIndex() == currentSourceIndex);
- // Change sync source if chaining is disabled, we are not syncing from the primary, and we know
- // who the new primary is. We do not consider chaining disabled if we are the primary, since
- // we are in catchup mode.
- auto chainingDisabled = !_rsConfig.isChainingAllowed() && _currentPrimaryIndex != _selfIndex;
+ // Change sync source if chaining is disabled (without overrides), we are not syncing from the
+ // primary, and we know who the new primary is. We do not consider chaining disabled if we are
+ // the primary, since we are in catchup mode.
+ auto chainingDisabled = !_rsConfig.isChainingAllowed() &&
+ !enableOverrideClusterChainingSetting.load() && _currentPrimaryIndex != _selfIndex;
auto foundNewPrimary = _currentPrimaryIndex != -1 && _currentPrimaryIndex != currentSourceIndex;
if (!sourceIsPrimary && chainingDisabled && foundNewPrimary) {
auto newPrimary = _rsConfig.getMemberAt(_currentPrimaryIndex).getHostAndPort();