jstests/sharding/index_commands_shard_targeting.js
/*
 * Runs the command after performing chunk operations to make the primary shard (shard0) not own
 * any chunks for the collection, and the subset of non-primary shards (shard1 and shard2) that
 * own chunks for the collection have stale catalog cache.
 *
 * Asserts that the command checks shard versions by checking that the shards to refresh their
 * cache after the command is run.
 */
Runs the command after performing chunk operations to make the primary shard (shard0) not own
any chunks for the collection, and the subset of non-primary shards (shard1 and shard2) that
own chunks for the collection have stale catalog cache.

Asserts that the command checks shard versions by checking that the shards to refresh their
cache after the command is run.
Runs the command after performing chunk operations to make the primary shard ( shard0 ) not own any chunks for the collection and the subset of non - primary shards ( shard1 and shard2 ) that own chunks for the collection have stale catalog cache . Asserts that the command checks shard versions by checking that the shards to refresh their cache after the command is run .
function assertCommandChecksShardVersions(st, dbName, collName, testCase) {
    const ns = dbName + "." + collName;
    ShardVersioningUtil.moveChunkNotRefreshRecipient(st.s, ns, st.shard0, st.shard1, {_id: MinKey});
    assert.commandWorked(st.s.adminCommand({split: ns, middle: {_id: 0}}));
    ShardVersioningUtil.moveChunkNotRefreshRecipient(st.s, ns, st.shard1, st.shard2, {_id: 0});
    ShardVersioningUtil.assertShardVersionEquals(st.shard0, ns, Timestamp(0, 0));
    const latestCollectionVersion =
        ShardVersioningUtil.getMetadataOnShard(st.shard1, ns).collVersion;
    ShardVersioningUtil.assertCollectionVersionOlderThan(st.shard0, ns, latestCollectionVersion);
    ShardVersioningUtil.assertCollectionVersionOlderThan(st.shard2, ns, latestCollectionVersion);
    if (testCase.setUpFuncForCheckShardVersionTest) {
        testCase.setUpFuncForCheckShardVersionTest();
    }
    assert.commandWorked(st.s.getDB(dbName).runCommand(testCase.command));
    ShardVersioningUtil.assertCollectionVersionOlderThan(st.shard0, ns, latestCollectionVersion);
    ShardVersioningUtil.assertCollectionVersionEquals(st.shard1, ns, latestCollectionVersion);
    ShardVersioningUtil.assertCollectionVersionEquals(st.shard2, ns, latestCollectionVersion);
}
function assertCommandChecksShardVersions ( st , dbName , collName , testCase ) { const ns = dbName + "." + collName ; ShardVersioningUtil . moveChunkNotRefreshRecipient ( st . s , ns , st . shard0 , st . shard1 , { _id : MinKey } ) ; assert . commandWorked ( st . s . adminCommand ( { split : ns , middle : { _id : 0 } } ) ) ; ShardVersioningUtil . moveChunkNotRefreshRecipient ( st . s , ns , st . shard1 , st . shard2 , { _id : 0 } ) ; ShardVersioningUtil . assertShardVersionEquals ( st . shard0 , ns , Timestamp ( 0 , 0 ) ) ; const latestCollectionVersion = ShardVersioningUtil . getMetadataOnShard ( st . shard1 , ns ) . collVersion ; ShardVersioningUtil . assertCollectionVersionOlderThan ( st . shard0 , ns , latestCollectionVersion ) ; ShardVersioningUtil . assertCollectionVersionOlderThan ( st . shard2 , ns , latestCollectionVersion ) ; if ( testCase . setUpFuncForCheckShardVersionTest ) { testCase . setUpFuncForCheckShardVersionTest ( ) ; } assert . commandWorked ( st . s . getDB ( dbName ) . runCommand ( testCase . command ) ) ; ShardVersioningUtil . assertCollectionVersionOlderThan ( st . shard0 , ns , latestCollectionVersion ) ; ShardVersioningUtil . assertCollectionVersionEquals ( st . shard1 , ns , latestCollectionVersion ) ; ShardVersioningUtil . assertCollectionVersionEquals ( st . shard2 , ns , latestCollectionVersion ) ; }
Runs the command after performing chunk operations to make the primary shard (shard0) not own
 any chunks for the collection, and the subset of non-primary shards (shard1 and shard2) that
 own chunks for the collection have stale catalog cache.
Runs the command after performing chunk operations to make the primary shard ( shard0 ) not own any chunks for the collection and the subset of non - primary shards ( shard1 and shard2 ) that own chunks for the collection have stale catalog cache .
// Move the initial chunk out of the primary shard. // Split the chunk to create two chunks on shard1. Move one of the chunks to shard2. // Assert that primary shard does not have any chunks for the collection. // The donor shard for the last moveChunk will have the latest collection version. // Assert that besides the latest donor shard (shard1), all shards have stale collection // version. // Assert that primary shard still has stale collection version after the command is run // because both the shard version in the command and in the shard's cache are UNSHARDED // (no chunks). // Assert that the targeted shards have the latest collection version after the command is // run.