Search in sources :

Example 1 with BsonTimestamp

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);
}
Also used : TypesMismatchException(com.eightkdata.mongowp.exceptions.TypesMismatchException) OpTime(com.eightkdata.mongowp.OpTime) BsonTimestamp(com.eightkdata.mongowp.bson.BsonTimestamp)

Aggregations

OpTime (com.eightkdata.mongowp.OpTime)1 BsonTimestamp (com.eightkdata.mongowp.bson.BsonTimestamp)1 TypesMismatchException (com.eightkdata.mongowp.exceptions.TypesMismatchException)1