.cursorType(CursorType.TailableAwait).noCursorTimeout(true);
/** * Use the given primary to read the oplog. * * @param primary the connection to the replica set's primary node; may not be null */ protected void readOplog(MongoClient primary) { BsonTimestamp oplogStart = source.lastOffsetTimestamp(replicaSet.replicaSetName()); logger.info("Reading oplog for '{}' primary {} starting at {}", replicaSet, primary.getAddress(), oplogStart); // Include none of the cluster-internal operations and only those events since the previous timestamp ... MongoCollection<Document> oplog = primary.getDatabase("local").getCollection("oplog.rs"); Bson filter = Filters.and(Filters.gt("ts", oplogStart), // start just after our last position Filters.exists("fromMigrate", false)); // skip internal movements across shards FindIterable<Document> results = oplog.find(filter) .sort(new Document("$natural", 1)) // force forwards collection scan .oplogReplay(true) // tells Mongo to not rely on indexes .cursorType(CursorType.TailableAwait); // tail and await new data // Read as much of the oplog as we can ... ServerAddress primaryAddress = primary.getAddress(); try (MongoCursor<Document> cursor = results.iterator()) { while (running.get() && cursor.hasNext()) { if (!handleOplogEvent(primaryAddress, cursor.next())) { // Something happened, and we're supposed to stop reading return; } } } }
.oplogReplay(true) // tells Mongo to not rely on indexes .noCursorTimeout(true) // don't timeout waiting for events .cursorType(CursorType.TailableAwait);
.cursorType(CursorType.TailableAwait).noCursorTimeout(true);
@Override public FindOperationConfigurator cursorType(CursorType cursorType) { iterable.cursorType(cursorType); return this; }
private MongoCursor<BasicDBObject> initializeCursor() { Object lastVal = tailTracking.lastVal; // lastVal can be null if we are initializing and there is no persistence enabled MongoCursor<BasicDBObject> answer; if (lastVal == null) { answer = dbCol.find().cursorType(CursorType.TailableAwait).iterator(); } else { final String increasingFieldName = tailTracking.getIncreasingFieldName(); BasicDBObject queryObj = endpoint.getTailTrackingStrategy().createQuery(lastVal, increasingFieldName); answer = dbCol.find(queryObj).cursorType(CursorType.TailableAwait).iterator(); } return answer; }
private FindIterable<Document> find(int page){ final FindIterable<Document> documents = oplog .find(query) .sort(new Document("$natural", 1)) .skip(page * batchSize) .limit(batchSize) .projection(Projections.include("ts", "op", "ns", "o")) .cursorType(CursorType.TailableAwait); return documents; }
ret.cursorType(CursorType.TailableAwait); if (timeout == 0) { ret.noCursorTimeout(true);
.sort(MongoBsonTranslator.translate(sortBy)) .projection(MongoBsonTranslator.translate(projection)) .cursorType(toCursorType(queryOptions)) .noCursorTimeout(queryOptions.isNoCursorTimeout()) .oplogReplay(queryOptions.isOplogReplay());
.sort(MongoBsonTranslator.translate(sortBy)) .projection(MongoBsonTranslator.translate(projection)) .cursorType(toCursorType(queryOptions)) .noCursorTimeout(queryOptions.isNoCursorTimeout()) .oplogReplay(queryOptions.isOplogReplay());