(function() {
|
"use strict";
|
|
load("jstests/sharding/libs/resharding_test_fixture.js");
|
|
const reshardingTest = new ReshardingTest({numDonors: 2, numRecipients: 2, reshardInPlace: true});
|
reshardingTest.setup();
|
|
const donorShardNames = reshardingTest.donorShardNames;
|
const sourceCollection = reshardingTest.createShardedCollection({
|
ns: "reshardingDb.coll",
|
shardKeyPattern: {oldKey: 1},
|
chunks: [
|
{min: {oldKey: MinKey}, max: {oldKey: 10}, shard: donorShardNames[0]},
|
{min: {oldKey: 10}, max: {oldKey: MaxKey}, shard: donorShardNames[1]},
|
],
|
});
|
|
const mongos = sourceCollection.getMongo();
|
const session = mongos.startSession({causalConsistency: false, retryWrites: false});
|
const sessionCollection = session.getDatabase(sourceCollection.getDB().getName())
|
.getCollection(sourceCollection.getName());
|
|
assert.commandWorked(sessionCollection.insert({_id: 0, oldKey: 5, newKey: 15, counter: 0}));
|
|
session.startTransaction();
|
assert.commandWorked(sessionCollection.update({_id: 0, oldKey: 5}, {$inc: {counter: 1}}));
|
|
const recipientShardNames = reshardingTest.recipientShardNames;
|
reshardingTest.withReshardingInBackground( //
|
{
|
newShardKeyPattern: {newKey: 1},
|
newChunks: [
|
{min: {newKey: MinKey}, max: {newKey: 10}, shard: recipientShardNames[0]},
|
{min: {newKey: 10}, max: {newKey: MaxKey}, shard: recipientShardNames[1]},
|
],
|
},
|
() => {
|
assert.soon(() => {
|
const coordinatorDoc = mongos.getCollection("config.reshardingOperations").findOne({
|
nss: sourceCollection.getFullName()
|
});
|
|
return coordinatorDoc !== null && coordinatorDoc.fetchTimestamp !== undefined;
|
});
|
|
assert.commandWorked(session.commitTransaction_forTesting());
|
});
|
|
reshardingTest.teardown();
|
})();
|