@Override
    public ByteBuffer doCompaction() {
        Stopwatch stopwatch = Stopwatch.createStarted();
        ByteBuffer buffer;
        try {
            buffer = compactToNewFile();
            log.debug("IndexStoreFile do compaction, timestamp: {}, file size: {}, cost: {}ms",
                this.getTimestamp(), buffer.capacity(), stopwatch.elapsed(TimeUnit.MICROSECONDS));
        } catch (Exception e) {
            log.error("IndexStoreFile do compaction, timestamp: {}, cost: {}ms",
                this.getTimestamp(), stopwatch.elapsed(TimeUnit.MICROSECONDS), e);
            return null;
        }

        try {
            // Make sure there is no read request here
            fileReadWriteLock.writeLock().lock();
            fileStatus.set(IndexStatusEnum.SEALED);
        } catch (Exception e) {
            log.error("IndexStoreFile change file status to sealed error, timestamp={}", this.getTimestamp());
        } finally {
            fileReadWriteLock.writeLock().unlock();
        }
        return buffer;
    }
@Test
    public void doCompactionTest() {
        long timestamp = indexStoreFile.getTimestamp();
        for (int i = 0; i < 10; i++) {
            Assert.assertEquals(AppendResult.SUCCESS, indexStoreFile.putKey(
                TOPIC_NAME, TOPIC_ID, QUEUE_ID, KEY_SET, MESSAGE_OFFSET, MESSAGE_SIZE, timestamp));
        }

        ByteBuffer byteBuffer = indexStoreFile.doCompaction();
        FileSegment fileSegment = new PosixFileSegment(
            storeConfig, FileSegmentType.INDEX, filePath, 0L);
        fileSegment.append(byteBuffer, timestamp);
        fileSegment.commitAsync().join();
        Assert.assertEquals(byteBuffer.limit(), fileSegment.getSize());
        fileSegment.destroyFile();
    }