summaryrefslogtreecommitdiff
path: root/jstests/replsets/initial_sync2.js
diff options
context:
space:
mode:
authorKristina Chodorow <kristina@10gen.com>2010-11-09 17:28:32 -0500
committerKristina Chodorow <kristina@10gen.com>2010-11-09 17:29:27 -0500
commit2683812ba8b59cc73db0c9826444cdc2b3fdc19d (patch)
tree6735314e3de93bf691cf868cdcc65b5c59b0a7f4 /jstests/replsets/initial_sync2.js
parent8e348439b2b6f0960627c322948b2ab1ec313fea (diff)
downloadmongo-2683812ba8b59cc73db0c9826444cdc2b3fdc19d.tar.gz
allow initial sync from secondaries SERVER-1829
Diffstat (limited to 'jstests/replsets/initial_sync2.js')
-rw-r--r--jstests/replsets/initial_sync2.js132
1 files changed, 132 insertions, 0 deletions
diff --git a/jstests/replsets/initial_sync2.js b/jstests/replsets/initial_sync2.js
new file mode 100644
index 00000000000..04d53acef74
--- /dev/null
+++ b/jstests/replsets/initial_sync2.js
@@ -0,0 +1,132 @@
+/**
+ * Test killing the primary during initial sync
+ * and don't allow the other secondary to become primary
+ *
+ * 1. Bring up set
+ * 2. Insert some data
+ * 4. Make sure synced
+ * 5. Freeze #2
+ * 6. Bring up #3
+ * 7. Kill #1 in the middle of syncing
+ * 8. Check that #1 doesn't make it into secondary state for a while
+ * 9. Bring #1 back up
+ * 10. Initial sync should succeed
+ * 11. Insert some stuff
+ * 12. Everyone happy eventually
+ */
+
+load("jstests/replsets/rslib.js");
+var basename = "jstests_initsync2";
+
+
+print("1. Bring up set");
+var replTest = new ReplSetTest( {name: basename, nodes: 2} );
+var conns = replTest.startSet();
+replTest.initiate();
+
+var master = replTest.getMaster();
+var foo = master.getDB("foo");
+var admin = master.getDB("admin");
+
+var slave1 = replTest.liveNodes.slaves[0];
+var admin_s1 = slave1.getDB("admin");
+var local_s1 = slave1.getDB("local");
+
+print("2. Insert some data");
+for (var i=0; i<10000; i++) {
+ foo.bar.insert({date : new Date(), x : i, str : "all the talk on the market"});
+}
+print("total in foo: "+foo.bar.count());
+
+
+print("4. Make sure synced");
+replTest.awaitReplication();
+
+
+print("5. Freeze #2");
+admin_s1.runCommand({replSetFreeze:999999});
+
+
+print("6. Bring up #3");
+var ports = allocatePorts( 3 );
+var basePath = "/data/db/" + basename;
+var hostname = getHostName();
+
+var sargs = new MongodRunner( ports[ 2 ], basePath, false, false,
+ ["--replSet", basename, "--oplogSize", 2],
+ {no_bind : true} );
+var slave2 = sargs.start();
+var local_s2 = slave2.getDB("local");
+var admin_s2 = slave2.getDB("admin");
+
+var config = replTest.getReplSetConfig();
+config.version = 2;
+config.members.push({_id:2, host:hostname+":"+ports[2]});
+
+try {
+ admin.runCommand({replSetReconfig:config});
+}
+catch(e) {
+ print(e);
+}
+reconnect(slave1);
+reconnect(slave2);
+
+wait(function() {
+ var config2 = local_s1.system.replset.findOne();
+ var config3 = local_s2.system.replset.findOne();
+
+ printjson(config2);
+ printjson(config3);
+
+ return config2.version == config.version &&
+ (config3 && config3.version == config.version);
+ });
+
+wait(function() {
+ var status = admin_s2.runCommand({replSetGetStatus:1});
+ printjson(status);
+ return status.members[2].state == 3 ||
+ status.members[2].state == 2;
+ });
+
+
+print("7. Kill #1 in the middle of syncing");
+replTest.stop(0);
+
+
+print("8. Check that #1 doesn't make it into secondary state for a while");
+for (var i=0; i<100; i++) {
+ var status = admin_s2.runCommand({replSetGetStatus:1});
+ assert(status.members[2].state != 2);
+ sleep(1000);
+}
+
+
+print("9. Bring #2 back up");
+replTest.start(0, {}, true);
+reconnect(master);
+wait(function() {
+ var status = admin.runCommand({replSetGetStatus:1});
+ printjson(status);
+ return status.members[0].state == 1;
+ });
+
+
+print("10. Initial sync should succeed");
+wait(function() {
+ var status = admin_s2.runCommand({replSetGetStatus:1});
+ printjson(status);
+ return status.members[2].state == 2;
+ });
+
+
+print("11. Insert some stuff");
+master = replTest.getMaster();
+for (var i=0; i<10000; i++) {
+ foo.bar.insert({date : new Date(), x : i, str : "all the talk on the market"});
+}
+
+
+print("12. Everyone happy eventually");
+replTest.awaitReplication();