summaryrefslogtreecommitdiff
path: root/jstests/replsets/reconfig_fails_no_cwwc_set.js
blob: 976392e62ec18f331c26800991e362984c9690f5 (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
/**
 * Test that a reconfig that would change the implicit default write concern fails.
 * In order to perform such a reconfig, users must set a cluster-wide write concern.
 */

(function() {
'use strict';

const rst = new ReplSetTest({nodes: 2});
rst.startSet();
rst.initiate();

const primary = rst.getPrimary();

let cwwc = primary.adminCommand({getDefaultRWConcern: 1});
assert(cwwc.hasOwnProperty("defaultWriteConcern"));
assert.eq({w: "majority", wtimeout: 0}, cwwc.defaultWriteConcern, tojson(cwwc));

jsTestLog("Starting arbiter");
const arbiter = rst.add();
const config = rst.getReplSetConfigFromNode();
config.members.push({_id: 2, host: arbiter.host, arbiterOnly: true});
config.version++;
const reconfigErrorMsg =
    "Reconfig attempted to install a config that would change the implicit default write concern";

// Adding the arbiter would change the implicit default write concern from {w: majority} to
// {w:1}, so we fail the reconfig.
let res = assert.commandFailed(primary.adminCommand({replSetReconfig: config}));
assert.eq(res.code, ErrorCodes.NewReplicaSetConfigurationIncompatible);
assert(res.errmsg.includes(reconfigErrorMsg));

// A force reconfig should also fail.
res = assert.commandFailed(primary.adminCommand({replSetReconfig: config, force: true}));
assert.eq(res.code, ErrorCodes.NewReplicaSetConfigurationIncompatible);
assert(res.errmsg.includes(reconfigErrorMsg));

assert.commandWorked(primary.adminCommand(
    {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}}));

// After setting the cluster-wide write concern, the same reconfig command should succeed.
assert.commandWorked(primary.adminCommand({replSetReconfig: config}));

cwwc = primary.adminCommand({getDefaultRWConcern: 1});
assert(cwwc.hasOwnProperty("defaultWriteConcern"));
assert.eq({w: 1, wtimeout: 0}, cwwc.defaultWriteConcern, tojson(cwwc));

rst.stopSet();
})();