use of com.eightkdata.mongowp.bson.BsonTimestamp in project torodb by torodb.
the class ReplSetHeartbeatReplyMarshaller method parseAppliedOpTime.
private static void parseAppliedOpTime(BsonDocument bson, ReplSetHeartbeatReplyBuilder builder, long term) throws TypesMismatchException, NoSuchKeyException {
// In order to support both the 3.0(V0) and 3.2(V1) heartbeats we must parse the OpTime
// field based on its type. If it is a Date, we parse it as the timestamp and use
// initialize's term argument to complete the OpTime type. If it is an Object, then it's
// V1 and we construct an OpTime out of its nested fields.
Entry<?> entry = BsonReaderTool.getEntry(bson, APPLIED_OP_TIME_FIELD_NAME, null);
if (entry == null) {
return;
}
BsonValue<?> value = entry.getValue();
OpTime opTime;
switch(value.getType()) {
case TIMESTAMP:
opTime = new OpTime(value.asTimestamp(), term);
break;
case DATETIME:
BsonTimestamp ts = BsonReaderTool.getTimestampFromDateTime(entry);
opTime = new OpTime(ts, term);
break;
case //repl v1
DOCUMENT:
opTime = OpTime.fromBson(value.asDocument());
builder.setIsReplSet(true);
break;
default:
throw new TypesMismatchException(APPLIED_OP_TIME_FIELD_NAME, "Date or Timestamp", value.getType());
}
builder.setAppliedOpTime(opTime);
}
Aggregations