Repository navigation
Enable snappy compression in HTTP interface - #100752
Conversation
The server already recognized `Accept-Encoding: snappy` and set the `Content-Encoding` response header, but the write path threw "Unsupported compression method" when actually trying to compress. Replace the throw in `createWriteCompressedWrapper` with creating a `SnappyWriteBuffer`. Add the necessary `WriteBuffer *` constructor overload and change the `unique_ptr` constructor to take by reference so it works with the forwarding template. Closes #44885 Reimplements #96442 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Remove the fake fallback — require python3 snappy module and fail if it is not available. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [544ab0f] Summary: ✅
AI ReviewSummaryThis PR enables working HTTP Findings
Final VerdictStatus: |
Taking `unique_ptr &` silently steals ownership from the caller. Use the same pattern as other compression buffers (Zlib, Brotli, etc.): take `unique_ptr` by value and use `std::move` at the call site. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The previous implementation accumulated all data in memory and only compressed at finalize — OOM risk for large HTTP responses. Rewrite to use the snappy framing format (framing_format.txt): each `nextImpl` call emits independently compressed chunks (up to 64 KB each) with masked CRC-32C checksums. This bounds memory usage to the buffer size and enables streaming (first bytes sent before query completes). The framing format is the standard wire format for streaming snappy, used by python-snappy StreamCompressor/StreamDecompressor, Go's snappy.NewWriter/NewReader, etc. It does not affect Parquet or Hadoop snappy codepaths, which use raw snappy and HadoopSnappyReadBuffer respectively. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
HTTP response headers use CRLF line endings; grep output includes the \r character. Match the existing pattern in 00302_http_compression. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The error code was declared but never used after switching to `snappy::RawCompress`, which does not return a failure status. This was flagged by style CI. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Test 04061 was taken by keeper_client_watch_commands on master. Renumber to 04063. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Rename test from 04063 to 04065 to avoid number collision with `04063_in_subquery_lowcardinality_tuple_key` merged to master - Rewrite test to verify snappy framing format stream identifier bytes instead of requiring python3 `snappy` module (not available in CI) - Remove unused raw `WriteBuffer *` constructor from `SnappyWriteBuffer` to address review concern about dangling pointer safety Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Refactor `SnappyWriteBuffer` to inherit from `WriteBufferWithOwnMemoryDecorator` instead of manually managing the underlying buffer. This fixes the arm_tidy build failure (missing `WriteBuffer *` constructor) and provides safe `cancelImpl`/`finalizeImpl` via the decorator base class. - Add `SnappyFramedReadBuffer` that reads the snappy framing format, aligning the read and write paths for `CompressionMethod::Snappy`. Previously the write path used snappy framing format but the read path used `HadoopSnappyReadBuffer` (Hadoop snappy format), creating an asymmetric contract. - Fix the test to validate the full 10-byte snappy stream identifier instead of only the first 5 bytes. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Fix arm_tidy build failure: pass pointer (`&getOutputStream(response)`) instead of lvalue reference to `SnappyWriteBuffer` constructor in `PrometheusRequestHandler`, since `WriteBufferDecorator` only accepts `std::unique_ptr<WriteBuffer>` or `WriteBuffer *`. - Enforce the snappy framing format limit of 65536 bytes per chunk on `uncompressed_length` before allocating the decompress buffer, preventing untrusted input from forcing huge allocations. - Distinguish truly empty streams (clean EOF) from truncated stream identifiers in `readStreamIdentifier`: only return `false` on EOF before any bytes; throw `SNAPPY_UNCOMPRESS_FAILED` on partial reads. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…eus format - Fix `readExact` to distinguish partial reads (throw) from clean EOF at chunk boundaries (return false). Previously truncated chunk headers or payloads were silently accepted as EOF. - Add filename to all exception messages via `getExceptionEntryWithFileName` so errors include "While reading from: <path>" (fixes test `02724_decompress_filename_exception`). - Enforce the snappy framing format 65536-byte limit on uncompressed chunks, not only compressed chunks. - Keep Prometheus remote-read using raw snappy block compression (`snappy::Compress`) instead of the framing format written by `SnappyWriteBuffer`, preserving wire compatibility with Prometheus clients. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Merged
The remaining private-CI reds on the sync PR are repo-wide flakes unrelated to this change: Verified locally before pushing: incremental build clean; smoke test against the fresh binary — The two open review threads remain the known maintainer design decisions ( |
|
Continued work — merged the latest Build-verified: rebuilt the CI: the sole Review: the AI review's remaining non-dismissed Major is the read-side counterpart at |
…nary_filter_push_down` The setting was added by #106952 (merged into this branch on 07-13) and reverted on master by #110354, but the merge kept the history entry because it is adjacent to this PR's own `snappy_mode` entry. The orphan entry made every query with a `compatibility` setting fail with `UNKNOWN_SETTING`, which is what broke the Fast test on https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100752&sha=bee84f139ca122148eaa99904c0a6dca3733cbd3&name_0=PR&name_1=Fast%20test Co-Authored-By: Claude Fable 5 <[email protected]>
|
Continued work — fixed the red The Dropped the orphan entry, audited the rest of the 26.7 block (every branch-added history entry has a matching declaration; no duplicate keys), rebuilt, and smoke-tested the fresh binary:
The three unresolved review threads (framed-vs-basic default, and the coupled read/write |
|
Continued work — resolved the After this morning's Pushed |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 399/478 (83.47%) · Uncovered code |
…nse compression The master merge pulled in the snappy wire-format work (setting `snappy_mode`, PR #100752), which added a new `SnappyMode snappy_mode` parameter as the 5th argument of `wrapWriteBufferWithCompressionMethod`. This PR's own generic response-body compression path (the `compression` setting) in `HTTPHandler::processQuery` still used the old argument order, so its call no longer matched the signature (`no matching function for call to 'wrapWriteBufferWithCompressionMethod'`). Pass `settings[Setting::snappy_mode]` at the new position, matching the pattern used by the other generic write paths (`StorageFile`, `StorageURL`, `StorageObjectStorageSink`). Generic response-body compression is generic I/O, so it honors the user-tunable `snappy_mode` setting, unlike the HTTP `Content-Encoding: snappy` path which always uses the framing format.
The cluster INSERT path (distributedWriteIntoReplicatedMergeTreeOrDataLakeFromClusterStorage) sends the SELECT to a remote replica, which writes the part there and replicates via ZooKeeper. The INSERT pipeline returns to the client as soon as the remote query completes, before the LOCAL replica on the coordinator has fetched the part. If the test runs SELECT immediately after INSERT (timing under ~10ms on slow CI shards), the part is still PreActive locally and the SELECT returns 0 rows. The first INSERT in the test happened to pass because the SYSTEM FLUSH LOGS ON CLUSTER between INSERT and SELECT acted as an accidental barrier. The second INSERT lacked any synchronization, so it fails about 30% of the time on slower configs (arm_binary, ASan, MSan, db disk, llvm_coverage). Add explicit SYSTEM SYNC REPLICA after each INSERT to ensure the local replica has fetched any new parts before reading. Related: ClickHouse#100752 Signed-off-by: Groene AI <[email protected]>
|
Two things on this thread, one of which needs your attention. The three fixes described above as landed in So the asymmetry the last two replies resolve is still live on Happy to open a PR that cherry-picks The Keeper item from the top of this thread is moot. |
The `url()` sink advertised `Content-Encoding: snappy` on the HTTP request but honored the `snappy_mode` setting, so the default `snappy_mode = 'basic'` wrote the Hadoop snappy block format under the standardized HTTP `snappy` content-encoding. The read paths had the mirror bug: a response with `Content-Encoding: snappy` failed to decode under the default `basic` mode. For HTTP transfers, `Content-Encoding: snappy` always denotes the snappy framing format independently of `snappy_mode`, which now applies only when snappy compression is inferred from a file/URL path. Add the `chooseSnappyModeForHTTP` helper and use it in `StorageURLSink`, both `StorageURL` schema-inference read paths, the main `StorageURL` read path (via a new `snappy_mode` override in `FormatFactory::getInput`), and `HTTPDictionarySource` (which previously open-coded the same logic). The main read path forces reading the response headers first, because the request is delayed for a single URL and `Content-Encoding` would not yet be known. Add `04549_snappy_url_write_and_content_encoding` covering the write-side framing and the `Content-Encoding: snappy` read path, which were previously unchecked. Addresses review: ClickHouse#100752 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The new `snappy_mode` setting was defaulting to `framed`, which silently changed how generic `compression_method='snappy'` reads (e.g. `file()`, `url()`) decoded data — switching from the historical Hadoop block format to snappy framing. Default the setting to `basic` so existing Hadoop-snappy data keeps decoding the same way. The HTTP layer (`Content-Encoding: snappy`) is standardized on the framing format, so `HTTPHandler` now passes `SnappyMode::Framed` directly instead of reading the user setting. Add a `26.5` entry in `SettingsChangesHistory.cpp` so the new setting shows up in `system.settings_changes` and the `02995_new_settings_history` fast-test passes. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100752&sha=540ec30dfefcd2667462b2bd627c86bd21188ab2&name_0=PR PR: ClickHouse#100752 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`SnappyWriteBuffer::finalFlushBefore` only called `next`, which short-circuits in `nextImpl` when `offset() == 0`. As a result, an empty HTTP response body produced an empty byte stream rather than a valid (zero-data) snappy framed stream, which strict decoders can reject. Emit the stream identifier explicitly in `finalFlushBefore` when no data was buffered so the output is always a well-formed snappy framed stream. PR: ClickHouse#100752 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The snappy framing format used by `SnappyWriteBuffer`/`SnappyFramedReadBuffer`
needs `crc32c::Crc32c` for chunk checksums, but `ch_contrib::crc32c` was only
built when `ENABLE_GOOGLE_CLOUD_CPP` was on. That option is gated on
`(OS_LINUX OR OS_DARWIN OR OS_FREEBSD) AND (ARCH_AMD64 OR (ARCH_AARCH64 AND NOT NO_ARMV81_OR_HIGHER))`,
so on `arm_v80compat`, `ppc64le`, `riscv64`, `s390x`, `loongarch64` the
`target_link_libraries (clickhouse_common_io PUBLIC ch_contrib::snappy ch_contrib::crc32c)`
line failed cmake configuration with:
Target "clickhouse_common_io" links to: ch_contrib::crc32c
but the target was not found.
Move `add_contrib (crc32c-cmake crc32c)` out of the `ENABLE_GOOGLE_CLOUD_CPP`
block so the library is always built. Update `crc32c-cmake/CMakeLists.txt` to
pick a config header for every architecture: keep the existing AArch64+ARMv8.1+
and AMD64 paths, and add a portable little-endian config (`generic/`) for
ARMv8.0 compat / ppc64le / riscv64 / loongarch64 plus a big-endian one
(`generic_be/`) for s390x.
Build report (cmake configuration failures on cross-platform builds):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100752&sha=85b9d5f0e497043b5d1d1ecf66ec6c1614c0dbf0
PR: ClickHouse#100752
The existing test only validated the response-side encoder (`SnappyWriteBuffer` output via `Accept-Encoding: snappy`) and left the new framed reader (`SnappyFramedReadBuffer` / `Content-Encoding: snappy` request body) without coverage. Add a round-trip case: ask the server to encode a query string into framed snappy via `Accept-Encoding: snappy`, then POST the framed bytes back as the request body with `Content-Encoding: snappy`. The server must decode the body through `SnappyFramedReadBuffer` and execute the inner `SELECT 99`. PR: ClickHouse#100752
…FormatFactory::wrapReadBufferIfNeeded`
`StorageURL` does not wrap its raw HTTP `ReadBuffer` with the compression
method itself; it passes the raw buffer plus the compression method to
`FormatFactory::getInput`, which delegates to
`FormatFactory::wrapReadBufferIfNeeded`. That helper called
`wrapReadBufferWithCompressionMethod` without forwarding the
`snappy_mode` setting, so the default `SnappyMode::Basic` was always
used. As a result `url(...)` reading framed-snappy with
`SETTINGS snappy_mode = 'framed'` decoded with `HadoopSnappyReadBuffer`
and threw `SNAPPY_UNCOMPRESS_FAILED` ("hadoop snappy decode error:
INVALID_INPUT ... while reading header") on the framed stream
identifier.
Forward `settings[Setting::snappy_mode]` to
`wrapReadBufferWithCompressionMethod` so URL/object-storage read paths
that go through `FormatFactory::wrapReadBufferIfNeeded` honor the
setting like the file path does.
CI report: ClickHouse#100752
`ReadBuffer::next` recursively calls itself when `nextImpl` returns `true` with an empty `working_buffer`, so a crafted framed-snappy stream of empty chunks could drive the read path into unbounded recursion and exhaust the stack. Skip zero-length chunks at the source in both the compressed and uncompressed branches, and add `04266_snappy_empty_chunks` covering a stream of 100k empty uncompressed chunks followed by a real query payload. Addresses review feedback on ClickHouse#100752
In the gRPC `ExecuteQuery` external-table path, the decompression buffer was wrapped with `snappy_mode` read from the outer `query_context` before the external table's own `external_table.settings()` were applied to `external_table_context`. As a result, a per-table `settings['snappy_mode'] = 'framed'` (alongside `compression_type = 'snappy'`) was ignored, and the body was decoded with the outer/default `basic` (Hadoop block) mode. Move the `wrapReadBufferWithCompressionMethod` call after the per-table settings are applied and read `snappy_mode` from the resulting `settings`, so the per-table wire format is honored. This matches the code's evident intent (the same `external_table_context`/`settings` are already used to build the input format). Reported by the AI review on the internal sync of ClickHouse#100752
…tp-compression Enable snappy compression in HTTP interface
The server already recognized
Accept-Encoding: snappyand set theContent-Encodingresponse header, but the write path threw "Unsupported compression method" when actually trying to compress the response body.Replace the throw in
createWriteCompressedWrapperwith creating aSnappyWriteBuffer. Add the necessaryWriteBuffer *constructor overload and change theunique_ptrconstructor to take by reference so it works with the forwarding template.Closes #44885
Reimplements #96442
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Allow snappy compression in the HTTP interface (
Accept-Encoding: snappy) and add thesnappy_modesetting to choose the Hadoop snappy block format or the snappy framing format for genericfile/urlsnappy I/O.Documentation entry for user-facing changes
Note
Medium Risk
Touches core I/O compression wrappers and HTTP request/response handling, so regressions could impact data import/export paths across multiple storage backends. New snappy framing parser/writer adds additional parsing and checksum logic that must be correct for untrusted HTTP input.
Overview
Enables working
Accept-Encoding: snappy/Content-Encoding: snappyin the HTTP interface by implementing the standardized snappy framing format for both response compression and request-body decompression.Introduces a new
snappy_modesetting (basicvsframed) and threads it through generic compression wrapping sofile()/url()/object storage and dictionary HTTP sources can choose between legacy Hadoop snappy blocks and framed streaming; snappy writes are now supported only inframedmode.Adds new
SnappyFramedReadBufferand rewritesSnappyWriteBufferto emit framed streams with CRC32C checks, plus build/link changes to always build/linkcrc32c(including new generic/big-endian configs) and tests covering HTTP snappy framing and mode-mismatch failures.Reviewed by Cursor Bugbot for commit 8d27928. Bugbot is set up for automated code reviews on this repo. Configure here.
Version info
26.7.1.1063(included in26.7and later)