public void truncateSuffix(final int wrotePos, final long logIndex, final boolean sync) {
        this.writeLock.lock();
        try {
            if (wrotePos >= this.wrotePos) {
                return;
            }
            swapInIfNeed();
            final int oldPos = this.wrotePos;
            clear(wrotePos, sync);
            this.wrotePos = wrotePos;
            this.lastLogIndex = logIndex;
            BufferUtils.position(this.buffer, wrotePos);
            LOG.info(
                "Segment file {} truncate suffix from pos={}, then set lastLogIndex={}, oldWrotePos={}, newWrotePos={}",
                this.path, wrotePos, logIndex, oldPos, this.wrotePos);
        } finally {
            this.writeLock.unlock();
        }
    }
Truncate data from wrotePos(inclusive) to the file end and set lastLogIndex=logIndex.
@param wrotePos the wrote position(inclusive)
@param logIndex the log index
@param sync whether to call fsync
jraft-core/src/main/java/com/alipay/sofa/jraft/storage/log/SegmentFile.java