Skip to content

[client-v2] Fix compressed buffer size for incompressible request data - #3303

Merged
chernser merged 1 commit into
ClickHouse:mainfrom
dizider:fix/compressed-buffer-size
Nov 5, 2026
Merged

chernser merged 1 commit into
ClickHouse:mainfrom
dizider:fix/compressed-buffer-size

Conversation

@dizider

@dizider dizider commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

CompressedBlockOutputStream sized its output buffer as bufferSize + HEADER_LENGTH, so the compressor had no room for blocks that grow when compressed (e.g. random data). Since 0342bd9, this made LZ4 and ZSTD request compression fail with "maxDestLen is too small" / "Destination buffer is too small". The buffer is now sized with each codec's worst-case bound: LZ4Compressor.maxCompressedLength and Zstd.compressBound.

Added CompressedBlockOutputStreamTest, which round-trips full 64 KiB blocks of incompressible and compressible data through both codecs.

Closes #3302

Checklist


Note

Low Risk
Localized buffer sizing fix in client compression with new unit tests; public stream constructors are unchanged.

Overview
Fixes request compression failures when a full block does not shrink under LZ4/ZSTD (e.g. random payload data). CompressedBlockOutputStream previously allocated the destination buffer as large as the uncompressed block, which is too small when compression expands data and triggered errors like maxDestLen is too small / Destination buffer is too small.

The base constructor now takes a separate maxCompressedBufferSize, and LZ4 / ZSTD wrappers set it via LZ4Compressor.maxCompressedLength(bufferSize) and Zstd.compressBound(bufferSize) respectively. Uncompressed chunk size is unchanged.

Adds CompressedBlockOutputStreamTest with 64 KiB round-trip cases for both codecs on incompressible and compressible payloads.

Reviewed by Cursor Bugbot for commit 81ab6b1. Bugbot is set up for automated code reviews on this repo. Configure here.

@chernser

chernser commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Thank you for the fix!

Seems we need to port it to 0.11.1

@chernser
chernser merged commit 1ba32e3 into ClickHouse:main Nov 5, 2026
29 of 30 checks passed
chernser pushed a commit that referenced this pull request Nov 5, 2026
Add history/latest/3302.md for the compressed request buffer fix in #3303.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chernser added a commit that referenced this pull request Nov 5, 2026
Add changelog entry for #3302 (compressed request buffer fix, #3303)
@chernser chernser mentioned this pull request Nov 7, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants