Source:
public void suffixTrim() { long globalTailCopy = logMetadata.getGlobalTail(); try { long committedTail = dataStore.getCommittedTail(); if (isTrimmed(committedTail)) { throw new SuffixTrimException("local committed tail is trimmed", committedTail, globalTailCopy); } if (committedTail > globalTailCopy) { throw new SuffixTrimException("local committed tail is greater than global tail", committedTail, globalTailCopy); } long committedSegment = committedTail / RECORDS_PER_LOG_FILE; long tailSegment = Math.max(globalTailCopy, 0L) / RECORDS_PER_LOG_FILE; closeSegmentHandlers(tailSegment); deleteFilesMatchingFilter(file -> { try { String segmentStr = file.getName().split("\\.")[0]; long segment = Long.parseLong(segmentStr); return segment >= committedSegment && segment <= tailSegment; } catch (Exception e) { log.warn("suffixTrim: ignoring file {}", file.getName()); return false; } }); long newTailSegment = Math.max(committedSegment - 1, 0); dataStore.resetTailSegment(); dataStore.updateTailSegment(newTailSegment); logMetadata = new LogMetadata(); rebuildLogMetadataWithValidation(); dataStore.resetTailSegment(); updateCommittedTail(logMetadata.getGlobalTail()); } catch (RuntimeException e) { log.debug("suffixTrim: degrade to reset", e); logMetadata.updateGlobalTail(globalTailCopy); reset(); return; } log.info("suffixTrim: Completed, new end segment {}, new global tail {}", dataStore.getTailSegment(), logMetadata.getGlobalTail()); }

Target:
public void suffixTrim() { long globalTailCopy = logMetadata.getGlobalTail(); try { long committedTail = dataStore.getCommittedTail(); if (committedTail == Address.NON_ADDRESS) { throw new IllegalStateException(String.format("Local committed tail is not " + "initialized, committedTail: %s, globalTail: %s", committedTail, globalTailCopy)); } if (isTrimmed(committedTail)) { throw new IllegalStateException(String.format("Local committed tail is trimmed, " + "committedTail: %s, globalTail: %s", committedTail, globalTailCopy)); } if (committedTail > globalTailCopy) { throw new IllegalStateException(String.format("Local committed tail is greater " + "than global tail, committedTail: %s, globalTail: %s", committedTail, globalTailCopy)); } long tailSegment = getSegmentIndexForAddress(Math.max(globalTailCopy, 0L)); closeSegmentHandlers(tailSegment); long committedSegment = getSegmentIndexForAddress(committedTail); long firstSegmentTBD = isTheLastAddressInASegment(committedTail) ? committedSegment + 1 : committedSegment; deleteFilesMatchingFilter(file -> { try { String segmentStr = file.getName().split("\\.")[0]; long segment = Long.parseLong(segmentStr); return segment >= firstSegmentTBD && segment <= tailSegment; } catch (Exception e) { log.warn("suffixTrim: ignoring file {}", file.getName()); return false; } }); long newTailSegment = Math.max(firstSegmentTBD - 1, 0); dataStore.resetTailSegment(); dataStore.updateTailSegment(newTailSegment); logMetadata = new LogMetadata(); rebuildLogMetadataWithValidation(); dataStore.resetTailSegment(); updateCommittedTail(logMetadata.getGlobalTail()); } catch (RuntimeException e) { log.debug("suffixTrim: degrade to reset", e); logMetadata.updateGlobalTail(globalTailCopy); reset(); return; } log.info("suffixTrim: Completed, new end segment {}, new global tail {}", dataStore.getTailSegment(), logMetadata.getGlobalTail()); }