@SneakyThrows(StreamingException.class) private void checkTruncatedSegment(StreamingException ex, RollingSegmentHandle handle, SegmentChunk segmentChunk) { if (ex != null && (Exceptions.unwrap(ex) instanceof StreamSegmentNotExistsException) || !segmentChunk.exists()) { // We ran into a SegmentChunk that does not exist (either marked as such or due to a failed read). segmentChunk.markInexistent(); String message = String.format("Offsets %d-%d have been deleted.", segmentChunk.getStartOffset(), segmentChunk.getLastOffset()); ex = new StreamSegmentTruncatedException(handle.getSegmentName(), message, ex); } if (ex != null) { throw ex; } }
private void refreshChunkExistence(RollingSegmentHandle handle) { // We check all SegmentChunks that we assume exist for actual existence (since once deleted, they can't come back). for (SegmentChunk s : handle.chunks()) { if (s.exists() && !this.baseStorage.exists(s.getName())) { s.markInexistent(); } } }
private void deleteChunks(RollingSegmentHandle handle, Predicate<SegmentChunk> canDelete) throws StreamSegmentException { for (SegmentChunk s : handle.chunks()) { if (s.exists() && canDelete.test(s)) { try { val subHandle = this.baseStorage.openWrite(s.getName()); this.baseStorage.delete(subHandle); s.markInexistent(); log.debug("Deleted SegmentChunk '{}' for '{}'.", s, handle); } catch (StreamSegmentNotExistsException ex) { // Ignore; It's OK if it doesn't exist; just make sure the handle is updated. s.markInexistent(); } } } }
/** * Creates a new instance of the SegmentChunk class with the same information as this one, but with a new offset. * * @param newOffset The new offset. * @return A new SegmentChunk. */ SegmentChunk withNewOffset(long newOffset) { SegmentChunk ns = new SegmentChunk(this.name, newOffset); ns.setLength(getLength()); if (isSealed()) { ns.markSealed(); } if (!exists()) { ns.markInexistent(); } return ns; }
Assert.assertFalse("Expected first SegmentChunk to be marked as deleted.", writeHandle.chunks().get(failAtIndex - 1).exists()); Assert.assertTrue("Expected failed-to-delete SegmentChunk to not be marked as deleted.", writeHandle.chunks().get(failAtIndex).exists()); Assert.assertTrue("Expected subsequent SegmentChunk to not be marked as deleted.", writeHandle.chunks().get(failAtIndex + 1).exists());
expectedExists, segmentChunk.exists()); boolean existsInStorage = baseStorage.exists(segmentChunk.getName()); Assert.assertEquals("Expected SegmentChunk deletion status for " + segmentChunk + ", truncation offset = " + truncateOffset,