public void onBecomeInactiveSegment() throws IOException {
        timeIndex().maybeAppend(maxTimestampSoFar(), shallowOffsetOfMaxTimestampSoFar(), true);
        offsetIndex().trimToValidSize();
        timeIndex().trimToValidSize();
        log.trim();
    }
Append the largest time index entry to the time index and trim the log and indexes.

The time index entry appended will be used to decide when to delete the segment.
storage/src/main/java/org/apache/kafka/storage/internals/log/LogSegment.java