/** * Transform a wavelet delta if it has been submitted against a different head (currentVersion). * Must be called with write lock held. * * @param delta to possibly transform * @return the transformed delta and the version it was applied at * (the version is the current version of the wavelet, unless the delta is * a duplicate in which case it is the version at which it was originally * applied) * @throws InvalidHashException if submitting against same version but different hash * @throws OperationException if transformation fails */ protected WaveletDelta maybeTransformSubmittedDelta(WaveletDelta delta) throws InvalidHashException, OperationException { HashedVersion targetVersion = delta.getTargetVersion(); HashedVersion currentVersion = getCurrentVersion(); if (targetVersion.equals(currentVersion)) { // Applied version is the same, we're submitting against head, don't need to do OT return delta; } else { // Not submitting against head, we need to do OT, but check the versions really are different if (targetVersion.getVersion() == currentVersion.getVersion()) { LOG.warning("Mismatched hash, expected " + currentVersion + ") but delta targets (" + targetVersion + ")"); throw new InvalidHashException(currentVersion, targetVersion); } else { return transformSubmittedDelta(delta); } } }