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
|
// Test for SERVER-9333
// Previously, we were not clearing the cache of slaves in the primary at reconfig
// time. This would cause us to update stale items in the cache when secondaries
// reported their progress to a primary.
(function() {
"use strict";
// Start a replica set with 3 nodes
var host = getHostName();
var replTest = new ReplSetTest({nodes: 3});
var nodes = replTest.startSet();
var ports = replTest.ports;
// Set tags and getLastErrorModes
var conf = {
_id: replTest.name,
members: [
{_id: 0, host: host + ":" + ports[0], tags: {"dc": "bbb"}},
{_id: 1, host: host + ":" + ports[1], tags: {"dc": "bbb"}},
{_id: 2, host: host + ":" + ports[2], tags: {"dc": "ccc"}}
],
settings: {
getLastErrorModes: {
anydc: {dc: 1},
alldc: {dc: 2},
}
}
};
replTest.initiate(conf);
replTest.awaitReplication();
var wtimeout = ReplSetTest.kDefaultTimeoutMS;
var master = replTest.getPrimary();
var db = master.getDB("test");
// Insert a document with write concern : anydc
assert.writeOK(db.foo.insert({x: 1}, {writeConcern: {w: 'anydc', wtimeout: wtimeout}}));
// Insert a document with write concern : alldc
assert.writeOK(db.foo.insert({x: 2}, {writeConcern: {w: 'alldc', wtimeout: wtimeout}}));
// Add a new tag to the replica set
var config = master.getDB("local").system.replset.findOne();
printjson(config);
var modes = config.settings.getLastErrorModes;
config.version++;
config.members[0].tags.newtag = "newtag";
try {
master.getDB("admin").runCommand({replSetReconfig: config});
} catch (e) {
print(e);
}
replTest.awaitReplication();
// Print the new config for replica set
var config = master.getDB("local").system.replset.findOne();
printjson(config);
master = replTest.getPrimary();
var db = master.getDB("test");
// Insert a document with write concern : anydc
assert.writeOK(db.foo.insert({x: 3}, {writeConcern: {w: 'anydc', wtimeout: wtimeout}}));
// Insert a document with write concern : alldc
assert.writeOK(db.foo.insert({x: 4}, {writeConcern: {w: 'alldc', wtimeout: wtimeout}}));
replTest.stopSet();
}());
|