/** * Calculates the hashed version after an applied delta is applied. */ public static HashedVersion calculateResultingHashedVersion( ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDelta) throws InvalidProtocolBufferException { return HASH_FACTORY.create( appliedDelta.getByteArray(), getHashedVersionAppliedAt(appliedDelta), appliedDelta.getMessage().getOperationsApplied()); }
@Override public HashedVersion getAppliedAtVersion(long version) throws IOException { lifeCycle.enter(); try { checkIsOpen(); ByteStringMessage<ProtocolAppliedWaveletDelta> applied = getAppliedDelta(version); return (applied != null) ? AppliedDeltaUtil.getHashedVersionAppliedAt(applied) : null; } finally { lifeCycle.leave(); } }
/** * Read a record and return it. */ private WaveletDeltaRecord readRecord() throws IOException { DeltaHeader header = readDeltaHeader(); ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDelta = readAppliedDelta(header.appliedDeltaLength); TransformedWaveletDelta transformedDelta = readTransformedWaveletDelta( header.transformedDeltaLength); return new WaveletDeltaRecord(AppliedDeltaUtil.getHashedVersionAppliedAt(appliedDelta), appliedDelta, transformedDelta); }
/** * Builds a transformed delta from an applied delta and its transformed ops. */ public static TransformedWaveletDelta buildTransformedDelta( ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDeltaBytes, WaveletDelta transformed) throws InvalidProtocolBufferException { ProtocolAppliedWaveletDelta appliedDelta = appliedDeltaBytes.getMessage(); Preconditions.checkArgument( getHashedVersionAppliedAt(appliedDeltaBytes).equals(transformed.getTargetVersion())); Preconditions.checkArgument(appliedDelta.getOperationsApplied() == transformed.size()); HashedVersion resultingVersion = HASH_FACTORY.create(appliedDeltaBytes.getByteArray(), transformed.getTargetVersion(), appliedDelta.getOperationsApplied()); return TransformedWaveletDelta.cloneOperations(resultingVersion, appliedDelta.getApplicationTimestamp(), transformed); }
appliedAt = AppliedDeltaUtil.getHashedVersionAppliedAt(appliedDelta); } catch (InvalidProtocolBufferException e) { markStateCorrupted();
HashedVersion hashedVersion = AppliedDeltaUtil.getHashedVersionAppliedAt(appliedDelta); Preconditions.checkState(hashedVersion.equals(getCurrentVersion()), "Applied delta must apply to current version");