private void loadNextSegmentV2() throws IOException {
    long position = channel.position();
    SegmentInfo segmentInfo = getNextSegmentInfo();
    try {
      if (segmentInfo.compressionType != CompressionType.UNCOMPRESSED) {
        // A compressed segment
        if (Objects.isNull(dataBuffer)
            || dataBuffer.capacity() < segmentInfo.uncompressedSize
            || dataBuffer.capacity() > segmentInfo.uncompressedSize * 2) {
          MmapUtil.clean(dataBuffer);
          dataBuffer = ByteBuffer.allocateDirect(segmentInfo.uncompressedSize);
        }
        dataBuffer.clear();

        if (Objects.isNull(compressedBuffer)
            || compressedBuffer.capacity() < segmentInfo.dataInDiskSize
            || compressedBuffer.capacity() > segmentInfo.dataInDiskSize * 2) {
          MmapUtil.clean(compressedBuffer);
          compressedBuffer = ByteBuffer.allocateDirect(segmentInfo.dataInDiskSize);
        }
        compressedBuffer.clear();
        // limit the buffer to prevent it from reading too much byte than expected
        compressedBuffer.limit(segmentInfo.dataInDiskSize);
        if (readWALBufferFromChannel(compressedBuffer) != segmentInfo.dataInDiskSize) {
          throw new IOException("Unexpected end of file");
        }
        compressedBuffer.flip();
        IUnCompressor unCompressor = IUnCompressor.getUnCompressor(segmentInfo.compressionType);
        uncompressWALBuffer(compressedBuffer, dataBuffer, unCompressor);
      } else {
        // An uncompressed segment
        if (Objects.isNull(dataBuffer)
            || dataBuffer.capacity() < segmentInfo.dataInDiskSize
            || dataBuffer.capacity() > segmentInfo.dataInDiskSize * 2) {
          MmapUtil.clean(dataBuffer);
          dataBuffer = ByteBuffer.allocateDirect(segmentInfo.dataInDiskSize);
        }
        dataBuffer.clear();
        // limit the buffer to prevent it from reading too much byte than expected
        dataBuffer.limit(segmentInfo.dataInDiskSize);

        if (readWALBufferFromChannel(dataBuffer) != segmentInfo.dataInDiskSize) {
          throw new IOException("Unexpected end of file");
        }
      }
    } catch (Exception e) {
      logger.error(
          "Unexpected error when loading a wal segment {} in {}@{}",
          segmentInfo,
          logFile,
          position,
          e);
      throw new IOException(e);
    }
    dataBuffer.flip();
  }
1 byte for whether enable compression, 4 byte for compressedSize
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/io/WALInputStream.java