summaryrefslogtreecommitdiff
path: root/jstests/replsets/config_server_checks.js
blob: 2c6128d75e8a6fc9234699c4ddd9f528ec77f43c (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
 * Tests various combinations of the configsvr field in replica set configurations and the
 * command line options that control whether a node can function as a member of a CSRS.
 */

function expectState(rst, state) {
    assert.soon(function() {
                    var status = rst.status();
                    if (status.myState != state) {
                        print("Waiting for state " + state +
                              " in replSetGetStatus output: " + tojson(status));
                    }
                    return status.myState == state;
                });
}

(function() {
"use strict";

(function() {
// Test that node with --configsvr cmd line and configsvr in replset config goes
// into REMOVED state if storage engine is not WiredTiger
jsTestLog("configsvr in rs config and --configsvr cmd line, but mmapv1");
var rst = new ReplSetTest({name: "configrs3", nodes: 1, nodeOptions: {configsvr: "",
                                                                      journal: "",
                                                                      storageEngine: "mmapv1"}});

rst.startSet();
var conf = rst.getReplSetConfig();
conf.configsvr = true;
try {
    rst.nodes[0].adminCommand({replSetInitiate: conf});
} catch (e) {
    // expected since we close all connections after going into REMOVED
}
expectState(rst, ReplSetTest.State.REMOVED);
rst.stopSet();
})();

(function() {
// Test that node with --configsvr cmd line and configsvr in replset config does NOT go
// into REMOVED state if storage engine is not WiredTiger but we're running in SCCC mode
jsTestLog("configsvr in rs config and --configsvr cmd line, but mmapv1 with configSvrMode=sccc");
var rst = new ReplSetTest({name: "configrs4", nodes: 1, nodeOptions: {configsvr: "",
                                                                      journal: "",
                                                                      storageEngine: "mmapv1",
                                                                      configsvrMode: "sccc"}});

rst.startSet();
var conf = rst.getReplSetConfig();
conf.configsvr = true;
assert.commandWorked(rst.nodes[0].adminCommand({replSetInitiate: conf}));

rst.getPrimary();
expectState(rst, ReplSetTest.State.PRIMARY);
rst.stopSet();
})();

(function() {
// Test that node with --configsvr cmd line and configsvr in replset config and using wiredTiger
// does NOT go into REMOVED state.
jsTestLog("configsvr in rs config and --configsvr cmd line, normal case");
var rst = new ReplSetTest({name: "configrs5",
                           nodes: 1,
                           nodeOptions: {configsvr: "",
                                         journal: "",
                                         storageEngine: "wiredTiger"}});

rst.startSet();
var conf = rst.getReplSetConfig();
conf.configsvr = true;
assert.commandWorked(rst.nodes[0].adminCommand({replSetInitiate: conf}));

rst.getPrimary();
expectState(rst, ReplSetTest.State.PRIMARY);

var conf = rst.getPrimary().getDB('local').system.replset.findOne();
assert(conf.configsvr, tojson(conf));

rst.stopSet();
})();

(function() {
// Test that node with --configsvr cmd line and initiated with an empty replset config
// will result in configsvr:true getting automatically added to the config (SERVER-20247).
jsTestLog("--configsvr cmd line, empty config to replSetInitiate");
var rst = new ReplSetTest({name: "configrs6",
                           nodes: 1,
                           nodeOptions: {configsvr: "",
                                         journal: "",
                                         storageEngine: "wiredTiger"}});

rst.startSet();
assert.commandWorked(rst.nodes[0].adminCommand({replSetInitiate: 1}));

rst.getPrimary();
expectState(rst, ReplSetTest.State.PRIMARY);
rst.stopSet();
})();

(function() {
// Test that a set initialized without --configsvr but then restarted with --configsvr will fail to
// start up and won't automatically add "configsvr" to the replset config (SERVER-21236).
jsTestLog("set initiated without configsvr, restarted adding --configsvr cmd line");
var rst = new ReplSetTest({name: "configrs7",
                           nodes: 1,
                           nodeOptions: {journal: "",
                                         storageEngine: "wiredTiger"}});

rst.startSet();
var conf = rst.getReplSetConfig();
assert.commandWorked(rst.nodes[0].adminCommand({replSetInitiate: conf}));

rst.getPrimary();
expectState(rst, ReplSetTest.State.PRIMARY);
assert.throws(function() {
                  rst.restart(0, {configsvr: ""});
              });

rst.stopSet();
})();

(function() {
// Test that a set initialized with --configsvr but then restarted without --configsvr will fail to
// start up.
jsTestLog("set initiated with configsvr, restarted without --configsvr cmd line");
var rst = new ReplSetTest({name: "configrs8",
                           nodes: 1,
                           nodeOptions: {configsvr: "",
                                         journal: "",
                                         storageEngine: "wiredTiger"}});

rst.startSet();
var conf = rst.getReplSetConfig();
conf.configsvr = true;
assert.commandWorked(rst.nodes[0].adminCommand({replSetInitiate: conf}));

rst.getPrimary();
expectState(rst, ReplSetTest.State.PRIMARY);

var node = rst.nodes[0];
var options = node.savedOptions;
delete options.configsvr;
options.noCleanData = true;

MongoRunner.stopMongod(node);
var conn = MongoRunner.runMongod(options);
assert.eq(null, conn, "Mongod should have failed to start, but didn't");

rst.stopSet();
})();

})();