summaryrefslogtreecommitdiff
path: root/jstests/replsets/initial_sync_oplog_rollover.js
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2017-03-16 18:08:49 -0400
committerJudah Schvimer <judah@mongodb.com>2017-03-16 18:08:49 -0400
commitf53a88a57da5788b355cb3037061372a706ccf0d (patch)
tree7a62a074b6dcdcbdc324a37207df1eff5ae8eede /jstests/replsets/initial_sync_oplog_rollover.js
parent5fe822f53e4bb28e15af2541c0ca931fa05a0e20 (diff)
downloadmongo-f53a88a57da5788b355cb3037061372a706ccf0d.tar.gz
SERVER-26772 removed old initial sync code
Diffstat (limited to 'jstests/replsets/initial_sync_oplog_rollover.js')
-rw-r--r--jstests/replsets/initial_sync_oplog_rollover.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/jstests/replsets/initial_sync_oplog_rollover.js b/jstests/replsets/initial_sync_oplog_rollover.js
new file mode 100644
index 00000000000..858b9d279d3
--- /dev/null
+++ b/jstests/replsets/initial_sync_oplog_rollover.js
@@ -0,0 +1,65 @@
+/**
+ * This test tests that initial sync succeeds when the sync source's oplog rolls over before the
+ * destination node reaches the oplog apply phase. It adds a new secondary to a replicaset and then
+ * pauses the initial sync before it copies the databases but after it starts to fetch and buffer
+ * oplog entries. The primary then fills up its oplog until it rolls over. At that point
+ * initial sync is resumed and we assert that it succeeds and that all of the inserted documents
+ * are there.
+ */
+
+(function() {
+ "use strict";
+ load("jstests/libs/check_log.js");
+
+ var name = 'initial_sync_oplog_rollover';
+ var replSet = new ReplSetTest({
+ name: name,
+ nodes: 1,
+ });
+
+ var oplogSizeOnPrimary = 1; // size in MB
+ replSet.startSet({oplogSize: oplogSizeOnPrimary});
+ replSet.initiate();
+ var primary = replSet.getPrimary();
+
+ var coll = primary.getDB('test').foo;
+ assert.writeOK(coll.insert({a: 1}));
+
+ function getFirstOplogEntry(conn) {
+ return conn.getDB('local').oplog.rs.find().sort({ts: 1}).limit(1)[0];
+ }
+
+ var firstOplogEntry = getFirstOplogEntry(primary);
+
+ // Add a secondary node but make it hang before copying databases.
+ var secondary = replSet.add();
+ secondary.setSlaveOk();
+
+ assert.commandWorked(secondary.getDB('admin').runCommand(
+ {configureFailPoint: 'initialSyncHangBeforeCopyingDatabases', mode: 'alwaysOn'}));
+ replSet.reInitiate();
+
+ checkLog.contains(secondary,
+ 'initial sync - initialSyncHangBeforeCopyingDatabases fail point enabled');
+
+ // Keep inserting large documents until they roll over the oplog.
+ const largeStr = new Array(4 * 1024 * oplogSizeOnPrimary).join('aaaaaaaa');
+ var i = 0;
+ while (bsonWoCompare(getFirstOplogEntry(primary), firstOplogEntry) === 0) {
+ assert.writeOK(coll.insert({a: 2, x: i++, long_str: largeStr}));
+ sleep(100);
+ }
+
+ assert.commandWorked(secondary.getDB('admin').runCommand(
+ {configureFailPoint: 'initialSyncHangBeforeCopyingDatabases', mode: 'off'}));
+
+ replSet.awaitSecondaryNodes(200 * 1000);
+
+ assert.eq(i,
+ secondary.getDB('test').foo.count({a: 2}),
+ 'collection successfully synced to secondary');
+
+ assert.eq(0,
+ secondary.getDB('local')['temp_oplog_buffer'].find().itcount(),
+ "Oplog buffer was not dropped after initial sync");
+})();