jstests/concurrency/fsm_workload_helpers/snapshot_read_utils.js
/**
 * Performs a find with readConcern {level: "snapshot"} and optionally atClusterTime, if specified.
 */
Performs a find with readConcern {level: "snapshot"} and optionally atClusterTime, if specified.
Performs a find with readConcern { level : " snapshot " } and optionally atClusterTime if specified .
function doSnapshotFindAtClusterTime(
    db, collName, data, findErrorCodes, sortOrder, checkSnapshotCorrectness) {
    const findCmd = {
        find: collName,
        sort: sortOrder,
        batchSize: data.batchSize,
        readConcern: {level: "snapshot"}
    };
    if (data.atClusterTime) {
        findCmd.readConcern.atClusterTime = data.atClusterTime;
    }
    let res = db.runCommand(findCmd);
    assert.commandWorkedOrFailedWithCode(
        res, findErrorCodes, () => `cmd: ${tojson(findCmd)}, res: ${tojson(res)}`);
    const cursor = parseCursor(res);
    if (!cursor) {
        data.cursorId = NumberLong(0);
    } else {
        assert(cursor.hasOwnProperty("firstBatch"), tojson(res));
        assert(cursor.hasOwnProperty("atClusterTime"), tojson(res));
        assert.neq(cursor.id, 0);
        data.cursorId = cursor.id;
        if (typeof checkSnapshotCorrectness === "function") {
            checkSnapshotCorrectness(res);
        }
    }
}
function doSnapshotFindAtClusterTime ( db , collName , data , findErrorCodes , sortOrder , checkSnapshotCorrectness ) { const findCmd = { find : collName , sort : sortOrder , batchSize : data . batchSize , readConcern : { level : "snapshot" } } ; if ( data . atClusterTime ) { findCmd . readConcern . atClusterTime = data . atClusterTime ; } let res = db . runCommand ( findCmd ) ; assert . commandWorkedOrFailedWithCode ( res , findErrorCodes , ( ) => ` ${ tojson ( findCmd ) } ${ tojson ( res ) } ` ) ; const cursor = parseCursor ( res ) ; if ( ! cursor ) { data . cursorId = NumberLong ( 0 ) ; } else { assert ( cursor . hasOwnProperty ( "firstBatch" ) , tojson ( res ) ) ; assert ( cursor . hasOwnProperty ( "atClusterTime" ) , tojson ( res ) ) ; assert . neq ( cursor . id , 0 ) ; data . cursorId = cursor . id ; if ( typeof checkSnapshotCorrectness === "function" ) { checkSnapshotCorrectness ( res ) ; } } }
Performs a find with readConcern {level: "snapshot"} and optionally atClusterTime, if specified.
Performs a find with readConcern { level : " snapshot " } and optionally atClusterTime if specified .
// Store the cursorId and cursor in the data object. // checkSnapshotCorrectness verifies that the snapshot sees the correct documents.