diff options
author | Ali Mir <ali.mir@mongodb.com> | 2020-02-22 04:12:19 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-02-22 04:12:19 +0000 |
commit | c4b918f7335495a8d5fc7f70ed14a9d674a4f289 (patch) | |
tree | 355040a47f4ccfbf408fced866fc272ce9da0c65 | |
parent | 36cdf610b30d1a96fc0d54f5694c4034c84d140b (diff) | |
download | mongo-c4b918f7335495a8d5fc7f70ed14a9d674a4f289.tar.gz |
SERVER-45089 Assert force reconfig with missing term field results in default -1 term
-rw-r--r-- | jstests/replsets/reconfig_ignores_term_field.js | 15 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.cpp | 6 |
2 files changed, 19 insertions, 2 deletions
diff --git a/jstests/replsets/reconfig_ignores_term_field.js b/jstests/replsets/reconfig_ignores_term_field.js index 2cc48ac950d..82971834432 100644 --- a/jstests/replsets/reconfig_ignores_term_field.js +++ b/jstests/replsets/reconfig_ignores_term_field.js @@ -26,5 +26,20 @@ replTest.awaitReplication(); config = primary.getDB("local").system.replset.findOne(); assert.eq(config.term, 1); + +jsTestLog("Force reconfig ignores user provided term"); +config.term = 55; +config.version++; +assert.commandWorked(primary.getDB("admin").runCommand({replSetReconfig: config, force: true})); +config = primary.getDB("local").system.replset.findOne(); +assert.eq(config.term, -1); + +jsTestLog("Force reconfig with missing term results in term -1"); +delete config.term; +config.version++; +assert.commandWorked(primary.getDB("admin").runCommand({replSetReconfig: config, force: true})); +config = primary.getDB("local").system.replset.findOne(); +assert.eq(config.term, -1); + replTest.stopSet(); }());
\ No newline at end of file diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index 751f971a648..290223fc358 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -2922,7 +2922,6 @@ Status ReplicationCoordinatorImpl::processReplSetReconfig(OperationContext* opCt makeGuard([&] { lockAndCall(&lk, [=] { _setConfigState_inlock(kConfigSteady); }); }); ReplSetConfig oldConfig = _rsConfig; - auto topCoordTerm = _topCoord->getTerm(); lk.unlock(); ReplSetConfig newConfig; @@ -2936,7 +2935,10 @@ Status ReplicationCoordinatorImpl::processReplSetReconfig(OperationContext* opCt // When initializing a new config through the replSetReconfig command, ignore the term // field passed in through its args. Instead, use this node's term. - Status status = newConfig.initialize(newConfigObj, topCoordTerm, oldConfig.getReplicaSetId()); + // If it is a force reconfig, explicitly set the term to -1. + + auto term = !args.force ? _topCoord->getTerm() : OpTime::kUninitializedTerm; + Status status = newConfig.initialize(newConfigObj, term, oldConfig.getReplicaSetId()); if (!status.isOK()) { LOGV2_ERROR(21418, "replSetReconfig got {status} while parsing {newConfigObj}", |