summaryrefslogtreecommitdiff
path: root/jstests/sharding/reconfig_race_with_failover.js
blob: a63c40596cf37cd9711bc03cecae5dfa97fbc89c (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
59
60
61
62
63
64
65
/*
 * Tests that if reconfig did not replicate before step up, the new primary
 * is not stale because its new election Id takes precedence over Set version when
 * comparing.
 *
 * @tags: [does_not_support_stepdowns, multiversion_incompatible]
 */
(function() {
"use strict";
load("jstests/libs/fail_point_util.js");
load('jstests/libs/parallel_shell_helpers.js');
load("jstests/sharding/libs/sharded_index_util.js");

// Skip db hash check because secondary is left with a different config.
TestData.skipCheckDBHashes = true;

const st = new ShardingTest({shards: {rs0: {nodes: [{}, {}, {rsConfig: {priority: 0}}]}}});
const rst = st.rs0;
const primary = rst.getPrimary();
if (primary !== nodes[0]) {
    st.stop();
    return;  // For simplicity.
}

const config = rst.getReplSetConfigFromNode();
jsTestLog(`Initial config ${tojson(config)}`);
config.version++;

const versionToBlock = config.version;
const termToBlock = config.term;

let pauseInReconfig = configureFailPoint(primary, "hangAfterReconfig");
let maxElectionIdSetVersionPairUpdated =
    configureFailPoint(primary, "maxElectionIdSetVersionPairUpdated");

// Fail points to prevent the new config from being replicated.
let testFpHangBeforeFetchingConfig1 = configureFailPoint(
    nodes[1], "skipBeforeFetchingConfig", {versionAndTerm: [versionToBlock, termToBlock]});
let testFpHangBeforeFetchingConfig2 = configureFailPoint(
    nodes[2], "skipBeforeFetchingConfig", {versionAndTerm: [versionToBlock, termToBlock]});
let runReconfigJoin = startParallelShell(
    funWithArgs(function(config) {
        jsTestLog(`Run reconfig`);
        let result = db.getSiblingDB("admin").runCommand({replSetReconfig: config});
        jsTestLog(`Reconfig finished, result ${tojson(result)}`);
    }, config), primary.port);
pauseInReconfig.wait();
maxElectionIdSetVersionPairUpdated.wait();

// After step up the new primary still has the Set at previous version.
const nextPrimary = rst.getSecondary();
jsTestLog("Step Up");
nextPrimary.adminCommand({replSetStepUp: 1});
pauseInReconfig.off();
runReconfigJoin();

testFpHangBeforeFetchingConfig1.off();
testFpHangBeforeFetchingConfig2.off();

// This command fails if mongos' RSM was stuck with stale primary unable to rollback Set version.
let res = ShardedIndexUtil.getPerShardIndexes(st.s.getCollection("config.system.sessions"));
jsTestLog(`Aggregate run on Mongos ${tojson(res)}`);

st.stop();
}());