@SuppressWarnings({ "unchecked", "rawtypes" }) public static int compare(Timestamp oplogTimestamp, Timestamp startTimestamp) { return oplogTimestamp.compareTo(startTimestamp); }
/** Parse last timestamp field(s) from river source metadata. */ public static Timestamp<?> on(Map<String, Object> map) { return on(map, true); }
private static XContentBuilder source(Timestamp<?> time) throws IOException { XContentBuilder builder = jsonBuilder().startObject().startObject(TYPE); time.saveFields(builder); return builder.endObject().endObject(); }
Long lastTimestamp = null; if (ts != null) { lastTimestamp = ts.getTime();
private DBCursor oplogCursor(final Timestamp<?> time) throws SlurperException { DBObject indexFilter = time.getOplogFilter(); if (indexFilter == null) { return null; } int options = Bytes.QUERYOPTION_TAILABLE | Bytes.QUERYOPTION_AWAITDATA | Bytes.QUERYOPTION_NOTIMEOUT // Using OPLOGREPLAY to improve performance: // https://jira.mongodb.org/browse/JAVA-771 | Bytes.QUERYOPTION_OPLOGREPLAY; DBCursor cursor = oplogCollection.find(indexFilter).setOptions(options); // Toku sometimes gets stuck without this hint: if (indexFilter.containsField(MongoDBRiver.MONGODB_ID_FIELD)) { cursor = cursor.hint("_id_"); } isRiverStale(cursor, time); return cursor; }
/** Parse timestamp field(s) on an oplog entry. */ public static Timestamp<?> on(DBObject entry) { return on(entry.toMap(), false); }
} else { for (Shard shard : config.getShards()) { if (startTimestamp == null || shard.getLatestOplogTimestamp().compareTo(startTimestamp) < 1) { startTimestamp = shard.getLatestOplogTimestamp(); if (initialImportTimestamp == null || shard.getLatestOplogTimestamp().compareTo(initialImportTimestamp) < 1) { initialImportTimestamp = shard.getLatestOplogTimestamp();
private Timestamp<?> getCurrentOplogTimestamp() { try (DBCursor cursor = oplogCollection.find().sort(new BasicDBObject(MongoDBRiver.INSERTION_ORDER_KEY, -1)).limit(1)) { return Timestamp.on(cursor.next()); } }
private void isRiverStale(DBCursor cursor, Timestamp<?> time) throws SlurperException { if (cursor == null || time == null) { return; } if (definition.getInitialTimestamp() != null && time.equals(definition.getInitialTimestamp())) { return; } DBObject entry = cursor.next(); Timestamp<?> oplogTimestamp = Timestamp.on(entry); if (!time.equals(oplogTimestamp)) { MongoDBRiverHelper.setRiverStatus(esClient, definition.getRiverName(), Status.RIVER_STALE); throw new SlurperException("River out of sync with oplog.rs collection"); } }
private Timestamp<?> getCurrentOplogTimestamp(MongoClient shardClient) { DBCollection oplogCollection = shardClient .getDB(MongoDBRiver.MONGODB_LOCAL_DATABASE) .getCollection(MongoDBRiver.OPLOG_COLLECTION); try (DBCursor cursor = oplogCollection.find().sort(new BasicDBObject("$natural", -1)).limit(1)) { return Timestamp.on(cursor.next()); } }
/** * Get the latest timestamp for a given namespace. */ @SuppressWarnings("unchecked") public static Timestamp<?> getLastTimestamp(Client client, MongoDBRiverDefinition definition) { client.admin().indices().prepareRefresh(definition.getRiverIndexName()).get(); GetResponse lastTimestampResponse = client.prepareGet(definition.getRiverIndexName(), definition.getRiverName(), definition.getMongoOplogNamespace()).get(); if (lastTimestampResponse.isExists()) { Map<String, Object> mongodbState = (Map<String, Object>) lastTimestampResponse.getSourceAsMap().get(TYPE); if (mongodbState != null) { Timestamp<?> lastTimestamp = Timestamp.on(mongodbState); if (lastTimestamp != null) { return lastTimestamp; } } } else { if (definition.getInitialTimestamp() != null) { return definition.getInitialTimestamp(); } } return null; }
String namespace = entry.get(MongoDBRiver.OPLOG_NAMESPACE).toString(); String collection = null; Timestamp<?> oplogTimestamp = Timestamp.on(entry); DBObject object = (DBObject) entry.get(MongoDBRiver.OPLOG_OBJECT);