@Override
    public void truncateTo(long offset) {
        lock.lock();
        try {
            ByteBuffer idx = mmap().duplicate();
            int slot = largestLowerBoundSlotFor(idx, offset, IndexSearchType.VALUE);

            /* There are 3 cases for choosing the new size
             * 1) if there is no entry in the index <= the offset, delete everything
             * 2) if there is an entry for this exact offset, delete it and everything larger than it
             * 3) if there is no entry for this offset, delete everything larger than the next smallest
             */
            int newEntries;
            if (slot < 0)
                newEntries = 0;
            else if (relativeOffset(idx, slot) == offset - baseOffset())
                newEntries = slot;
            else
                newEntries = slot + 1;

            truncateToEntries(newEntries);
        } finally {
            lock.unlock();
        }
    }
Remove all entries from the index which have an offset greater than or equal to the given offset.
Truncating to an offset larger than the largest in the index has no effect.
storage/src/main/java/org/apache/kafka/storage/internals/log/TimeIndex.java