summaryrefslogtreecommitdiff
path: root/jstests/replsets/arbiters_not_included_in_w2_wc.js
blob: 6ea19cc55a5ec0d8ea619d4a50e2cd1fde285545 (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
/**
 * Tests that arbiters cannot be used to acknowledge w:number writes even when some of the
 * required secondaries are unavailable. After a write commits, the corresponding
 * lastCommittedOpTime becomes the lastAppliedOpTime on arbiters in the set. This particular test
 * uses a PSSAA set where both of the secondaries are non-voting, which makes the majority only one
 * node. The effect of this configuration is that writes only need to be on the primary to commit.
 * A w:2 write would thus require only one additional member to fully satisfy the write concern
 * after committing. This test therefore shuts down the both secondaries and verifies that neither
 * of the arbiters gets picked in its place and the w:2 write times out instead.
 */

(function() {
    "use strict";

    const name = "arbiters_not_included_in_w2_wc";
    const rst = new ReplSetTest({name: name, nodes: 5});
    const nodes = rst.nodeList();

    rst.startSet();
    rst.initiate({
        "_id": name,
        "members": [
            {"_id": 0, "host": nodes[0]},
            {"_id": 1, "host": nodes[1], priority: 0, votes: 0},
            {"_id": 2, "host": nodes[2], priority: 0, votes: 0},
            {"_id": 3, "host": nodes[3], "arbiterOnly": true},
            {"_id": 4, "host": nodes[4], "arbiterOnly": true}
        ]
    });

    const dbName = "test";
    const collName = name;

    const primary = rst.getPrimary();
    const testDB = primary.getDB(dbName);
    const testColl = testDB.getCollection(collName);

    assert.commandWorked(
        testColl.insert({"a": 1}, {writeConcern: {w: 2, wtimeout: ReplSetTest.kDefaultTimeoutMS}}));

    jsTestLog("Shutting down both secondaries");

    rst.stop(1);
    rst.stop(2);

    jsTestLog("Issuing a w:2 write and confirming that it times out");

    assert.commandFailedWithCode(
        testColl.insert({"b": 2}, {writeConcern: {w: 2, wtimeout: 5 * 1000}}),
        ErrorCodes.WriteConcernFailed);

    rst.stopSet();
})();