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
|
load("jstests/replsets/rslib.js");
/**
* High level test scenario:
* 1. Shard collection.
* 2. Perform writes.
* 3. Migrate only chunk to other shard.
* 4. Retry writes.
* 5. Step up secondary and wait for new primary.
* 6. Retry writes.
* 7. Migrate only chunk back to original shard.
* 8. Retry writes.
*/
var testMoveChunkWithSession = function(
st, collName, cmdObj, setupFunc, checkRetryResultFunc, checkDocumentsFunc) {
var ns = 'test.' + collName;
var testDB = st.s.getDB('test');
var coll = testDB.getCollection(collName);
assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {x: 1}}));
setupFunc(coll);
var result = assert.commandWorked(testDB.runCommand(cmdObj));
assert.commandWorked(st.s.adminCommand({moveChunk: ns, find: {x: 0}, to: st.shard1.shardName}));
checkRetryResultFunc(result, assert.commandWorked(testDB.runCommand(cmdObj)));
checkDocumentsFunc(coll);
const secondary = st.rs1.getSecondary();
st.rs1.stepUp(secondary);
st.rs1.awaitNodesAgreeOnPrimary();
st.configRS.nodes.concat([st.s]).forEach(function awaitNode(conn) {
awaitRSClientHosts(conn, {host: st.rs1.getPrimary().host}, {ok: true, ismaster: true});
});
checkRetryResultFunc(result, assert.commandWorked(testDB.runCommand(cmdObj)));
checkDocumentsFunc(coll);
// Make sure that the other shard knows about the latest primary.
awaitRSClientHosts(
st.rs0.getPrimary(), {host: st.rs1.getPrimary().host}, {ok: true, ismaster: true});
assert.commandWorked(st.s.adminCommand({moveChunk: ns, find: {x: 0}, to: st.shard0.shardName}));
checkRetryResultFunc(result, assert.commandWorked(testDB.runCommand(cmdObj)));
checkDocumentsFunc(coll);
};
|