镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[client-v2] Insert fails when request compression is enabled and data is incompressible #3302

Closed

Description

@dizider

Description

The issue was introduced in 0342bd9, when output buffer size calculation changed. Since that revision, CompressedBlockOutputStream limits the compressor's output to the input buffer size. When the data is incompressible (e.g. random bytes), compressed block can be larger than the input, so compression fails. Before that change, ClickHouseLZ4OutputStream sized the buffer with maxCompressedLength, which accounts for this.

Both codecs are affected: ZSTD throws ZstdException: Destination buffer is too small, LZ4 throws LZ4Exception: maxDestLen is too small.

The fix needs an equivalent bound for each codec: LZ4Compressor.maxCompressedLength and Zstd.compressBound.

Steps to reproduce

  1. Enable request compression (compressClientRequest(true)).
  2. Insert data containing a 64 KiB block that does not compress (e.g. random bytes).
  3. The compressed block is larger than the input, so flush() throws before the request is sent.

Error Log or Exception StackTrace

Caused by: com.github.luben.zstd.ZstdException: Destination buffer is too small
	at com.github.luben.zstd.ZstdCompressCtx.compressByteArray(ZstdCompressCtx.java:905) ~[zstd-jni-1.5.7-23-cloud.jar:1.5.7-23]
	at com.github.luben.zstd.Zstd.compressByteArray(Zstd.java:134) ~[zstd-jni-1.5.7-23-cloud.jar:1.5.7-23]
	at com.github.luben.zstd.Zstd.compressByteArray(Zstd.java:158) ~[zstd-jni-1.5.7-23-cloud.jar:1.5.7-23]
	at com.clickhouse.client.api.internal.CompressedBlockOutputStream$ZSTDOutputStream.compressData(CompressedBlockOutputStream.java:145) ~[client-v2-0.11.0.jar:client-v2 0.11.0 (revision: c1834d0)]
	at com.clickhouse.client.api.internal.CompressedBlockOutputStream.flush(CompressedBlockOutputStream.java:81) ~[client-v2-0.11.0.jar:client-v2 0.11.0 (revision: c1834d0)]
	at com.clickhouse.client.api.internal.CompressedBlockOutputStream.write(CompressedBlockOutputStream.java:66) ~[client-v2-0.11.0.jar:client-v2 0.11.0 (revision: c1834d0)]

Code Example

reproduction using the internal stream directly:

  byte[] data = new byte[CompressedBlockOutputStream.UNCOMPRESSED_BUFF_SIZE];                                                                           
  new Random(42).nextBytes(data);                                                                                                                       
  try (CompressedBlockOutputStream out =                                                                                                                
           new CompressedBlockOutputStream.ZSTDOutputStream(new ByteArrayOutputStream(),                                                                
                   CompressedBlockOutputStream.UNCOMPRESSED_BUFF_SIZE)) {                                                                               
      out.write(data);                                                                                                                                  
  }

Configuration

Client Configuration

compressClientRequest(true)

Environment

  • Client version: 0.11.0 (0.10.0 is fine)

Activity

  1. chernser commented on Nov 5, 2026

    @chernser
    Contributor

    @dizider

    Thank you for reporting!

  2. added this to the 0.12.0 milestone on Nov 5, 2026
  3. added 2 commits that reference this issue on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions