summaryrefslogtreecommitdiff
path: root/jstests/replsets/sync_source_enters_quiesce_mode.js
blob: 3455ca7d37fd268d4e56077d676827a7ee7fa687 (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
/**
 * Tests that reading from an existing sync source continues uninterrupted when the sync source
 * enters quiesce mode.
 *
 * @tags: [
 *   live_record_incompatible,
 * ]
 */
(function() {
"use strict";

load("jstests/libs/fail_point_util.js");

// Set the oplog fetcher batch size to 1, in order to test fetching multiple batches while the sync
// source is in quiesce mode.
const rst = new ReplSetTest(
    {nodes: 3, useBridge: true, nodeOptions: {setParameter: "bgSyncOplogFetcherBatchSize=1"}});
rst.startSet();
rst.initiateWithHighElectionTimeout();

const primary = rst.getPrimary();
const testDB = primary.getDB("testDB");
const testCollName = "testColl";
assert.eq(primary, rst.nodes[0]);

const syncSource = rst.nodes[1];
const syncingNode = rst.nodes[2];

jsTestLog("Ensure syncingNode is syncing from syncSource.");
syncingNode.disconnect(primary);
assert.commandWorked(
    testDB.runCommand({insert: testCollName, documents: [{a: 1}], writeConcern: {w: 3}}));

jsTestLog("Ensure syncingNode is behind syncSource.");
let hangSyncingNodeFailPoint =
    configureFailPoint(syncingNode, "hangBeforeProcessingSuccessfulBatch");
assert.commandWorked(testDB.runCommand(
    {insert: testCollName, documents: [{b: 2}, {c: 3}, {d: 4}], writeConcern: {w: 2}}));
hangSyncingNodeFailPoint.wait();

jsTestLog("Transition syncSource to quiesce mode.");
let quiesceModeFailPoint = configureFailPoint(syncSource, "hangDuringQuiesceMode");
// We must skip validation due to the failpoint that hangs awaitData queries.
rst.stop(syncSource, null /*signal*/, {skipValidation: true}, {forRestart: true, waitpid: false});
quiesceModeFailPoint.wait();

jsTestLog("Check that syncing continues uninterrupted.");
hangSyncingNodeFailPoint.off();
rst.awaitReplication();

jsTestLog("Finish test.");
syncingNode.reconnect(primary);
quiesceModeFailPoint.off();
rst.restart(syncSource);
rst.stopSet();
})();