summaryrefslogtreecommitdiff
path: root/jstests/sharding/moveChunk_recipient_rejects_chunk_if_UUID_mismatch.js
blob: 16536ea4bb1e4bed2379eb3348825c523b89a96d (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
42
43
44
45
46
47
48
49
50
/**
 * Test that moving a chunk into a shard that already has the collection with a different UUID
 * causes the recipient to fail the migration.
 */
(function() {
"use strict";

const dbName = "test";
const collName = "inputColl";
const ns = dbName + "." + collName;

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

let donor = st.shard0;
let recipient = st.shard1;

jsTest.log("Make " + donor.shardName + " the primary shard, and shard collection " + ns);
assert.commandWorked(st.s.adminCommand({enableSharding: dbName}));
st.ensurePrimaryShard(dbName, donor.shardName);
assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {_id: 1}}));

jsTest.log("Insert a document with {_id: 0} into " + ns + " through mongos");
assert.commandWorked(st.s.getCollection(ns).insert({_id: 0}));

jsTest.log("Insert a document with {_id: 1} into " + ns + " directly on the recipient");
assert.commandWorked(recipient.getCollection(ns).insert({_id: 1}));

jsTest.log("Check that the UUID on the recipient differs from the UUID on the donor");
const recipientUUIDBefore =
    recipient.getDB(dbName).getCollectionInfos({name: collName})[0].info.uuid;
const donorUUIDBefore = donor.getDB(dbName).getCollectionInfos({name: collName})[0].info.uuid;
assert.neq(recipientUUIDBefore, donorUUIDBefore);

jsTest.log("Ensure that we fail to migrate data from the donor to the recipient");
assert.commandFailed(st.s.adminCommand({moveChunk: ns, find: {_id: 0}, to: recipient.shardName}));

jsTest.log("Ensure the recipient's collection UUID is unmodified after the migration attempt");
const recipientUUIDAfter =
    recipient.getDB(dbName).getCollectionInfos({name: collName})[0].info.uuid;
assert.eq(recipientUUIDBefore, recipientUUIDAfter);

jsTest.log("Ensure the document that was on the recipient was not deleted");
assert.neq(null, recipient.getCollection(ns).findOne({_id: 1}));

jsTest.log("Ensure dropCollection causes the collection to be dropped even on the recipient");
assert.commandWorked(st.s.getDB(dbName).runCommand({drop: collName}));
assert.eq(0, recipient.getDB(dbName).getCollectionInfos({name: collName}).length);

st.stop();
})();