jstests/multiVersion/libs/multiversion_rollback.js
/**
 * Executes and validates rollback between a pair of nodes with the given versions.
 *
 * @param {string} testName the name of the test being run
 * @param {string} rollbackNodeVersion the desired version for the rollback node
 * @param {string} syncSourceVersion the desired version for the sync source
 *
 */
Executes and validates rollback between a pair of nodes with the given versions.
@param {string} testName the name of the test being run
@param {string} rollbackNodeVersion the desired version for the rollback node
@param {string} syncSourceVersion the desired version for the sync source
Executes and validates rollback between a pair of nodes with the given versions . @param { string } testName the name of the test being run @param { string } rollbackNodeVersion the desired version for the rollback node @param { string } syncSourceVersion the desired version for the sync source
function testMultiversionRollback(testName, rollbackNodeVersion, syncSourceVersion) {
    jsTestLog("Started multiversion rollback test for versions: {rollbackNode: " +
              rollbackNodeVersion + ", syncSource: " + syncSourceVersion + "}.");
    let dbName = testName;
    let CommonOps = (node) => {
        assert.commandWorked(node.getDB(dbName)["bothNodesKeep"].insert({a: 1}));
        assert.commandWorked(node.getDB(dbName)["rollbackNodeDeletes"].insert({b: 1}));
        assert.commandWorked(node.getDB(dbName)["rollbackNodeUpdates"].insert({c: 1}));
        assert.commandWorked(node.getDB(dbName)["bothNodesUpdate"].insert({d: 1}));
    };
    let RollbackOps = (node) => {
        assert.commandWorked(node.getDB(dbName)["rollbackNodeDeletes"].remove({b: 1}));
        assert.commandWorked(node.getDB(dbName)["rollbackNodeUpdates"].update({c: 1}, {c: 0}));
        assert.commandWorked(node.getDB(dbName)["bothNodesUpdate"].update({d: 1}, {d: 0}));
    };
    let SyncSourceOps = (node) => {
        assert.commandWorked(node.getDB(dbName)["bothNodesUpdate"].update({d: 1}, {d: 2}));
        assert.commandWorked(node.getDB(dbName)["syncSourceInserts"].insert({e: 1}));
    };
    let replSet = setupReplicaSet(testName, rollbackNodeVersion, syncSourceVersion);
    let rollbackTest = new RollbackTest(testName, replSet);
    CommonOps(rollbackTest.getPrimary());
    let rollbackNode = rollbackTest.transitionToRollbackOperations();
    RollbackOps(rollbackNode);
    let syncSource = rollbackTest.transitionToSyncSourceOperationsBeforeRollback();
    SyncSourceOps(syncSource);
    rollbackTest.transitionToSyncSourceOperationsDuringRollback();
    rollbackTest.transitionToSteadyStateOperations();
    rollbackTest.stop();
}
function testMultiversionRollback ( testName , rollbackNodeVersion , syncSourceVersion ) { jsTestLog ( "Started multiversion rollback test for versions: {rollbackNode: " + rollbackNodeVersion + ", syncSource: " + syncSourceVersion + "}." ) ; let dbName = testName ; let CommonOps = ( node ) => { assert . commandWorked ( node . getDB ( dbName ) [ "bothNodesKeep" ] . insert ( { a : 1 } ) ) ; assert . commandWorked ( node . getDB ( dbName ) [ "rollbackNodeDeletes" ] . insert ( { b : 1 } ) ) ; assert . commandWorked ( node . getDB ( dbName ) [ "rollbackNodeUpdates" ] . insert ( { c : 1 } ) ) ; assert . commandWorked ( node . getDB ( dbName ) [ "bothNodesUpdate" ] . insert ( { d : 1 } ) ) ; } ; let RollbackOps = ( node ) => { assert . commandWorked ( node . getDB ( dbName ) [ "rollbackNodeDeletes" ] . remove ( { b : 1 } ) ) ; assert . commandWorked ( node . getDB ( dbName ) [ "rollbackNodeUpdates" ] . update ( { c : 1 } , { c : 0 } ) ) ; assert . commandWorked ( node . getDB ( dbName ) [ "bothNodesUpdate" ] . update ( { d : 1 } , { d : 0 } ) ) ; } ; let SyncSourceOps = ( node ) => { assert . commandWorked ( node . getDB ( dbName ) [ "bothNodesUpdate" ] . update ( { d : 1 } , { d : 2 } ) ) ; assert . commandWorked ( node . getDB ( dbName ) [ "syncSourceInserts" ] . insert ( { e : 1 } ) ) ; } ; let replSet = setupReplicaSet ( testName , rollbackNodeVersion , syncSourceVersion ) ; let rollbackTest = new RollbackTest ( testName , replSet ) ; CommonOps ( rollbackTest . getPrimary ( ) ) ; let rollbackNode = rollbackTest . transitionToRollbackOperations ( ) ; RollbackOps ( rollbackNode ) ; let syncSource = rollbackTest . transitionToSyncSourceOperationsBeforeRollback ( ) ; SyncSourceOps ( syncSource ) ; rollbackTest . transitionToSyncSourceOperationsDuringRollback ( ) ; rollbackTest . transitionToSteadyStateOperations ( ) ; rollbackTest . stop ( ) ; }
Executes and validates rollback between a pair of nodes with the given versions.
Executes and validates rollback between a pair of nodes with the given versions .
// Insert four documents on both nodes. // Perform operations only on the rollback node: //   1. Delete a document. //   2. Update a document only on this node. //   3. Update a document on both nodes. // All three documents will be refetched during rollback. // Perform operations only on the sync source: //   1. Make a conflicting write on one of the documents the rollback node updates. //   2. Insert a new document. // Set up replica set. // Set up Rollback Test. // Perform operations that will be rolled back. // Perform different operations only on the sync source. // Wait for rollback to finish.