Repository navigation
Query Condition Cache: key object-storage entries by ETag - #109310
Conversation
The Query Condition Cache keyed object-storage files by their path only. For a general (non-data-lake) remote object that is not a stable identity: an object can be overwritten in place under the same path, after which the cache would serve stale row-group information and a query could return wrong results. Fold a content-version token into the key for non-data-lake objects: the ETag, which changes when the object is overwritten. A query after an overwrite then misses the cache and re-reads rather than reusing stale entries. S3, Azure, HDFS, local and web object storage all populate the ETag, so the cache keeps working for them. If no ETag is available the object is not cached (fail-close) rather than risking a stale hit. Data-lake data files (Iceberg, DeltaLake, Hudi) are immutable, so their path is a stable identity on its own; they keep using the path-only key, which also avoids disabling the cache for data lakes whose object metadata does not carry an ETag. The shared helper `QueryConditionCache::makeFilePartName(path, version_token)` composes the key (path and token separated by a NUL byte, which cannot occur in either). The same helper is used by the local-file path in `StorageFile`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [42c0c5d] Summary: ✅
AI ReviewSummaryThis PR fixes the obvious cross-query stale-hit case by folding object-storage PR Metadata
Findings❌ Blockers
Final VerdictStatus: Minimum required actions:
|
Add `test_query_condition_cache_overwrite_invalidation` to `test_storage_s3` that overwrites the same object in place between two `SELECT`s (via `s3_truncate_on_insert = 1`) and asserts the second query misses the old cache entry (`ProfileEvents['QueryConditionCacheMisses']`) and returns the new rows. This exercises the core correctness contract of keying object-storage entries by ETag: an in-place rewrite yields a new ETag and therefore a new cache key, so stale row-group information is not reused. Requested in review of #109310 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed the two AI-review findings:
|
| String identifier = object_info.getIdentifier(/*include_file_bucket_info=*/false); | ||
| if (is_data_lake) | ||
| return identifier; | ||
| const auto & metadata = object_info.getObjectMetadata(); |
There was a problem hiding this comment.
makeQueryConditionCacheKey is using whatever ObjectMetadata is already attached to the iterator entry, which on the normal listObjects path is the etag from the listing rather than a freshly validated generation token. That still leaves a wrong-result window on every backend whose later read is not pinned to the same etag: if the object is overwritten after LIST but before createReader, we hit the old path + etag cache entry here and then read the new bytes. S3 only avoids that while s3_validate_etag_on_read = 1; Azure, Local, Web (and S3 with validation disabled via compatibility) can still reuse stale row-group marks. To actually close the stale-hit bug, the cache lookup needs a fresh version token at this point or equivalent read-time generation validation for all supported backends.
There was a problem hiding this comment.
I'd keep this in the PR. The smallest safe scope is to make the Query Condition Cache fail-close anywhere the later read is not pinned to the same generation token used at lookup time; otherwise Azure, Local, and Web still retain the wrong-result window, and Web is in scope here because WebObjectStorage::getObjectMetadata can populate etag from the response headers. That closes the correctness gap without taking on the broader filesystem/page-cache follow-up in the same patch.
|
On the AI-review blocker for The observation is correct: the cache key uses the
Closing the residual window for every backend means either extending read-time The |
…he-object-storage-etag
|
The only failing check here — Integration tests (amd_asan_ubsan, flaky) — is unrelated to this change (Query Condition Cache keyed by object-storage Root cause: the integration flaky check runs the entire @groeneai, could you investigate the |
|
Confirmed, taking it in a separate PR (plus a tracking issue). One correction to the root cause: this is a write-side race plus the sequential-write slowness, not an S3 listing/pagination bug. From the failing flaky-check logs (gw0): only 514 of the 1001 Fix direction for the separate PR: replace the 30-thread sequential writer with a single server-side partitioned write ( |
|
Fix PR: #110167. Tracking issue: #110165. Rewrites the writer as batched server-side partitioned inserts (all 1001 objects, no client threads, no ~1000 round-trips); passes locally in ~33s (was ~10 min and failing 3/3), and the assertion is strengthened to verify every distinct file exists (sum(column1)=500500). |
…on-cache-object-storage-etag
…id flaky-check OOM/timeout The overwrite-invalidation test wrote a `numbers(1000)` Parquet object twice (once for `v1`, once for the `v2` in-place overwrite) with `output_format_parquet_row_group_size = 1`, i.e. 1000 row groups per write. That made it by far the slowest test in `test_storage_s3` (~283s). The integration flaky check runs the whole `test_storage_s3` module 3x concurrently (`pytest -n 3 --dist=each`) under ASan, and this test runs last, so under peak accumulated memory pressure its post-write `SELECT` hung and the `clickhouse` client was SIGKILLed (`Return code: -9`), turning into a job-level timeout. Reduce both inserts to `numbers(200)`. With `id < 100` this still produces 100 prunable row groups out of 200 (so `QueryConditionCacheMisses` and `QueryConditionCacheHits` remain non-zero and the ETag-invalidation assertions are unchanged), while making the test strictly lighter than the single-write `test_query_condition_cache` that passes reliably in the same job. CI report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/109310/aae9b291098f14ada806c8f84360d94c2287a99a/integration_tests_amd_asan_ubsan_flaky/ Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 38/38 (100.00%) · Uncovered code |
alexey-milovidov
left a comment
There was a problem hiding this comment.
This is good for me.
Add `test_query_condition_cache_overwrite_invalidation` to `test_storage_s3` that overwrites the same object in place between two `SELECT`s (via `s3_truncate_on_insert = 1`) and asserts the second query misses the old cache entry (`ProfileEvents['QueryConditionCacheMisses']`) and returns the new rows. This exercises the core correctness contract of keying object-storage entries by ETag: an in-place rewrite yields a new ETag and therefore a new cache key, so stale row-group information is not reused. Requested in review of ClickHouse#109310 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…cache-object-storage-etag Query Condition Cache: key object-storage entries by ETag
The Query Condition Cache keyed object-storage files by their path only (
ObjectInfo::getIdentifier). For a general (non-data-lake) remote object that is not a stable identity: an object can be overwritten in place under the same path, after which the cache would serve stale row-group information and a query could return wrong results.This folds a content-version token into the key for non-data-lake objects — the ETag, which changes when the object is overwritten. A query after an overwrite then misses the cache and re-reads instead of reusing stale entries.
S3,AzureBlobStorage, and local object storage populate the ETag, so the cache keeps working for them.HDFSobject metadata does not currently carry an ETag (HDFSObjectStorageleaves it empty), and web object storage does not support object metadata at all (WebObjectStorage::getObjectMetadatathrowsNOT_IMPLEMENTED), so non-data-lake objects on those backends are deliberately not cached (fail-close) — the same safe behaviour as any object without an ETag. TheHDFScase can be revisited if a stableHDFSversion token becomes available. If no ETag is available the object is not cached (fail-close) rather than risking a stale hit.Data-lake data files (Iceberg, DeltaLake, Hudi) are immutable, so their path is a stable identity on its own; they keep using the path-only key. This also avoids disabling the cache for data lakes whose object metadata does not carry an ETag.
The key is composed by a shared helper
QueryConditionCache::makeFilePartName(path, version_token)(path and token separated by a NUL byte, which cannot occur in either). The same helper is used by the local-file path inStorageFile.Notes:
ObjectIteratorSplitByBuckets(cluster split) read path keeps the path-only key. That is safe: path-only entries are now written only for immutable data-lake files, so a path-only read can only hit a correct data-lake entry; non-data-lake reads there simply miss.HEAD, matching how the filesystem cache and page cache already key object-storage reads. Closing the narrow window where an object is overwritten in place betweenLISTandGETwithin a single query requires read-time ETag validation (ass3_validate_etag_on_readalready provides forS3), which is orthogonal to this change.test_query_condition_cache.py(Iceberg over s3/azure/local). The new non-data-lake ETag behaviour (overwrite invalidation) is covered bytest_query_condition_cache_overwrite_invalidationintests/integration/test_storage_s3/test.py, which overwrites the same MinIO object in place and asserts the next query misses the stale entry and returns the new rows.Related: #102115
Related: #109247
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Key the Query Condition Cache for remote (object storage) Parquet files by ETag in addition to the path, so that overwriting an object in place no longer serves stale cached results.
Documentation entry for user-facing changes
Version info
26.7.1.874(included in26.7and later)