jstests/replsets/initial_sync_replicates_prepare_received_during_another_initial_sync.js
/**
 * Restarts a secondary node so that it goes through initial sync and forces it to sync from
 * a specific sync source.
 *
 * We will confirm that the secondary properly replicated the prepare oplog entry by performing
 * an afterClusterTime read that encounters a prepare conflict.
 *
 */
Restarts a secondary node so that it goes through initial sync and forces it to sync from
a specific sync source.

We will confirm that the secondary properly replicated the prepare oplog entry by performing
an afterClusterTime read that encounters a prepare conflict.
Restarts a secondary node so that it goes through initial sync and forces it to sync from a specific sync source . We will confirm that the secondary properly replicated the prepare oplog entry by performing an afterClusterTime read that encounters a prepare conflict .
function restartSecondaryAndForceSyncSource(replSet, secondary, syncSource, dbName, clusterTime) {
    replSet.stop(secondary,
                 undefined,
                 {skipValidation: true});
    replSet.start(secondary,
                  {
                      startClean: true,
                      setParameter: {
                          'failpoint.forceSyncSourceCandidate':
                              tojson({mode: 'alwaysOn', data: {hostAndPort: syncSource.host}}),
                      }
                  },
                  true );
    waitForState(secondary, ReplSetTest.State.SECONDARY);
    secondary.setSecondaryOk();
    const secondaryDB = secondary.getDB(dbName);
    assert.commandFailedWithCode(
        secondaryDB.runCommand({
            find: name,
            filter: {_id: 0},
            readConcern: {afterClusterTime: clusterTime},
            maxTimeMS: 5000
        }),
        ErrorCodes.MaxTimeMSExpired);
}
function restartSecondaryAndForceSyncSource ( replSet , secondary , syncSource , dbName , clusterTime ) { replSet . stop ( secondary , undefined , { skipValidation : true } ) ; replSet . start ( secondary , { startClean : true , setParameter : { 'failpoint.forceSyncSourceCandidate' : tojson ( { mode : 'alwaysOn' , data : { hostAndPort : syncSource . host } } ) , } } , true ) ; waitForState ( secondary , ReplSetTest . State . SECONDARY ) ; secondary . setSecondaryOk ( ) ; const secondaryDB = secondary . getDB ( dbName ) ; assert . commandFailedWithCode ( secondaryDB . runCommand ( { find : name , filter : { _id : 0 } , readConcern : { afterClusterTime : clusterTime } , maxTimeMS : 5000 } ) , ErrorCodes . MaxTimeMSExpired ) ; }
Restarts a secondary node so that it goes through initial sync and forces it to sync from
 a specific sync source.
Restarts a secondary node so that it goes through initial sync and forces it to sync from a specific sync source .
// Restart secondary with startClean: true so that it goes through initial sync. // signal // Validation would encounter a prepare conflict on the open transaction. // Force this secondary to sync from the primary. /* wait */ // Wait for the secondary to complete initial sync. // Allow for secondary reads. // Confirm that we have a prepared transaction in progress on the secondary. // Use a 5 second timeout so that there is enough time for the prepared transaction to // release its locks and for the command to obtain those locks. // Use afterClusterTime read to make sure that it will block on a prepare conflict.