jstests/replsets/rslib.js
/**
 * Run a 'replSetReconfig' command with one retry on NodeNotFound and multiple retries on
 * ConfigurationInProgress, CurrentConfigNotCommittedYet, and
 * NewReplicaSetConfigurationIncompatible.
 * Expect the reconfig to fail if shouldFail is set to true.
 */
Run a 'replSetReconfig' command with one retry on NodeNotFound and multiple retries on
ConfigurationInProgress, CurrentConfigNotCommittedYet, and
NewReplicaSetConfigurationIncompatible.
Expect the reconfig to fail if shouldFail is set to true.
Run a ' replSetReconfig ' command with one retry on NodeNotFound and multiple retries on ConfigurationInProgress CurrentConfigNotCommittedYet and NewReplicaSetConfigurationIncompatible . Expect the reconfig to fail if shouldFail is set to true .
function reconfigWithRetry(primary, config, force, shouldFail = false, errCode, errMsg) {
    const admin = primary.getDB("admin");
    force = force || false;
    let reconfigCommand = {
        replSetReconfig: config,
        force: force,
        maxTimeMS: ReplSetTest.kDefaultTimeoutMS
    };
    assert.soon(function() {
        const newVersion =
            assert.commandWorked(admin.runCommand({replSetGetConfig: 1})).config.version + 1;
        reconfigCommand.replSetReconfig.version = newVersion;
        let res = admin.runCommand(reconfigCommand);
        if (!res.ok && res.code === ErrorCodes.NodeNotFound) {
            print("Replset reconfig failed because quorum check failed. Retry reconfig once. " +
                  "Error: " + tojson(res));
            res = admin.runCommand(reconfigCommand);
        }
        if (!res.ok &&
            (res.code === ErrorCodes.ConfigurationInProgress ||
             res.code === ErrorCodes.CurrentConfigNotCommittedYet)) {
            print("Replset reconfig failed since another configuration is in progress. Retry.");
            return false;
        }
        if (!res.ok && res.code === ErrorCodes.NewReplicaSetConfigurationIncompatible) {
            const curVersion =
                assert.commandWorked(admin.runCommand({replSetGetConfig: 1})).config.version;
            if (curVersion >= newVersion) {
                print("Replset reconfig failed since the config version was too low. Retry. " +
                      "Error: " + tojson(res));
                return false;
            }
        }
        if (!shouldFail) {
            assert.commandWorked(res);
        } else {
            assert.commandFailed(res);
            if (errCode) {
                assert.eq(res.code, errCode);
            }
            if (errMsg) {
                assert(res.errmsg.includes(errMsg));
            }
        }
        return true;
    });
}
function reconfigWithRetry ( primary , config , force , shouldFail = false , errCode , errMsg ) { const admin = primary . getDB ( "admin" ) ; force = force || false ; let reconfigCommand = { replSetReconfig : config , force : force , maxTimeMS : ReplSetTest . kDefaultTimeoutMS } ; assert . soon ( function ( ) { const newVersion = assert . commandWorked ( admin . runCommand ( { replSetGetConfig : 1 } ) ) . config . version + 1 ; reconfigCommand . replSetReconfig . version = newVersion ; let res = admin . runCommand ( reconfigCommand ) ; if ( ! res . ok && res . code === ErrorCodes . NodeNotFound ) { print ( "Replset reconfig failed because quorum check failed. Retry reconfig once. " + "Error: " + tojson ( res ) ) ; res = admin . runCommand ( reconfigCommand ) ; } if ( ! res . ok && ( res . code === ErrorCodes . ConfigurationInProgress || res . code === ErrorCodes . CurrentConfigNotCommittedYet ) ) { print ( "Replset reconfig failed since another configuration is in progress. Retry." ) ; return false ; } if ( ! res . ok && res . code === ErrorCodes . NewReplicaSetConfigurationIncompatible ) { const curVersion = assert . commandWorked ( admin . runCommand ( { replSetGetConfig : 1 } ) ) . config . version ; if ( curVersion >= newVersion ) { print ( "Replset reconfig failed since the config version was too low. Retry. " + "Error: " + tojson ( res ) ) ; return false ; } } if ( ! shouldFail ) { assert . commandWorked ( res ) ; } else { assert . commandFailed ( res ) ; if ( errCode ) { assert . eq ( res . code , errCode ) ; } if ( errMsg ) { assert ( res . errmsg . includes ( errMsg ) ) ; } } return true ; } ) ; }
Run a 'replSetReconfig' command with one retry on NodeNotFound and multiple retries on
 ConfigurationInProgress, CurrentConfigNotCommittedYet, and
 NewReplicaSetConfigurationIncompatible.
Run a ' replSetReconfig ' command with one retry on NodeNotFound and multiple retries on ConfigurationInProgress CurrentConfigNotCommittedYet and NewReplicaSetConfigurationIncompatible .
// Retry reconfig if quorum check failed because not enough voting nodes responded. One // reason for this is if the connections used for heartbeats get closed on the destination // node. // Always retry on these errors, even if we already retried on NodeNotFound. // Retry. // Always retry on NewReplicaSetConfigurationIncompatible, if the current config version is // higher than the requested one. // Retry.