blob: 8b49447bed6b7ccdc9b3479b4150edaaac0be1f2 (
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
40
41
|
/**
* Tests that the shardCollection command obtains the collection's UUID from the primary shard and
* persists it in config.collections.
*/
(function() {
"use strict";
load("jstests/libs/uuid_util.js");
let db = "test";
let st = new ShardingTest({shards: {rs0: {nodes: 1}, rs1: {nodes: 1}}, other: {config: 3}});
assert.commandWorked(st.s.adminCommand({enableSharding: db}));
st.ensurePrimaryShard(db, st.shard0.shardName);
// Check that shardCollection propagates and persists UUIDs.
for (let i = 0; i < 3; i++) {
let coll = "bar" + i;
let nss = db + "." + coll;
// It shouldn't matter whether the collection existed on the shard already or not; test
// both cases.
if (i === 0) {
assert.commandWorked(st.s.getDB(db).getCollection(coll).insert({x: 1}));
}
assert.commandWorked(st.s.adminCommand({shardCollection: nss, key: {_id: 1}}));
// Check that the entry for the collection in config.collections has a uuid field.
let collEntryUUID = getUUIDFromConfigCollections(st.s, nss);
assert.neq(undefined, collEntryUUID);
// Check that the uuid field in the config.collections entry matches the uuid on the shard.
let listCollsUUID = getUUIDFromListCollections(st.shard0.getDB(db), coll);
assert.neq(undefined, listCollsUUID);
assert.eq(listCollsUUID, collEntryUUID);
}
st.stop();
})();
|