summaryrefslogtreecommitdiff
path: root/jstests/replsets/arbiters_not_included_in_w3_wc.js
blob: aaf35cb4501279c9eeba0cf27d5247f47cf10f9e (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
/**
 * 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 PSSA set where one of the secondaries is non-voting, which makes the majority 2 nodes.
 * This means that a write needs to replicate to only one of the secondaries to commit. A w:3
 * write would thus require only one additional member to fully satisfy the write concern after
 * committing. This test therefore shuts down the last secondary and verifies that the arbiter does
 * *not* get picked in its place and the w:3 write times out instead.
 */

(function() {
"use strict";

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

rst.startSet();
rst.initiate({
    "_id": name,
    "members": [
        {"_id": 0, "host": nodes[0]},
        {"_id": 1, "host": nodes[1], priority: 0},
        {"_id": 2, "host": nodes[2], priority: 0, votes: 0},
        {"_id": 3, "host": nodes[3], "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: 3, wtimeout: ReplSetTest.kDefaultTimeoutMS}}));

jsTestLog("Shutting down the non-voting secondary");

rst.stop(2);

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

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

rst.stopSet();
})();