jstests/sharding/compound_hashed_shard_key_zoning.js
/**
 * Test that shardCollection uses existing zone ranges to split chunks.
 */
Test that shardCollection uses existing zone ranges to split chunks.
Test that shardCollection uses existing zone ranges to split chunks .
function testChunkSplits({collectionExists, shardKey, zoneRanges, expectedNumChunks}) {
    const shards = configDB.shards.find().toArray();
    if (collectionExists) {
        assert.commandWorked(testDB.foo.createIndex(shardKey));
    }
    for (let i = 0; i < zoneRanges.length; i++) {
        assert.commandWorked(
            st.s.adminCommand({addShardToZone: shards[i % shards.length]._id, zone: zoneName + i}));
        assert.commandWorked(st.s.adminCommand({
            updateZoneKeyRange: ns,
            min: zoneRanges[i][0],
            max: zoneRanges[i][1],
            zone: zoneName + i
        }));
    }
    assert.eq(configDB.tags.count({ns: ns}), zoneRanges.length);
    assert.eq(0,
              configDB.chunks.count({ns: ns}),
              "expect to see no chunk documents for the collection before shardCollection is run");
    assert.commandWorked(mongos.adminCommand({shardCollection: ns, key: shardKey}));
    const chunkDocs = findChunksUtil.findChunksByNs(configDB, ns).toArray();
    assert.eq(chunkDocs.length, expectedNumChunks, chunkDocs);
    for (let i = 0; i < zoneRanges.length; i++) {
        assert.eq(1,
                  findChunksUtil.countChunksForNs(configDB, ns, {
                      min: zoneRanges[i][0],
                      max: zoneRanges[i][1],
                      shard: shards[i % shards.length]._id
                  }),
                  chunkDocs);
    }
    assert.commandWorked(testDB.runCommand({drop: kCollName}));
}
function testChunkSplits ( { collectionExists , shardKey , zoneRanges , expectedNumChunks } ) { const shards = configDB . shards . find ( ) . toArray ( ) ; if ( collectionExists ) { assert . commandWorked ( testDB . foo . createIndex ( shardKey ) ) ; } for ( let i = 0 ; i < zoneRanges . length ; i ++ ) { assert . commandWorked ( st . s . adminCommand ( { addShardToZone : shards [ i % shards . length ] . _id , zone : zoneName + i } ) ) ; assert . commandWorked ( st . s . adminCommand ( { updateZoneKeyRange : ns , min : zoneRanges [ i ] [ 0 ] , max : zoneRanges [ i ] [ 1 ] , zone : zoneName + i } ) ) ; } assert . eq ( configDB . tags . count ( { ns : ns } ) , zoneRanges . length ) ; assert . eq ( 0 , configDB . chunks . count ( { ns : ns } ) , "expect to see no chunk documents for the collection before shardCollection is run" ) ; assert . commandWorked ( mongos . adminCommand ( { shardCollection : ns , key : shardKey } ) ) ; const chunkDocs = findChunksUtil . findChunksByNs ( configDB , ns ) . toArray ( ) ; assert . eq ( chunkDocs . length , expectedNumChunks , chunkDocs ) ; for ( let i = 0 ; i < zoneRanges . length ; i ++ ) { assert . eq ( 1 , findChunksUtil . countChunksForNs ( configDB , ns , { min : zoneRanges [ i ] [ 0 ] , max : zoneRanges [ i ] [ 1 ] , shard : shards [ i % shards . length ] . _id } ) , chunkDocs ) ; } assert . commandWorked ( testDB . runCommand ( { drop : kCollName } ) ) ; }
Test that shardCollection uses existing zone ranges to split chunks.
Test that shardCollection uses existing zone ranges to split chunks .
// Create a new zone and assign each zone to the shards using round-robin. Then update each of // the zone's range to the range specified in 'zoneRanges'. // Shard the collection and validate the resulting chunks. // Verify that each of the chunks corresponding to zones are in the right shard.