Skip to content

Enable bucket-region cache per catalogs - #113330

Merged
scanhex12 merged 2 commits into
masterfrom
enable_datalakes_cache
Aug 21, 2026
Merged

scanhex12 merged 2 commits into
masterfrom
enable_datalakes_cache

Conversation

@scanhex12

@scanhex12 scanhex12 commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

There is bucket-region cache in S3 Client. However, it didn't work for data lake catalogs. This PR fixes such behaviour


Workflow [PR]
Sync PR [sync-upstream/pr/113330]

Version info

  • Merged into: 26.8.1.1858 (included in 26.8 and later)

@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5ee19da]

Summary: ✅


AI Review

Summary

This PR makes ClientCacheRegistry keep S3 bucket caches alive across client instances so data lake catalogs can reuse detected bucket regions and redirect URIs. The idea is reasonable, but the current implementation shares the whole ClientCache across callers that do not share the same RemoteHostFilter, so a redirect URI accepted by a permissive internal client can later be replayed by a stricter user-facing client without being checked again.

Findings

❌ Blockers

  • [src/IO/S3/Client.h:93, src/IO/S3/Client.cpp:1064-1068, src/IO/S3/Client.cpp:1085-1089, src/Coordination/KeeperSnapshotManagerS3.cpp:117-120, src/Databases/DataLake/GlueCatalog.cpp:152-155] The new registry entry now owns the entire ClientCache, not just the bucket-region map. That cache also persists uri_for_bucket_cache, but redirect URIs are validated against RemoteHostFilter only when they are first learned. Once cached, later clients reuse getURIForBucket directly with no revalidation. Because the registry key is only (endpoint, bucket), a URI accepted under a permissive caller such as KeeperSnapshotManagerS3 can be reused later by stricter user-facing paths such as GlueCatalog or BACKUP/RESTORE, which breaks the host-filter boundary and can bypass the second caller's SSRF guard.
    Suggested fix: either keep only the region cache shared across client lifetimes, or partition/revalidate cached URI overrides with the current client's RemoteHostFilter before every reuse.
Tests
  • ⚠️ Add a focused regression test that creates two clients for the same (endpoint, bucket) with different RemoteHostFilter policies, stores a redirect URI through the permissive client, and verifies that the stricter client does not reuse it without validation. The current green CI does not cover this boundary.
Final Verdict

Status: ⚠️ Request changes
Minimum required actions:

  1. Stop sharing cached uri_for_bucket_cache entries across different host-filter policies, or revalidate them on reuse.
  2. Add focused regression coverage for that boundary.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.00% 87.00% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 16/24 (66.67%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 4, 2026
@scanhex12

Copy link
Copy Markdown
Member Author

Demo:

:) SELECT count() FROM icebench.`clickbench.hits`;

SELECT count()
FROM icebench.`clickbench.hits`

Query id: 15094344-b589-4ef3-a576-1a13d470c314

2026.08.04 13:38:28.018188 [ 876542 ] {15094344-b589-4ef3-a576-1a13d470c314} <Debug> IcebergMetadata: Latest metadata file path is *****, version 0
2026.08.04 13:38:28.018206 [ 876542 ] {15094344-b589-4ef3-a576-1a13d470c314} <Information> S3Client: Resolving region for bucket databricks-storage-***


:) SELECT count() FROM icebench.`clickbench.hits`;

SELECT count()
FROM icebench.`clickbench.hits`

Query id: ca9ecc7d-fa90-4b18-9f24-234a8698d13b

<NO Resolving region for bucket>

Comment thread src/IO/S3/Client.h
@@ -92,7 +92,7 @@ class ClientCacheRegistry
std::mutex clients_mutex;
UnorderedMapWithMemoryTracking<ClientCache *, std::pair<std::weak_ptr<ClientCache>, size_t>> client_caches TSA_GUARDED_BY(clients_mutex);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Persisting std::shared_ptr<ClientCache> here makes the whole ClientCache cross-client, not just the bucket-region map. ClientCache also carries uri_for_bucket_cache (src/IO/S3/Client.h:66-67), and those redirect URIs are only checked against remote_host_filter when they are first learned (src/IO/S3/Client.cpp:1065-1069 / src/IO/S3/PocoHTTPClient.cpp:681-685). Later clients reuse getURIForBucket directly (src/IO/S3/Client.cpp:1086-1090) with no revalidation.

That becomes a real boundary change because the registry key is only (endpoint, bucket), while different callers build clients with different host filters. For example KeeperSnapshotManagerS3 uses RemoteHostFilter() (src/Coordination/KeeperSnapshotManagerS3.cpp:117-120, which allows all hosts by default), while user-facing paths such as GlueCatalog use getContext()->getRemoteHostFilter() (src/Databases/DataLake/GlueCatalog.cpp:152-155). After this change, a redirect URI accepted under the permissive client can survive past its lifetime and be replayed later by the stricter client, bypassing the second client's host-filter check. Please either keep only the region cache alive across dead clients, or revalidate cached URI overrides against the current client's remote_host_filter before every reuse.

@Avogar Avogar self-assigned this Aug 14, 2026

@Avogar Avogar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Loogs good, just a few minor comments

Comment thread src/IO/S3/Client.cpp Resolved
Comment thread src/IO/S3/Client.cpp Resolved
Comment thread src/IO/S3/Client.cpp Resolved
Comment thread src/IO/S3/Client.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5ee19da63 with master ff4ddd319 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 957f7b7e2; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 704.41 MiB 701.39 MiB -3.02 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

64 translation units recompiled, 585 s compile time in total, 64 of them have a recent master baseline.

Job report

@scanhex12
scanhex12 enabled auto-merge August 21, 2026 12:57
@scanhex12
scanhex12 added this pull request to the merge queue Aug 21, 2026
Merged via the queue into master with commit d8bf9a0 Aug 21, 2026
177 checks passed
@scanhex12
scanhex12 deleted the enable_datalakes_cache branch August 21, 2026 14:43
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 21, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants