Repository navigation
Closed
Description
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
- Enable request compression (
compressClientRequest(true)). - Insert data containing a 64 KiB block that does not compress (e.g. random bytes).
- 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
chernser commentedon Nov 5, 2026
@dizider
Thank you for reporting!
Add changelog entry for #3302 (#3303)
Merge pull request #3305 from LjungeldTheHelper/docs/3302-changelog