Shorten the locking in tailQuery()
@@ -164,15 +164,18 @@ func (ot *OplogTail) tail() {
}
func (ot *OplogTail) tailQuery() bson.M {
- ot.lock.Lock()
- defer ot.lock.Unlock()
-
query := bson.M{"op": bson.M{"$ne": mdbstructs.OperationNoop}}
+
+ ot.lock.Lock()
if ot.lastOplogTimestamp != nil {
query["ts"] = bson.M{"$gt": *ot.lastOplogTimestamp}
+ return query
} else if ot.startOplogTimestamp != nil {
query["ts"] = bson.M{"$gte": *ot.startOplogTimestamp}
- } else {
+ return query
+ }
+ ot.lock.Unlock()
+
isMasterDoc, err := getIsMaster(ot.session)
if err != nil {
mongoTimestamp, _ := bson.NewMongoTimestamp(time.Now(), 0)
@@ -180,7 +183,6 @@ func (ot *OplogTail) tailQuery() bson.M {
} else {
query["ts"] = bson.M{"$gt": isMasterDoc.LastWrite.OpTime.Ts}
}
- }
return query
}
