public DefaultResolver(MutableIntrinsics intrinsics, Compaction compaction) { this(intrinsics); _intrinsics.setVersion(compaction.getCount()); _intrinsics.setFirstUpdateAt(compaction.getFirst()); _intrinsics.setLastMutateAt(compaction.getFirst()); _intrinsics.setLastUpdateAt(compaction.getFirst()); _compactionCutoffId = compaction.getCutoff(); _compactionCutoffSignature = compaction.getCutoffSignature(); _lastCompactedMutationId = compaction.getLastMutation(); _lastMutationId = _lastCompactedMutationId; if (compaction.hasCompactedDelta()) { // We have compacted delta in this compaction. No cutoff delta was mutated as a part of this compaction. _content = DeltaEvaluator.eval(compaction.getCompactedDelta(), _content, _intrinsics); _lastAppliedTags = compaction.getLastTags(); _intrinsics.setDeleted(_content == Resolved.UNDEFINED); _intrinsics.setSignature(parseHash(_compactionCutoffSignature)); _intrinsics.setLastMutateAt(compaction.getLastContentMutation()); _intrinsics.setLastUpdateAt(compaction.getCutoff()); } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Compaction)) { return false; } Compaction that = (Compaction) o; return _count == that._count && Objects.equal(_first, that.getFirst()) && Objects.equal(_cutoff, that.getCutoff()) && Objects.equal(_cutoffSignature, that.getCutoffSignature()) && Objects.equal(_lastMutation, that.getLastMutation()) && Objects.equal(_lastContentMutation, that.getLastContentMutation()); }
if (!isFirstCompaction) { Compaction compactionInfo = new Compaction(versionOfFirstCompactedDelta, compaction.getFirst(), compaction.getCutoff(), compaction.getCutoffSignature(), compaction.getLastContentMutation(), compaction.getLastMutation(), pendingCompaction.getStartingDelta(), compaction.getLastTags()); resolver = new DefaultResolver(intrinsics, compactionInfo); } else {
if (compactionEntry != null && !compactionEntry.getValue().hasCompactedDelta()) { numDeletedDeltas = compaction.getCount(); cutoffId = compaction.getCutoff(); initialCutoff = compaction.getCutoff(); while (deltaIterator.hasNext() && TimeUUIDs.compare(deltaIterator.peek().getKey(), cutoffId) <= 0) { if (!deleteDeltasForCompaction) { assert (compaction.getCompactedDelta().isConstant()) : "Compacted delta was not a literal"; cutoffDelta = compaction.getCompactedDelta(); initialCutoffDelta = compaction.getCompactedDelta(); compaction = new Compaction( resolved.getIntrinsics().getVersion(), resolved.getIntrinsics().getFirstUpdateAtUuid(), cutoffId = compaction.getCutoff(); cutoffDelta = resolved.getConstant(); compactionChanged = true;
UUID cutoffId = compaction.getCutoff(); UUID initialCutoff = compaction.getCutoff(); boolean compactionChanged = false; long numDeletedDeltas = compaction.getCount(); compaction = new Compaction( resolved.getIntrinsics().getVersion(), resolved.getIntrinsics().getFirstUpdateAtUuid(), cutoffId = compaction.getCutoff(); cutoffDelta = resolved.getConstant(); compactionChanged = true;
protected void updateSizeCounter(@Nullable PendingCompaction pendingCompaction) { if (pendingCompaction == null) { return; } long deltaSizeInBytes = 0L; for (Map.Entry<UUID, Delta> deltaEntry : pendingCompaction.getDeltasToArchive()) { long deltaSize = deltaEntry.getValue().size(); deltaSizeInBytes += deltaSize; _deltaSizeHistogram.update(deltaSize); } // One last check to make sure we don't violate transport protocol size limit // Delta History saves history for each compacted delta that includes // 1) Actual Delta, and 2) Complete resolved content as of that Delta // While we do have the size of actual deltas, we need to account for the resolved content that will get saved // with each delta history. To get that, we will assume that the actual content size for each delta is going to // be roughly the size of the final compacted delta literal. We do not want to resolve content for each delta // here. // TotalDeltaArchiveSize = deltaSize + ContentSize; long eachDeltaContentSize = pendingCompaction.getCompaction().getCompactedDelta().size(); long totalDeltaArchiveSize = deltaSizeInBytes + (pendingCompaction.getDeltasToArchive().size() * eachDeltaContentSize); if (totalDeltaArchiveSize >= MAX_TRANSPORT_SIZE) { _discardedDeltaHistory.mark(); throw new DeltaHistorySizeExceededException(); } _archiveDeltaSizeInMemory.inc(deltaSizeInBytes); }
if (!isFirstCompaction) { Compaction compactionInfo = new Compaction(versionOfFirstCompactedDelta, compaction.getFirst(), compaction.getCutoff(), compaction.getCutoffSignature(), compaction.getLastContentMutation(), compaction.getLastMutation(), pendingCompaction.getStartingDelta(), compaction.getLastTags()); resolver = new DefaultResolver(intrinsics, compactionInfo); } else {
if (compactionEntry != null && !compactionEntry.getValue().hasCompactedDelta()) { numDeletedDeltas = compaction.getCount(); cutoffId = compaction.getCutoff(); initialCutoff = compaction.getCutoff(); while (deltaIterator.hasNext() && TimeUUIDs.compare(deltaIterator.peek().getKey(), cutoffId) <= 0) { if (!deleteDeltasForCompaction) { assert (compaction.getCompactedDelta().isConstant()) : "Compacted delta was not a literal"; cutoffDelta = compaction.getCompactedDelta(); initialCutoffDelta = compaction.getCompactedDelta(); compaction = new Compaction( resolved.getIntrinsics().getVersion(), resolved.getIntrinsics().getFirstUpdateAtUuid(), cutoffId = compaction.getCutoff(); cutoffDelta = resolved.getConstant(); compactionChanged = true;
UUID cutoffId = compaction.getCutoff(); UUID initialCutoff = compaction.getCutoff(); boolean compactionChanged = false; long numDeletedDeltas = compaction.getCount(); compaction = new Compaction( resolved.getIntrinsics().getVersion(), resolved.getIntrinsics().getFirstUpdateAtUuid(), cutoffId = compaction.getCutoff(); cutoffDelta = resolved.getConstant(); compactionChanged = true;
protected void updateSizeCounter(@Nullable PendingCompaction pendingCompaction) { if (pendingCompaction == null) { return; } long deltaSizeInBytes = 0L; for (Map.Entry<UUID, Delta> deltaEntry : pendingCompaction.getDeltasToArchive()) { long deltaSize = deltaEntry.getValue().size(); deltaSizeInBytes += deltaSize; _deltaSizeHistogram.update(deltaSize); } // One last check to make sure we don't violate transport protocol size limit // Delta History saves history for each compacted delta that includes // 1) Actual Delta, and 2) Complete resolved content as of that Delta // While we do have the size of actual deltas, we need to account for the resolved content that will get saved // with each delta history. To get that, we will assume that the actual content size for each delta is going to // be roughly the size of the final compacted delta literal. We do not want to resolve content for each delta // here. // TotalDeltaArchiveSize = deltaSize + ContentSize; long eachDeltaContentSize = pendingCompaction.getCompaction().getCompactedDelta().size(); long totalDeltaArchiveSize = deltaSizeInBytes + (pendingCompaction.getDeltasToArchive().size() * eachDeltaContentSize); if (totalDeltaArchiveSize >= MAX_TRANSPORT_SIZE) { _discardedDeltaHistory.mark(); throw new DeltaHistorySizeExceededException(); } _archiveDeltaSizeInMemory.inc(deltaSizeInBytes); }
public DefaultResolver(MutableIntrinsics intrinsics, Compaction compaction) { this(intrinsics); _intrinsics.setVersion(compaction.getCount()); _intrinsics.setFirstUpdateAt(compaction.getFirst()); _intrinsics.setLastMutateAt(compaction.getFirst()); _intrinsics.setLastUpdateAt(compaction.getFirst()); _compactionCutoffId = compaction.getCutoff(); _compactionCutoffSignature = compaction.getCutoffSignature(); _lastCompactedMutationId = compaction.getLastMutation(); _lastMutationId = _lastCompactedMutationId; if (compaction.hasCompactedDelta()) { // We have compacted delta in this compaction. No cutoff delta was mutated as a part of this compaction. _content = DeltaEvaluator.eval(compaction.getCompactedDelta(), _content, _intrinsics); _lastAppliedTags = compaction.getLastTags(); _intrinsics.setDeleted(_content == Resolved.UNDEFINED); _intrinsics.setSignature(parseHash(_compactionCutoffSignature)); _intrinsics.setLastMutateAt(compaction.getLastContentMutation()); _intrinsics.setLastUpdateAt(compaction.getCutoff()); } }
/** * Find the version of the first delta of a pending compaction retroactively */ public static long getVersionRetroactively(PendingCompaction pendingCompaction) { Compaction compaction = pendingCompaction.getCompaction(); // Calculate the version and create a dummy compaction record for the resolver return compaction.getCount() - (long)pendingCompaction.getDeltasToArchive().size(); } }
/** * Find the version of the first delta of a pending compaction retroactively */ public static long getVersionRetroactively(PendingCompaction pendingCompaction) { Compaction compaction = pendingCompaction.getCompaction(); // Calculate the version and create a dummy compaction record for the resolver return compaction.getCount() - (long)pendingCompaction.getDeltasToArchive().size(); } }
protected Map.Entry<UUID, Compaction> findEffectiveCompaction(Iterator<Map.Entry<UUID, Compaction>> compactionIter, Collection<UUID> otherCompactionIds, long compactionConsistencyTimeStamp) { Compaction best = null; UUID bestId = null; Map.Entry<UUID, Compaction> bestEntry = null; while (compactionIter.hasNext()) { Map.Entry<UUID, Compaction> entry = compactionIter.next(); UUID changeId = entry.getKey(); Compaction compaction = entry.getValue(); // The most recent compaction that covers the most "old deltas" wins if (compaction.getCount() > 0 && (best == null || isLessThan(bestId, best, changeId, compaction))) { if (best != null) { otherCompactionIds.add(bestId); } best = compaction; bestId = changeId; bestEntry = entry; } else { otherCompactionIds.add(changeId); } } // Check if bestEntry is behind FCT. If so, we can get rid of others. if (bestEntry != null && TimeUUIDs.getTimeMillis(bestEntry.getKey()) >= compactionConsistencyTimeStamp) { // Since the bestEntry is ahead of FCT, we keep all the other compactions and defer their deletion otherCompactionIds.clear(); } return bestEntry; }
protected Map.Entry<UUID, Compaction> findEffectiveCompaction(Iterator<Map.Entry<UUID, Compaction>> compactionIter, Collection<UUID> otherCompactionIds, long compactionConsistencyTimeStamp) { Compaction best = null; UUID bestId = null; Map.Entry<UUID, Compaction> bestEntry = null; while (compactionIter.hasNext()) { Map.Entry<UUID, Compaction> entry = compactionIter.next(); UUID changeId = entry.getKey(); Compaction compaction = entry.getValue(); // The most recent compaction that covers the most "old deltas" wins if (compaction.getCount() > 0 && (best == null || isLessThan(bestId, best, changeId, compaction))) { if (best != null) { otherCompactionIds.add(bestId); } best = compaction; bestId = changeId; bestEntry = entry; } else { otherCompactionIds.add(changeId); } } // Check if bestEntry is behind FCT. If so, we can get rid of others. if (bestEntry != null && TimeUUIDs.getTimeMillis(bestEntry.getKey()) >= compactionConsistencyTimeStamp) { // Since the bestEntry is ahead of FCT, we keep all the other compactions and defer their deletion otherCompactionIds.clear(); } return bestEntry; }