From 2f1ebbbcc7c82857d9ece9039902e9faa3196678 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Tue, 22 Oct 2013 00:27:08 -0700 Subject: [PATCH] Restructure code to "allow" misordered sequencers. Throw in an assertion that they aren't misordered anyway. This will be removed before merge. But it should never fire for a singleton replset. --- packages/mongo-livedata/mongo_driver.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/mongo-livedata/mongo_driver.js b/packages/mongo-livedata/mongo_driver.js index dd36270299..d1f9ea0516 100644 --- a/packages/mongo-livedata/mongo_driver.js +++ b/packages/mongo-livedata/mongo_driver.js @@ -330,15 +330,25 @@ MongoConnection.prototype._startOplogTailing = function (oplogUrl, return; } - if (!_.isEmpty(pendingSequencers) - && _.last(pendingSequencers).ts.greaterThan(ts)) { + var insertAfter = pendingSequencers.length; + while (insertAfter - 1 > 0 + && pendingSequencers[insertAfter - 1].ts.greaterThan(ts)) { + insertAfter--; + } + + // XXX this can occur if we fail over from one primary to another. so + // this check needs to be removed before we merge oplog. that said, it + // has been helpful so far at proving that we are properly using + // poolSize 1. Also, we could keep something like it if we could + // actually detect failover; see + // https://github.com/mongodb/node-mongodb-native/issues/1120 + if (insertAfter !== pendingSequencers.length) { throw Error("found misordered oplog: " + showTS(_.last(pendingSequencers).ts) + " vs " + showTS(ts)); } - pendingSequencers.push({ts: ts, - callback: callback}); + pendingSequencers.splice(insertAfter, 0, {ts: ts, callback: callback}); }).run(); } };