use of com.eightkdata.mongowp.bson.BsonDateTime in project torodb by torodb.
the class OplogManager method loadState.
@Locked(exclusive = true)
private void loadState() throws OplogManagerPersistException {
try {
retrier.retry(() -> {
try (ReadOnlyMongodTransaction transaction = connection.openReadOnlyTransaction()) {
Status<FindResult> status = transaction.execute(new Request(OPLOG_DB, null, true, null), FindCommand.INSTANCE, new FindArgument.Builder().setCollection(OPLOG_COL).setSlaveOk(true).build());
if (!status.isOk()) {
throw new RetrierAbortException(new MongoException(status));
}
Iterator<BsonDocument> batch = status.getResult().getCursor().getFirstBatch();
if (!batch.hasNext()) {
lastAppliedHash = 0;
lastAppliedOpTime = OpTime.EPOCH;
} else {
BsonDocument doc = batch.next();
BsonDocument subDoc = BsonReaderTool.getDocument(doc, KEY);
lastAppliedHash = BsonReaderTool.getLong(subDoc, "hash");
long optimeAsLong = BsonReaderTool.getLong(subDoc, "optime_i");
BsonDateTime optimeAsDateTime = DefaultBsonValues.newDateTime(optimeAsLong);
lastAppliedOpTime = new OpTime(TimestampToDateTime.toTimestamp(optimeAsDateTime, DefaultBsonValues::newTimestamp), BsonReaderTool.getLong(subDoc, "optime_t"));
}
notifyLastAppliedOpTimeChange();
return Empty.getInstance();
}
}, Hint.INFREQUENT_ROLLBACK);
} catch (RetrierGiveUpException ex) {
throw new OplogManagerPersistException(ex);
}
}
Aggregations