jstests/sharding/index_commands_shard_targeting.js
/*
 * Runs moveChunk to move one chunk from the primary shard (shard0) to shard1. Pauses the
 * migration after shard0 enters the read-only phase of the critical section, and runs
 * the given command function. Asserts that the command is blocked behind the critical section.
 */
Runs moveChunk to move one chunk from the primary shard (shard0) to shard1. Pauses the
migration after shard0 enters the read-only phase of the critical section, and runs
the given command function. Asserts that the command is blocked behind the critical section.
Runs moveChunk to move one chunk from the primary shard ( shard0 ) to shard1 . Pauses the migration after shard0 enters the read - only phase of the critical section and runs the given command function . Asserts that the command is blocked behind the critical section .
function assertCommandBlocksIfCriticalSectionInProgress(
    st, staticMongod, dbName, collName, allShards, testCase) {
    const ns = dbName + "." + collName;
    const fromShard = st.shard0;
    const toShard = st.shard1;
    if (testCase.setUpFuncForCriticalSectionTest) {
        testCase.setUpFuncForCriticalSectionTest();
    }
    assert.commandWorked(st.s.adminCommand({split: ns, middle: {_id: 0}}));
    pauseMoveChunkAtStep(fromShard, moveChunkStepNames.chunkDataCommitted);
    let joinMoveChunk =
        moveChunkParallel(staticMongod, st.s.host, {_id: 0}, null, ns, toShard.shardName);
    waitForMoveChunkStep(fromShard, moveChunkStepNames.chunkDataCommitted);
    const cmdWithMaxTimeMS = Object.assign({}, testCase.command, {maxTimeMS: 750});
    assert.commandFailed(st.s.getDB(dbName).runCommand(cmdWithMaxTimeMS));
    checkLog.checkContainsOnceJsonStringMatch(st.shard0, 22062, "error", "MaxTimeMSExpired");
    allShards.forEach(function(shard) {
        testCase.assertCommandDidNotRunOnShard(shard);
    });
    unpauseMoveChunkAtStep(fromShard, moveChunkStepNames.chunkDataCommitted);
    joinMoveChunk();
}
function assertCommandBlocksIfCriticalSectionInProgress ( st , staticMongod , dbName , collName , allShards , testCase ) { const ns = dbName + "." + collName ; const fromShard = st . shard0 ; const toShard = st . shard1 ; if ( testCase . setUpFuncForCriticalSectionTest ) { testCase . setUpFuncForCriticalSectionTest ( ) ; } assert . commandWorked ( st . s . adminCommand ( { split : ns , middle : { _id : 0 } } ) ) ; pauseMoveChunkAtStep ( fromShard , moveChunkStepNames . chunkDataCommitted ) ; let joinMoveChunk = moveChunkParallel ( staticMongod , st . s . host , { _id : 0 } , null , ns , toShard . shardName ) ; waitForMoveChunkStep ( fromShard , moveChunkStepNames . chunkDataCommitted ) ; const cmdWithMaxTimeMS = Object . assign ( { } , testCase . command , { maxTimeMS : 750 } ) ; assert . commandFailed ( st . s . getDB ( dbName ) . runCommand ( cmdWithMaxTimeMS ) ) ; checkLog . checkContainsOnceJsonStringMatch ( st . shard0 , 22062 , "error" , "MaxTimeMSExpired" ) ; allShards . forEach ( function ( shard ) { testCase . assertCommandDidNotRunOnShard ( shard ) ; } ) ; unpauseMoveChunkAtStep ( fromShard , moveChunkStepNames . chunkDataCommitted ) ; joinMoveChunk ( ) ; }
Runs moveChunk to move one chunk from the primary shard (shard0) to shard1.
Runs moveChunk to move one chunk from the primary shard ( shard0 ) to shard1 .
// Split the initial chunk. // Turn on the fail point, and move one of the chunks to shard1 so that there are two // shards that own chunks for the collection. Wait for moveChunk to hit the fail point. // Run the command with maxTimeMS. // Assert that the command reached the shard and then timed out. // It could be possible that the following check fails on slow clusters because the request // expired its maxTimeMS on the mongos before to reach the shard. // Turn off the fail point and wait for moveChunk to complete.