diff options
author | Spencer T Brody <spencer@mongodb.com> | 2017-04-21 14:50:17 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2017-06-16 13:51:47 -0400 |
commit | dab240e80f5f69df8f7c5796146fa0fed876a84d (patch) | |
tree | 61740ef80aeab81ba3e49933aed54cf3eb3585e3 | |
parent | 95d108fe848d3dbea4ca020739430e0672a4dedd (diff) | |
download | mongo-dab240e80f5f69df8f7c5796146fa0fed876a84d.tar.gz |
SERVER-28326 Ensure primary doesn't change in initial_sync4.js test
(cherry picked from commit d6524fe73938fbce2c9c429886e425363aa40a9c)
-rw-r--r-- | jstests/replsets/initial_sync4.js | 163 |
1 files changed, 84 insertions, 79 deletions
diff --git a/jstests/replsets/initial_sync4.js b/jstests/replsets/initial_sync4.js index d7f2ec01697..e0ff50af4a2 100644 --- a/jstests/replsets/initial_sync4.js +++ b/jstests/replsets/initial_sync4.js @@ -1,81 +1,86 @@ // Test update modifier uassert during initial sync. SERVER-4781 -load("jstests/replsets/rslib.js"); -basename = "jstests_initsync4"; - -print("1. Bring up set"); -replTest = new ReplSetTest({name: basename, nodes: 1}); -replTest.startSet(); -replTest.initiate(); - -m = replTest.getPrimary(); -md = m.getDB("d"); -mc = m.getDB("d")["c"]; - -print("2. Insert some data"); -N = 5000; -mc.ensureIndex({x: 1}); -var bulk = mc.initializeUnorderedBulkOp(); -for (i = 0; i < N; ++i) { - bulk.insert({_id: i, x: i, a: {}}); -} -assert.writeOK(bulk.execute()); - -print("3. Make sure synced"); -replTest.awaitReplication(); - -print("4. Bring up a new node"); -hostname = getHostName(); - -s = MongoRunner.runMongod({replSet: basename, oplogSize: 2}); - -var config = replTest.getReplSetConfig(); -config.version = replTest.getReplSetConfigFromNode().version + 1; -config.members.push({_id: 2, host: hostname + ":" + s.port}); -try { - m.getDB("admin").runCommand({replSetReconfig: config}); -} catch (e) { - print(e); -} -reconnect(s); - -print("5. Wait for new node to start cloning"); - -s.setSlaveOk(); -sc = s.getDB("d")["c"]; - -wait(function() { - printjson(sc.stats()); - return sc.stats().count > 0; -}); - -print("6. Start updating documents on primary"); -for (i = N - 1; i >= N - 10000; --i) { - // If the document is cloned as {a:1}, the {$set:{'a.b':1}} modifier will uassert. - mc.update({_id: i}, {$set: {'a.b': 1}}); - mc.update({_id: i}, {$set: {a: 1}}); -} - -for (i = N; i < N * 2; i++) { - mc.insert({_id: i, x: i}); -} - -assert.eq(N * 2, mc.find().itcount()); - -print("7. Wait for new node to become SECONDARY"); -wait(function() { - var status = s.getDB("admin").runCommand({replSetGetStatus: 1}); - printjson(status); - return status.members && (status.members[1].state == 2); -}); - -print("8. Wait for new node to have all the data"); -wait(function() { - return sc.find().itcount() == mc.find().itcount(); -}); - -assert.eq(mc.getIndexKeys().length, sc.getIndexKeys().length); - -assert.eq(mc.find().sort({x: 1}).itcount(), sc.find().sort({x: 1}).itcount()); - -replTest.stopSet(15); +(function doTest() { + "use strict"; + + load("jstests/replsets/rslib.js"); + var basename = "jstests_initsync4"; + + jsTestLog("1. Bring up set"); + var replTest = new ReplSetTest({name: basename, nodes: 1}); + replTest.startSet(); + replTest.initiate(); + + var m = replTest.getPrimary(); + var md = m.getDB("d"); + var mc = m.getDB("d")["c"]; + + jsTestLog("2. Insert some data"); + var N = 5000; + mc.ensureIndex({x: 1}); + var bulk = mc.initializeUnorderedBulkOp(); + for (var i = 0; i < N; ++i) { + bulk.insert({_id: i, x: i, a: {}}); + } + assert.writeOK(bulk.execute()); + + jsTestLog("3. Make sure synced"); + replTest.awaitReplication(); + + jsTestLog("4. Bring up a new node"); + var hostname = getHostName(); + + var s = MongoRunner.runMongod({replSet: basename, oplogSize: 2}); + + var config = replTest.getReplSetConfig(); + config.version = replTest.getReplSetConfigFromNode().version + 1; + config.members.push({_id: 2, host: hostname + ":" + s.port, priority: 0}); + try { + m.getDB("admin").runCommand({replSetReconfig: config}); + } catch (e) { + print(e); + } + reconnect(s); + assert.eq(m, replTest.getPrimary(), "Primary changed after reconfig"); + + jsTestLog("5. Wait for new node to start cloning"); + + s.setSlaveOk(); + var sc = s.getDB("d")["c"]; + + wait(function() { + printjson(sc.stats()); + return sc.stats().count > 0; + }); + + jsTestLog("6. Start updating documents on primary"); + for (i = N - 1; i >= N - 10000; --i) { + // If the document is cloned as {a:1}, the {$set:{'a.b':1}} modifier will uassert. + mc.update({_id: i}, {$set: {'a.b': 1}}); + mc.update({_id: i}, {$set: {a: 1}}); + } + + for (i = N; i < N * 2; i++) { + mc.insert({_id: i, x: i}); + } + + assert.eq(N * 2, mc.find().itcount()); + + jsTestLog("7. Wait for new node to become SECONDARY"); + wait(function() { + var status = s.getDB("admin").runCommand({replSetGetStatus: 1}); + printjson(status); + return status.members && (status.members[1].state == 2); + }); + + jsTestLog("8. Wait for new node to have all the data"); + wait(function() { + return sc.find().itcount() == mc.find().itcount(); + }); + + assert.eq(mc.getIndexKeys().length, sc.getIndexKeys().length); + + assert.eq(mc.find().sort({x: 1}).itcount(), sc.find().sort({x: 1}).itcount()); + + replTest.stopSet(15); +}());
\ No newline at end of file |