jstests/noPassthrough/libs/index_build.js
/**
     * Runs the resumable index build test specified by the provided index spec on the provided
     * replica set and namespace. This will be used to test that failing to resume an index build
     * during the setup phase will cause the index build to restart from the beginning instead.
     * The provided failpoint will be set on the node on restart to specify how resuming the index
     * build should fail. Documents specified by sideWrites will be inserted during the
     * initialization phase so that they are inserted into the side writes table and processed
     * during the drain writes phase.
     */
Runs the resumable index build test specified by the provided index spec on the provided
replica set and namespace. This will be used to test that failing to resume an index build
during the setup phase will cause the index build to restart from the beginning instead.
The provided failpoint will be set on the node on restart to specify how resuming the index
build should fail. Documents specified by sideWrites will be inserted during the
initialization phase so that they are inserted into the side writes table and processed
during the drain writes phase.
Runs the resumable index build test specified by the provided index spec on the provided replica set and namespace . This will be used to test that failing to resume an index build during the setup phase will cause the index build to restart from the beginning instead . The provided failpoint will be set on the node on restart to specify how resuming the index build should fail . Documents specified by sideWrites will be inserted during the initialization phase so that they are inserted into the side writes table and processed during the drain writes phase .
static runFailToResume(rst,
                           dbName,
                           collName,
                           indexSpec,
                           {failPointAfterStartup, removeTempFilesBeforeStartup},
                           sideWrites,
                           postIndexBuildInserts,
                           failWhileParsing = false) {
        const primary = rst.getPrimary();
        const coll = primary.getDB(dbName).getCollection(collName);
        const indexName = "resumable_index_build";
        const awaitCreateIndex = ResumableIndexBuildTest.createIndexWithSideWrites(
            rst, function(collName, indexSpec, indexName) {
                assert.commandFailedWithCode(
                    db.getCollection(collName).createIndex(indexSpec, {name: indexName}),
                    ErrorCodes.InterruptedDueToReplStateChange);
            }, coll, indexSpec, indexName, sideWrites, {hangBeforeBuildingIndex: true});
        const buildUUID = ResumableIndexBuildTest.restart(
            rst,
            primary,
            coll,
            [[indexName]],
            [{name: "hangIndexBuildDuringBulkLoadPhase", logIdWithIndexName: 4924400}],
            0,
            false ,
            failPointAfterStartup,
            function() {
                if (removeTempFilesBeforeStartup)
                    removeFile(primary.dbpath + "/_tmp");
            })[0];
        awaitCreateIndex();
        if (failWhileParsing) {
            checkLog.containsJson(primary, 4916300);
            checkLog.containsJson(primary, 22257);
        } else {
            checkLog.containsJson(primary, 4841701, {
                buildUUID: function(uuid) {
                    return uuid["uuid"]["$uuid"] === buildUUID;
                }
            });
        }
        ResumableIndexBuildTest.assertCompleted(primary, coll, [buildUUID], [indexName]);
        ResumableIndexBuildTest.checkIndexes(
            rst, dbName, collName, [indexName], postIndexBuildInserts);
        const checkLogIdAfterRestart = function(primary, id) {
            rst.stop(primary);
            rst.start(primary, {noCleanData: true});
            checkLog.containsJson(primary, id);
        };
        if (failWhileParsing) {
            checkLogIdAfterRestart(primary, 5071100);
            ResumableIndexBuildTest.checkTempDirectoryCleared(primary);
        } else if (removeTempFilesBeforeStartup) {
            checkLog.containsJson(primary, 22396);
        } else {
            ResumableIndexBuildTest.checkTempDirectoryCleared(primary);
            checkLogIdAfterRestart(primary, 22257);
        }
    }
static runFailToResume ( rst , dbName , collName , indexSpec , { failPointAfterStartup , removeTempFilesBeforeStartup } , sideWrites , postIndexBuildInserts , failWhileParsing = false ) { const primary = rst . getPrimary ( ) ; const coll = primary . getDB ( dbName ) . getCollection ( collName ) ; const indexName = "resumable_index_build" ; const awaitCreateIndex = ResumableIndexBuildTest . createIndexWithSideWrites ( rst , function ( collName , indexSpec , indexName ) { assert . commandFailedWithCode ( db . getCollection ( collName ) . createIndex ( indexSpec , { name : indexName } ) , ErrorCodes . InterruptedDueToReplStateChange ) ; } , coll , indexSpec , indexName , sideWrites , { hangBeforeBuildingIndex : true } ) ; const buildUUID = ResumableIndexBuildTest . restart ( rst , primary , coll , [ [ indexName ] ] , [ { name : "hangIndexBuildDuringBulkLoadPhase" , logIdWithIndexName : 4924400 } ] , 0 , false , failPointAfterStartup , function ( ) { if ( removeTempFilesBeforeStartup ) removeFile ( primary . dbpath + "/_tmp" ) ; } ) [ 0 ] ; awaitCreateIndex ( ) ; if ( failWhileParsing ) { checkLog . containsJson ( primary , 4916300 ) ; checkLog . containsJson ( primary , 22257 ) ; } else { checkLog . containsJson ( primary , 4841701 , { buildUUID : function ( uuid ) { return uuid [ "uuid" ] [ "$uuid" ] === buildUUID ; } } ) ; } ResumableIndexBuildTest . assertCompleted ( primary , coll , [ buildUUID ] , [ indexName ] ) ; ResumableIndexBuildTest . checkIndexes ( rst , dbName , collName , [ indexName ] , postIndexBuildInserts ) ; const checkLogIdAfterRestart = function ( primary , id ) { rst . stop ( primary ) ; rst . start ( primary , { noCleanData : true } ) ; checkLog . containsJson ( primary , id ) ; } ; if ( failWhileParsing ) { checkLogIdAfterRestart ( primary , 5071100 ) ; ResumableIndexBuildTest . checkTempDirectoryCleared ( primary ) ; } else if ( removeTempFilesBeforeStartup ) { checkLog . containsJson ( primary , 22396 ) ; } else { ResumableIndexBuildTest . checkTempDirectoryCleared ( primary ) ; checkLogIdAfterRestart ( primary , 22257 ) ; } }
Runs the resumable index build test specified by the provided index spec on the provided
 replica set and namespace.
Runs the resumable index build test specified by the provided index spec on the provided replica set and namespace .
/* shouldComplete */ // Ensure that the resumable index build failed as expected. // Ensure that the index build was completed after it was restarted. // If we fail while parsing, the persisted Sorter data will only be cleaned up after // another restart. // If we fail to resume due to the temp files being missing, the internal idents will // be cleaned up right away. // If we fail after parsing, any remaining internal idents will only be cleaned up // after another restart.