Skip to content

Enable snappy compression in HTTP interface - #100752

Merged
alexey-milovidov merged 120 commits into
masterfrom
enable-snappy-http-compression
Jul 17, 2026
Merged

alexey-milovidov merged 120 commits into
masterfrom
enable-snappy-http-compression

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 25, 2026 •

Copy link
Copy Markdown
Member

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 the response body.

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

Changelog category (leave one):

  • Improvement

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 the snappy_mode setting to choose the Hadoop snappy block format or the snappy framing format for generic file/url snappy I/O.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

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: snappy in the HTTP interface by implementing the standardized snappy framing format for both response compression and request-body decompression.

Introduces a new snappy_mode setting (basic vs framed) and threads it through generic compression wrapping so file()/url()/object storage and dictionary HTTP sources can choose between legacy Hadoop snappy blocks and framed streaming; snappy writes are now supported only in framed mode.

Adds new SnappyFramedReadBuffer and rewrites SnappyWriteBuffer to emit framed streams with CRC32C checks, plus build/link changes to always build/link crc32c (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

  • Merged into: 26.7.1.1063 (included in 26.7 and later)

alexey-milovidov and others added 2 commits March 25, 2026 22:17
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]>
Comment thread src/IO/SnappyWriteBuffer.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [544ab0f]

Summary: ✅


AI Review

Summary

This PR enables working HTTP snappy, adds the snappy_mode setting, and splits snappy handling into explicit basic/framed readers and writers across the generic I/O paths. Most earlier compatibility and hardening issues were addressed, but StorageURL still conflates the HTTP Content-Encoding: snappy transport contract with the generic snappy_mode file-format knob, so I would still request changes.

Findings

⚠️ Majors

  • [src/Storages/StorageURL.cpp:718-730, 967-1020, 2620; src/Core/Settings.cpp:2403] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/100752#discussion_r3540291584 ; https://github.com/ClickHouse/ClickHouse/pull/100752#discussion_r3573870146] StorageURL still lets session snappy_mode = 'basic' choose Hadoop-block snappy while sending or consuming the HTTP header Content-Encoding: snappy. That violates the transport contract this PR now documents for HTTP: standards-compliant peers interpret snappy as the framing format, so the default basic mode can emit non-standard request bodies and reject valid framed responses unless the user knows to override an unrelated session setting. Suggested fix: separate HTTP transfer-encoding from file-format snappy in StorageURL the same way HTTPDictionarySource already does, by forcing SnappyMode::Framed whenever the HTTP request or response actually carries Content-Encoding: snappy and reserving snappy_mode for path/explicit file-format cases with no HTTP Content-Encoding header. The current 04212_snappy_url_compression coverage only exercises blob-style url() round-trips with no response header, so this HTTP-header interoperability gap is still unproven.
Final Verdict

Status: ⚠️ Request changes

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Mar 25, 2026
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]>
Comment thread src/IO/CompressionMethod.cpp Resolved
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]>
Comment thread src/IO/SnappyWriteBuffer.cpp Resolved
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]>
Comment thread src/IO/CompressionMethod.cpp Resolved
alexey-milovidov and others added 6 commits March 27, 2026 15:37
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]>
alexey-milovidov and others added 2 commits March 29, 2026 00:13
- 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]>
Comment thread src/IO/SnappyFramedReadBuffer.cpp Resolved
Comment thread src/IO/SnappyFramedReadBuffer.cpp Resolved
alexey-milovidov and others added 2 commits March 30, 2026 05:16
- 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]>
Comment thread src/Server/PrometheusRequestHandler.cpp Resolved
Comment thread src/IO/SnappyFramedReadBuffer.cpp Resolved
Comment thread src/IO/SnappyFramedReadBuffer.cpp Resolved
alexey-milovidov and others added 2 commits March 30, 2026 10:24
…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]>
Comment thread src/IO/CompressionMethod.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Merged master (343 commits, clean — no conflicts) and pushed a new head to un-stick the CH Inc sync status. Why a new head was required:

  • The red on the previous head (9584dcc1a75, "Failed. Needs manual intervention", stamped 2026-07-12 20:46 UTC) predates the manual conflict resolution in the sync branch and can never self-heal: the hourly IncrementalSync run explicitly skips PRs whose head already carries a status (Do not process upstream PR #100752 with existing status CH Inc sync).
  • The private CI completion check stamps its verdict onto the synced_upstream_commit recorded in the sync metadata — still the pre-re-merge commit 8d6cde8cdd32, which duly received tests failed at 12:56 UTC today — so even a green re-run could never reach the current head.
  • A fresh head carries no status, so the sync machinery re-processes the PR, records the new upstream commit, and stamps the right SHA.

The remaining private-CI reds on the sync PR are repo-wide flakes unrelated to this change: 00965_send_logs_level_concurrent_queries and 03151_unload_index_race (both reported across many unrelated private PRs today), and 03271_parts_update_leader_in_system_replicas (has a dedicated open flaky-test fix in the private repo). A re-run of the failed jobs earlier today reproduced them, confirming they are independent of this PR.

Verified locally before pushing: incremental build clean; smoke test against the fresh binary — Accept-Encoding: snappy sets Content-Encoding: snappy with the correct framing-format stream identifier (ff 06 00 00 sNaPpY), and a snappy-compressed request body round-trips (SELECT 42 → 42).

The two open review threads remain the known maintainer design decisions (snappy_mode default basic vs framed in SettingsChangesHistory.cpp; Content-Encoding vs snappy_mode in StorageURL.cpp, dismissed), which are also the sole subject of the AI review's outstanding finding.

Comment thread src/Storages/StorageURL.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Continued work — merged the latest master (834 commits, clean merge, no conflicts, no code change) to keep the branch current and to re-trigger CH Inc sync on a fresh public head (bee84f139ca): an existing sync status on a head is final, so only a new head gets re-processed.

Build-verified: rebuilt the clickhouse target incrementally (ccache-warm) — zero errors/warnings. Smoke-tested the fresh binary: Accept-Encoding: snappy returns Content-Encoding: snappy with a valid snappy framing stream (ff 06 00 00 sNaPpY stream identifier → uncompressed chunk with CRC-32C → payload). The snappy_mode settings-history entry is intact in the 26.7 block.

CI: the sole PR failure is test_replicated_database/test.py::test_replicated_table_structure_alter, the known master-wide flake tracked by #110036 (no snappy/HTTP/compression code involved); it should clear on retry on the fresh head.

Review: the AI review's remaining non-dismissed Major is the read-side counterpart at src/Storages/StorageURL.cpp:967/:971 (and recreateLastReadBuffer) — url() decodes HTTP responses via the session snappy_mode rather than the actual Content-Encoding header, unlike HTTPDictionarySource. This is the read-side mirror of the write-side Content-Encoding: snappy vs snappy_mode tension already analyzed in #100752 (comment): a clean fix must distinguish the HTTP transfer-encoding (always framed for Content-Encoding: snappy) from file-format snappy (governed by snappy_mode), and forcing framed on the HTTP path alone would break url() round-trips to a plain blob store that does not echo Content-Encoding. Both Majors are two sides of the same deferred design decision (the write side is already [dismissed by author]), so they remain the maintainer's call.

alexey-milovidov and others added 2 commits July 15, 2026 08:20
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Continued work — fixed the red Fast test and merged the latest master (~450 commits, clean merge).

The Fast test failure on bee84f13 was branch-local fallout from the master-side revert of the Parquet dictionary filter: #106952 (which this branch picked up in the 07-13 merge) was reverted on master by #110354, and the subsequent merge kept an orphan SettingsChangesHistory.cpp entry for input_format_parquet_dictionary_filter_push_down because it sits directly next to this PR's own snappy_mode entry (a clean 3-way merge, no conflict markers). With the entry referencing a no-longer-declared setting, every query using the compatibility setting failed with UNKNOWN_SETTING, which is exactly the set of 19 failures in the report (all *compatibility*-machinery tests): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100752&sha=bee84f139ca122148eaa99904c0a6dca3733cbd3&name_0=PR&name_1=Fast%20test

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:

  • SELECT value FROM system.settings WHERE name = 'optimize_and_compare_chain_max_hash_work' SETTINGS compatibility = '26.6' → 0 (the exact query that failed before, no UNKNOWN_SETTING);
  • Accept-Encoding: snappy → Content-Encoding: snappy with a valid framing stream (ff 06 00 00 sNaPpY identifier);
  • framed request body with Content-Encoding: snappy round-trips (SELECT 42 → 42).

The three unresolved review threads (framed-vs-basic default, and the coupled read/write Content-Encoding-vs-snappy_mode question in StorageURL) remain open design questions as discussed above.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Continued work — resolved the CH Inc sync failure on the current head (544ab0fc6af).

After this morning's master re-merge and push, the sync bot could not update the private sync branch (sync-upstream/pr/100752) to the new public head, because the branch carries earlier manual commits — the status reported "Failed. Needs manual intervention". I updated it manually with the usual two-step merge: private master first (clean), then the new public head 544ab0fc6af. The only conflicts were in three Jepsen test files (tests/jepsen.clickhouse/…), where recent public-side Jepsen fixes overlapped private-side Jepsen changes; resolved by keeping the private-specific parts (the longer JDBC timeouts and the SharedMergeTree set workload) and taking the public-side fixes (:compress false for the stale JDBC driver, plus the Keeper storage-disk comment). The merge brought zero C++ changes on top of the already-reconciled private branch (all Build jobs passed on the previous sync head), so no rebuild was needed.

Pushed 7e9dd4a0a48; the sync PR ClickHouse/clickhouse-private#53712 is MERGEABLE again and private CI is re-running, which will refresh the CH Inc sync status here. The public CI on 544ab0fc6af is still in flight; the two reds on the previous head were tracked flakes (#110574, #110036) unrelated to this PR.

@clickhouse-gh

clickhouse-gh Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.90% 86.00% +0.10%
Functions 92.70% 92.70% +0.00%
Branches 78.10% 78.10% +0.00%

Changed lines: Changed C/C++ lines covered: 399/478 (83.47%) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Jul 16, 2026
@alexey-milovidov
alexey-milovidov merged commit c3d70ac into master Jul 17, 2026
178 of 179 checks passed
@alexey-milovidov
alexey-milovidov deleted the enable-snappy-http-compression branch July 17, 2026 02:25
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 17, 2026
alexey-milovidov added a commit that referenced this pull request Jul 17, 2026
…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.
pull Bot pushed a commit to sowelswl/ClickHouse that referenced this pull request Aug 5, 2026
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]>
@groeneai

Copy link
Copy Markdown
Collaborator

Two things on this thread, one of which needs your attention.

The three fixes described above as landed in d5ed913d446 are not in master. That commit was authored at 03:45:59Z, about 80 minutes after this PR merged at 02:25:14Z (merge commit c3d70ac7). It is the current head of enable-snappy-http-compression, but compare/d5ed913d446...master reports behind_by=1, and the single missing commit is d5ed913d446 itself. Confirmed on the merged tree and on current master: chooseSnappyModeForHTTP has zero occurrences in src/IO/CompressionMethod.h, src/IO/CompressionMethod.cpp and src/Storages/StorageURL.cpp, and 04549_snappy_url_write_and_content_encoding is absent. A PR search for either name matches only this PR, so nothing landed it later.

So the asymmetry the last two replies resolve is still live on master: HTTPDictionarySource.cpp:94-96 forces SnappyMode::Framed when the HTTP compression method is set, while the StorageURL sink (:730) and both read paths (:971, :1020) still pass the unconditional session snappy_mode. Under the default basic a standards-compliant framed-snappy HTTP response is decoded with the Hadoop-block decoder.

Happy to open a PR that cherry-picks d5ed913d446 as is, preserving your authorship, if you want it landed unchanged. Say the word and I will also validate 04549 locally first.

The Keeper item from the top of this thread is moot. test_keeper_snapshot_rotation_race::test_deterministic_rotation_race was removed from master on 2026-06-15 by @ antonio2368 in #107321 (90a907a8d962, "Remove test_deterministic_rotation_race invalidated by the snapshot split"), as invalidated by the snapshot split; the file now only defines test_stable_recovery_under_write_load. Last failure anywhere was 2026-06-14 20:20:39, and every occurrence after the #106842 mitigation was on Keeper rework branches rather than master. The chassert(false) in read_logical_snp_obj still exists (KeeperStateMachine.cpp:1796, :1815) behind the reworked pin and loader logic, and nuraft_use_bg_thread_for_snapshot_io is still default false. Since the trigger test is gone and the Keeper owner declined the hardening, I am leaving #107141 closed rather than relanding it.

kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
`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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…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
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
`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
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…tp-compression

Enable snappy compression in HTTP interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Snappy is not supported in http interface

4 participants