summaryrefslogtreecommitdiff
path: root/jstests/replsets/rslib.js
diff options
context:
space:
mode:
authorXuerui Fa <xuerui.fa@mongodb.com>2020-03-30 11:36:25 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-04-09 18:51:46 +0000
commit40ba53c90d745aa3da6445c533458146eea1755b (patch)
tree4a7dad0fdf8090d68c6eaed95362c7b7e07e95f3 /jstests/replsets/rslib.js
parent6328c0782c55a5c73a1c1d96a3845eda98dfcd2d (diff)
downloadmongo-40ba53c90d745aa3da6445c533458146eea1755b.tar.gz
SERVER-46348: Test behavior when user provides newlyAdded field in force reconfig
Diffstat (limited to 'jstests/replsets/rslib.js')
-rw-r--r--jstests/replsets/rslib.js24
1 files changed, 17 insertions, 7 deletions
diff --git a/jstests/replsets/rslib.js b/jstests/replsets/rslib.js
index 14953216ab9..564dbf37fcb 100644
--- a/jstests/replsets/rslib.js
+++ b/jstests/replsets/rslib.js
@@ -715,21 +715,31 @@ assertSameConfigContent = function(configA, configB) {
configB.term = termB;
};
-isMemberNewlyAdded = function(node, memberIndex) {
+isMemberNewlyAdded = function(node, memberIndex, force = false) {
// The in-memory config will not include the 'newlyAdded' field, so we must consult the on-disk
// version. However, the in-memory config is updated after the config is persisted to disk, so
// we must confirm that the in-memory config agrees with the on-disk config, before returning
// true or false.
const configInMemory = assert.commandWorked(node.adminCommand({replSetGetConfig: 1})).config;
- const configVersion = configInMemory.version;
- const configTerm = configInMemory.term;
- if (!configVersion || !configTerm) {
+
+ const versionSetInMemory = configInMemory.hasOwnProperty("version");
+ const termSetInMemory = configInMemory.hasOwnProperty("term");
+
+ // Since the term is not set in a force reconfig, we skip the check for the term if
+ // 'force=true'.
+ if (!versionSetInMemory || (!termSetInMemory && !force)) {
throw new Error("isMemberNewlyAdded: in-memory config has no version or term: " +
tojsononeline(configInMemory));
}
const configOnDisk = node.getDB("local").system.replset.findOne();
- if ((configOnDisk.version !== configVersion) || (configOnDisk.term !== configTerm)) {
+ const termSetOnDisk = configOnDisk.hasOwnProperty("term");
+
+ const isVersionSetCorrectly = (configOnDisk.version === configInMemory.version);
+ const isTermSetCorrectly =
+ ((!termSetInMemory && !termSetOnDisk) || (configOnDisk.term === configInMemory.term));
+
+ if (!isVersionSetCorrectly || !isTermSetCorrectly) {
throw new error(
"isMemberNewlyAdded: in-memory config version/term does not match on-disk config." +
" in-memory: " + tojsononeline(configInMemory) +
@@ -744,10 +754,10 @@ isMemberNewlyAdded = function(node, memberIndex) {
return false;
};
-waitForNewlyAddedRemovalForNodeToBeCommitted = function(node, memberIndex) {
+waitForNewlyAddedRemovalForNodeToBeCommitted = function(node, memberIndex, force = false) {
jsTestLog("Waiting for member " + memberIndex + " to no longer be 'newlyAdded'");
assert.soonNoExcept(function() {
- return !isMemberNewlyAdded(node, memberIndex) && isConfigCommitted(node);
+ return !isMemberNewlyAdded(node, memberIndex, force) && isConfigCommitted(node);
}, () => tojson(node.getDB("local").system.replset.findOne()));
};
}());