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(); } } } }
@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(); } } }
/** * 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; }
try { this.baseStorage.delete(subHandle); h.lastChunk().markInexistent(); h.markDeleted(); } catch (StreamSegmentNotExistsException ex) { h.lastChunk().markInexistent(); h.markDeleted(); throw ex;
ex -> ex instanceof IllegalArgumentException); chunk.markInexistent(); val chunk2 = new SegmentChunk("s2", chunk.getLastOffset()); chunk2.setLength(234L); chunk2.getStartOffset() + chunk2.getLength(), h.length()); Assert.assertEquals("Unexpected lastChunk.", chunk2, h.lastChunk()); h.lastChunk().markInexistent(); Assert.assertFalse("Unexpected value from isDeleted after last SegmentChunk marked as inexistent.", h.isDeleted());