@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;
            }
            final int slot = (int) (logIndex - this.header.getFirstLogIndex());
            return truncateToSlot(slot);
        } finally {
            this.writeLock.unlock();
        }
    }
@Test
    public void testTruncate() {
        // Append 10 index entry
        for (int idx = 1; idx <= 10; idx++) {
            this.offsetIndex.appendIndex(idx, idx, segmentIndex);
        }

        // Check truncate to 9
        {
            this.offsetIndex.truncate(9, 0);
            assertEquals(8, this.offsetIndex.getLastLogIndex());
        }

        // Check truncate to 5
        {
            this.offsetIndex.truncate(5, 0);
            // Test recover
            this.offsetIndex.shutdown(1000);
            this.init();
            this.offsetIndex.recover();
            assertEquals(4, this.offsetIndex.getLastLogIndex());
        }
    }