summaryrefslogtreecommitdiff
path: root/jstests/sharding/resharding_on_existing_key_is_noop.js
blob: dcc3f68178ec6dd5d623cfd9a3ce234479933dfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
 * Tests that trying to perform reshardCollection with a resharding key that matches the
 * collection's existing shard key is a noop (which can be done by confirming the collection's UUID
 * remains unchanged after the operation).
 *
 * @tags: [uses_atclustertime, requires_fcv_49,]
 */
(function() {
"use strict";

load("jstests/libs/uuid_util.js");
load("jstests/sharding/libs/create_sharded_collection_util.js");

const st = new ShardingTest({
    mongos: 1,
    config: 1,
    shards: 2,
    rs: {nodes: 2},
});

const sourceCollection = st.s.getCollection("reshardingDb.coll");

CreateShardedCollectionUtil.shardCollectionWithChunks(sourceCollection, {key: 1}, [
    {min: {key: MinKey}, max: {key: 0}, shard: st.shard0.shardName},
    {min: {key: 0}, max: {key: MaxKey}, shard: st.shard1.shardName},
]);

const ns = sourceCollection.getFullName();
const mongos = sourceCollection.getMongo();
const sourceDB = sourceCollection.getDB();

// The UUID should remain the same if the resharding key matches the existing shard key.
const preReshardCollectionUUID = getUUIDFromListCollections(sourceDB, sourceCollection.getName());
assert.commandWorked(mongos.adminCommand({reshardCollection: ns, key: {key: 1}}));
const postReshardCollectionUUID = getUUIDFromListCollections(sourceDB, sourceCollection.getName());
assert.eq(preReshardCollectionUUID, postReshardCollectionUUID);

st.stop();
})();