Skip to content

Instantly share code, notes, and snippets.

@Bowbaq
Created December 1, 2014 19:40
Show Gist options
  • Save Bowbaq/816890ec72681b0c8855 to your computer and use it in GitHub Desktop.
Save Bowbaq/816890ec72681b0c8855 to your computer and use it in GitHub Desktop.
Use the LogReplay optimization, sort is already "$natural" by default
diff --git a/logreplayer.go b/logreplayer.go
index 4660651..817f644 100644
--- a/logreplayer.go
+++ b/logreplayer.go
@@ -76,7 +76,7 @@ func (l *logReplayer) playLog() (err error) {
// set up initial query to the oplog
logger.Info("Replaying oplog from %s to %s", l.from, l.to)
- iter := sourceOplog.Find(bson.M{"ts": bson.M{"$gt": bson.MongoTimestamp(l.from)}}).Sort("$natural").Tail(1 * time.Second)
+ iter := sourceOplog.Find(bson.M{"ts": bson.M{"$gt": bson.MongoTimestamp(l.from)}}).LogReplay().Tail(1 * time.Second)
// loop over the oplog
outer:
@@ -175,7 +175,7 @@ outer:
logger.Critical("too many errors reading from oplog, bailing.")
os.Exit(1)
}
- iter = sourceOplog.Find(bson.M{"ts": bson.M{"$gt": lastTimestamp}}).Sort("$natural").Tail(1 * time.Second)
+ iter = sourceOplog.Find(bson.M{"ts": bson.M{"$gt": lastTimestamp}}).LogReplay().Tail(1 * time.Second)
}
for count > 0 {
@nstott
Copy link

nstott commented Dec 2, 2014

Nice, yeah
that's a good idea, I missed that first time around
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment