public boolean truncateSuffix(final long lastIndexKept, final int pos) {
        if (getLastLogIndex() <= lastIndexKept) {
            return true;
        }
        this.readLock.lock();
        final List<AbstractFile> willRemoveFiles = new ArrayList<>();
        try {
            long retainPosition = 0;
            for (final AbstractFile abstractFile : this.files) {
                final long firstLogIndex = abstractFile.getFirstLogIndex();
                final long lastLogIndex = abstractFile.getLastLogIndex();
                if (lastLogIndex > lastIndexKept) {
                    if (lastIndexKept >= firstLogIndex) {
                        // Truncate
                        final int lastPosition = abstractFile.truncate(lastIndexKept + 1, pos);
                        retainPosition += lastPosition;
                    } else {
                        // Remove
                        willRemoveFiles.add(abstractFile);
                    }
                } else {
                    retainPosition += this.fileSize;
                }
            }
            // Update flush position
            if (retainPosition < getFlushedPosition())
                setFlushedPosition(retainPosition);
            return true;
        } finally {
            this.readLock.unlock();
            for (final AbstractFile file : willRemoveFiles) {
                if (file != null) {
                    file.shutdown(1000, true);
                }
            }
            deleteFiles(willRemoveFiles);
        }
    }
Truncate files suffix by lastIndexKept , (last_index_kept, last_log_index]
 will be discarded.
jraft-extension/java-log-storage-impl/src/main/java/com/alipay/sofa/jraft/storage/file/FileManager.java