private void truncateToEntries(int entries) {
        lock.lock();
        try {
            super.truncateToEntries0(entries);
            this.lastEntry = lastEntryFromIndexFile();
            log.debug("Truncated index {} to {} entries; position is now {} and last entry is now {}",
                file().getAbsolutePath(), entries, mmap().position(), lastEntry.offset);
        } finally {
            lock.unlock();
        }
    }
Truncates index to a known number of entries.
storage/src/main/java/org/apache/kafka/storage/internals/log/TimeIndex.java