code: private void compactSegments() {
      // Create a compact segment with a newer version to which to rewrite the segment entries.
      Segment compactSegment = manager.createSegment(SegmentDescriptor.builder()
        .withId(segment.descriptor().id())
        .withVersion(segment.descriptor().version() + 1)
        .withIndex(segment.descriptor().index())
        .withMaxSegmentSize(segment.descriptor().maxSegmentSize())
        .withMaxEntries(segment.descriptor().maxEntries())
        .build());
  
      compactEntries(segment, compactSegment);
  
      // Replace the old segment with the compact segment.
      manager.replaceSegments(Collections.singletonList(segment), compactSegment);
  
      // Update the new segment with offsets that were released during compaction.
      mergeReleasedEntries(segment, compactSegment);
  
      // Delete the old segment.
      segment.close();
      segment.delete();
    }
docs: Compacts all compactable segments.