diff options
author | XueruiFa <xuerui.fa@mongodb.com> | 2021-05-13 20:39:09 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-05-19 20:18:58 +0000 |
commit | df68527f18b9353853849ff52dd0f4f600e2f15e (patch) | |
tree | 24e7c6dac2b1614b6a7e5e885167f39c4547df21 /src/mongo/shell | |
parent | 47f09ef73c7f9782312a2e72a2d7b95879648d0f (diff) | |
download | mongo-df68527f18b9353853849ff52dd0f4f600e2f15e.tar.gz |
SERVER-56919: Add validation for memberIndex to reconfigToPSASet() shell helper
(cherry picked from commit 3192123cbc96d4c8121bd9849e70fd8b79eb37a9)
Diffstat (limited to 'src/mongo/shell')
-rw-r--r-- | src/mongo/shell/utils.js | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js index c115bb58313..d06c96b2989 100644 --- a/src/mongo/shell/utils.js +++ b/src/mongo/shell/utils.js @@ -1568,13 +1568,38 @@ rs.reconfig = function(cfg, options) { } return this._runCmd(cmd); }; + +_validateMemberIndex = function(memberIndex, newConfig) { + const newMemberConfig = newConfig.members[memberIndex]; + assert(newMemberConfig, `Node at index ${memberIndex} does not exist in the new config`); + assert.eq(1, + newMemberConfig.votes, + `Node at index ${memberIndex} must have {votes: 1} in the new config`); + + // Use memberId to compare nodes across configs. + const memberId = newMemberConfig._id; + const oldConfig = rs.conf(); + const oldMemberConfig = oldConfig.members.find(member => member._id === memberId); + + // If the node doesn't exist in the old config, we are adding it as a new node. Skip validating + // the node in the old config. + if (!oldMemberConfig) { + return; + } + + assert(!oldMemberConfig.votes, + `Node at index ${memberIndex} must have {votes: 0} in the old config`); +}; + rs.reconfigForPSASet = function(memberIndex, cfg, options) { + _validateMemberIndex(memberIndex, cfg); + const memberPriority = cfg.members[memberIndex].priority; print( `Running first reconfig to give member at index ${memberIndex} { votes: 1, priority: 0 }`); cfg.members[memberIndex].votes = 1; cfg.members[memberIndex].priority = 0; - const res = rs.reconfig(cfg, options); + let res = rs.reconfig(cfg, options); if (!res.ok) { return res; } @@ -1582,7 +1607,15 @@ rs.reconfigForPSASet = function(memberIndex, cfg, options) { print(`Running second reconfig to give member at index ${memberIndex} { priority: ${ memberPriority} }`); cfg.members[memberIndex].priority = memberPriority; - return rs.reconfig(cfg, options); + + // If the first reconfig added a new node, the second config will not succeed until the + // automatic reconfig to remove the 'newlyAdded' field is completed. Retry the second reconfig + // until it succeeds in that case. + assert.soon(() => { + res = rs.reconfig(cfg, options); + return res.ok; + }); + return res; }; rs.add = function(hostport, arb) { let res; |