@Override
    public int truncate(final long logIndex, final int pos) {
        this.writeLock.lock();
        try {
            if (logIndex < this.header.getFirstLogIndex() || logIndex > this.header.getLastLogIndex()) {
                return 0;
            }
            if (pos < 0) {
                return getWrotePosition();
            }
            updateAllPosition(pos);
            clear(getWrotePosition());
            this.header.setLastLogIndex(logIndex - 1);
            return pos;
        } finally {
            this.writeLock.unlock();
        }
    }
@Test
    public void testTruncate() {
        testAppendDataAndRead();
        int truncatePos = FileHeader.HEADER_SIZE + 38;
        this.segmentFile.truncate(1, truncatePos);

        // Recover
        this.segmentFile.shutdown(1000);
        this.init();
        this.segmentFile.recover();

        assertEquals(this.segmentFile.getLastLogIndex(), 0);
    }