jstests/replsets/libs/rollback_test.js
/**
     * Validate and use the provided replica set.
     *
     * @param {Object} replSet the ReplSetTest instance to adopt
     */
Validate and use the provided replica set.
@param {Object} replSet the ReplSetTest instance to adopt
Validate and use the provided replica set . @param { Object } replSet the ReplSetTest instance to adopt
function validateAndUseSetup(replSet) {
        assert.eq(true,
                  replSet instanceof ReplSetTest,
                  `Must provide an instance of ReplSetTest. Have: ${tojson(replSet)}`);
        assert.eq(true, replSet.usesBridge(), "Must set up ReplSetTest with mongobridge enabled.");
        assert.eq(3, replSet.nodes.length, "Replica set must contain exactly three nodes.");
        curPrimary = replSet.getPrimary();
        assert.commandWorked(curPrimary.adminCommand(
            {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}}));
        replSet.awaitReplication();
        let secondaries = replSet.getSecondaries();
        let config = replSet.getReplSetConfigFromNode();
        assert.eq(config.settings.chainingAllowed,
                  false,
                  "Must set up ReplSetTest with chaining disabled.");
        assert.gte(config.settings.electionTimeoutMillis,
                   ReplSetTest.kForeverMillis,
                   "Must initiate the replset with high election timeout");
        assert.neq(0, config.members[0].priority);
        assert.eq(config.members[0].host, curPrimary.host);
        assert.neq(config.members[1].priority, config.members[2].priority);
        curSecondary = (config.members[1].priority !== 0) ? secondaries[0] : secondaries[1];
        tiebreakerNode = (config.members[2].priority === 0) ? secondaries[1] : secondaries[0];
        waitForState(curSecondary, ReplSetTest.State.SECONDARY);
        waitForState(tiebreakerNode, ReplSetTest.State.SECONDARY);
        replSet.nodes.forEach((node) => {
            configureFailPoint(
                node, "forceBgSyncSyncSourceRetryWaitMS", {sleepMS: kRetryIntervalMS});
            setFastGetMoreEnabled(node);
        });
        rst = replSet;
        lastRBID = assert.commandWorked(curSecondary.adminCommand("replSetGetRBID")).rbid;
        const dbName = "EnsureAnyNodeCanSyncFromAnyOther";
        assert.commandWorked(curPrimary.getDB(dbName).ensureSyncSource.insert(
            {thisDocument: 'is inserted to ensure any node can sync from any other'},
            {writeConcern: {w: 3, j: config.writeConcernMajorityJournalDefault}}));
    }
function validateAndUseSetup ( replSet ) { assert . eq ( true , replSet instanceof ReplSetTest , ` ${ tojson ( replSet ) } ` ) ; assert . eq ( true , replSet . usesBridge ( ) , "Must set up ReplSetTest with mongobridge enabled." ) ; assert . eq ( 3 , replSet . nodes . length , "Replica set must contain exactly three nodes." ) ; curPrimary = replSet . getPrimary ( ) ; assert . commandWorked ( curPrimary . adminCommand ( { setDefaultRWConcern : 1 , defaultWriteConcern : { w : 1 } , writeConcern : { w : "majority" } } ) ) ; replSet . awaitReplication ( ) ; let secondaries = replSet . getSecondaries ( ) ; let config = replSet . getReplSetConfigFromNode ( ) ; assert . eq ( config . settings . chainingAllowed , false , "Must set up ReplSetTest with chaining disabled." ) ; assert . gte ( config . settings . electionTimeoutMillis , ReplSetTest . kForeverMillis , "Must initiate the replset with high election timeout" ) ; assert . neq ( 0 , config . members [ 0 ] . priority ) ; assert . eq ( config . members [ 0 ] . host , curPrimary . host ) ; assert . neq ( config . members [ 1 ] . priority , config . members [ 2 ] . priority ) ; curSecondary = ( config . members [ 1 ] . priority !== 0 ) ? secondaries [ 0 ] : secondaries [ 1 ] ; tiebreakerNode = ( config . members [ 2 ] . priority === 0 ) ? secondaries [ 1 ] : secondaries [ 0 ] ; waitForState ( curSecondary , ReplSetTest . State . SECONDARY ) ; waitForState ( tiebreakerNode , ReplSetTest . State . SECONDARY ) ; replSet . nodes . forEach ( ( node ) => { configureFailPoint ( node , "forceBgSyncSyncSourceRetryWaitMS" , { sleepMS : kRetryIntervalMS } ) ; setFastGetMoreEnabled ( node ) ; } ) ; rst = replSet ; lastRBID = assert . commandWorked ( curSecondary . adminCommand ( "replSetGetRBID" ) ) . rbid ; const dbName = "EnsureAnyNodeCanSyncFromAnyOther" ; assert . commandWorked ( curPrimary . getDB ( dbName ) . ensureSyncSource . insert ( { thisDocument : 'is inserted to ensure any node can sync from any other' } , { writeConcern : { w : 3 , j : config . writeConcernMajorityJournalDefault } } ) ) ; }
Validate and use the provided replica set.
Validate and use the provided replica set .
// Make sure we have a primary. // The default WC is majority and we must use w:1 to be able to properly test rollback. // Extract the other two nodes and wait for them to be ready. // Make sure chaining is disabled, so that the tiebreaker cannot be used as a sync source. // Make sure electionTimeoutMillis is set to high value to avoid unplanned elections in // the rollback test. // Make sure the primary is not a priority: 0 node. // Make sure that of the two secondaries, one is a priority: 0 node and the other is not. // Make sync source selection faster. // Insert a document and replicate it to all 3 nodes so that any of the nodes can sync from // any other. If we do not do this, then due to initial sync timing and sync source // selection all nodes may not be guaranteed to have overlapping oplogs. // To prevent losing this document due to unclean shutdowns, we need to // ensure the insert was replicated and written to the on-disk journal of all 3 // nodes, with the exception of ephemeral and in-memory storage engines where // journaling isn't supported.