@Override
  public double write(ByteBuffer buffer, boolean allowCompress) throws IOException {
    long startTime = System.nanoTime();
    // To support hot loading, we can't define it as a variable,
    // because we need to dynamically check whether wal compression is enabled
    // each time the buffer is serialized
    CompressionType compressionType =
        allowCompress
            ? IoTDBDescriptor.getInstance().getConfig().getWALCompressionAlgorithm()
            : CompressionType.UNCOMPRESSED;
    int bufferSize = buffer.position();
    if (bufferSize == 0) {
      return 1.0;
    }
    originalSize += bufferSize;
    buffer.flip();
    boolean compressed = false;
    int uncompressedSize = bufferSize;
    if (compressionType != CompressionType.UNCOMPRESSED
        /* Do not compress buffer that is less than min size */
        && bufferSize > MIN_COMPRESSION_SIZE
        && compressedByteBuffer != null) {
      compressedByteBuffer.clear();
      if (compressor.getType() != compressionType) {
        compressor = ICompressor.getCompressor(compressionType);
      }
      compressor.compress(buffer, compressedByteBuffer);
      buffer = compressedByteBuffer;
      bufferSize = buffer.position();
      buffer.flip();
      compressed = true;
    }
    /*
     Header structure:
     [CompressionType(1 byte)][dataBufferSize(4 bytes)][uncompressedSize(4 bytes)]
    */
    headerBuffer.clear();
    headerBuffer.put(
        compressed ? compressionType.serialize() : CompressionType.UNCOMPRESSED.serialize());
    headerBuffer.putInt(bufferSize);
    if (compressed) {
      headerBuffer.putInt(uncompressedSize);
      WritingMetrics.getInstance().recordCompressWALBufferCost(System.nanoTime() - startTime);
    }
    startTime = System.nanoTime();
    try {
      headerBuffer.flip();
      logChannel.write(headerBuffer);
      logChannel.write(buffer);
    } catch (ClosedChannelException e) {
      logger.warn("Cannot write to {}", logFile, e);
    }
    WritingMetrics.getInstance()
        .recordWroteWALBuffer(uncompressedSize, bufferSize, System.nanoTime() - startTime);

    return ((double) bufferSize / uncompressedSize);
  }
Minimum size to compress, use magic number 32 KB
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/io/LogWriter.java