summaryrefslogtreecommitdiff
path: root/jstests/sharding/verify_reshard_collection_opmessage.js
blob: 305a75b464338d8f833ea100f1ad1799e3d76cbf (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
51
52
53
54
55
56
57
58
/**
 * Test that an opMessage is created during reshardCollection command.
 *
 * @tags: [requires_fcv_60]
 */
(function() {
"use strict";
load("jstests/libs/uuid_util.js");
load("jstests/sharding/libs/resharding_test_fixture.js");

const sourceNs = "reshardingDb.coll";

const reshardingTest = new ReshardingTest({
    numDonors: 2,
    numRecipients: 2,
    reshardInPlace: true,
});
reshardingTest.setup();

const donorShardNames = reshardingTest.donorShardNames;
const recipientShardNames = reshardingTest.recipientShardNames;

const primaryShardName = donorShardNames[0];

const inputCollection = reshardingTest.createShardedCollection({
    ns: sourceNs,
    shardKeyPattern: {oldKey: 1},
    primaryShardName: primaryShardName,
    chunks: [
        {min: {oldKey: MinKey}, max: {oldKey: 0}, shard: donorShardNames[0]},
        {min: {oldKey: 0}, max: {oldKey: MaxKey}, shard: donorShardNames[1]},
    ],
});

const mongos = inputCollection.getMongo();
const collectionUUID = getUUIDFromConfigCollections(mongos, sourceNs);

reshardingTest.withReshardingInBackground({
    newShardKeyPattern: {newKey: 1},
    newChunks: [
        {min: {newKey: MinKey}, max: {newKey: 0}, shard: recipientShardNames[0]},
        {min: {newKey: 0}, max: {newKey: MaxKey}, shard: recipientShardNames[1]},
    ],
});

const oplog = reshardingTest.getReplSetForShard(primaryShardName)
                  .getPrimary()
                  .getCollection("local.oplog.rs");
const logEntry = oplog.findOne({ns: sourceNs, op: 'n', "o2.reshardCollection": sourceNs});
assert(logEntry != null);
const reshardedUUID = getUUIDFromConfigCollections(mongos, sourceNs);
assert.eq(reshardedUUID, logEntry.o2.reshardUUID, logEntry);
assert.eq(logEntry.ui, collectionUUID, logEntry);
assert.eq(bsonWoCompare(logEntry.o2.oldShardKey, {oldKey: 1}), 0, logEntry);
assert.eq(bsonWoCompare(logEntry.o2.shardKey, {newKey: 1}), 0, logEntry);

reshardingTest.teardown();
})();