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