public void trimToValidSize() throws IOException {
        lock.lock();
        try {
            resize(entrySize() * entries);
        } finally {
            lock.unlock();
        }
    }
Trim this segment to fit just the valid entries, deleting all trailing unwritten bytes from
the file.
storage/src/main/java/org/apache/kafka/storage/internals/log/AbstractIndex.java