Skip to content

Fix attach tables & total rows stats for data lakes - #117584

Merged
scanhex12 merged 17 commits into
masterfrom
fix_attach_detach
Sep 8, 2026
Merged

scanhex12 merged 17 commits into
masterfrom
fix_attach_detach

Conversation

@scanhex12

@scanhex12 scanhex12 commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix attach tables for data lakes. We don't need to read anything from object storage in attach query + don't provide rows stats in system tables


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

@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4b3598e]

Summary: ✅


AI Review

Summary

This PR defers data-lake metadata loading during ATTACH/startup and makes system.tables leave total_rows / total_bytes as NULL for direct data-lake rows so a plain listing does not probe object storage. The direction is correct, but two important contract gaps remain: wrappers/proxies around data-lake tables can still route system.tables back into object storage, and the broader lazy-init on ATTACH drops the eager user_files_path rejection for IcebergLocal / DeltaLakeLocal.

Findings

⚠️ Majors

  • [src/Storages/System/StorageSystemTables.cpp:647] and [src/Storages/System/StorageSystemTables.cpp:945] now decide whether to skip totals from the outer storage's isDataLake() flag only. That misses wrappers that forward totalRows / totalBytes but do not forward isDataLake() (StorageTableProxy, StorageAlias, StorageMerge, StorageBuffer). A concrete trace is StorageSystemTables -> StorageTableProxy::totalRows in [src/Storages/StorageTableProxy.h:170] -> nested StorageObjectStorage::totalRows in [src/Storages/ObjectStorage/StorageObjectStorage.cpp:582], which still calls configuration->update(...). So a loaded proxy/alias/merge over a dead Iceberg* / DeltaLake* table can still make SELECT total_rows, total_bytes FROM system.tables touch object storage and reintroduce the stall this PR is trying to eliminate. Suggested fix: compose the guard through delegating storages, or expose a dedicated capability that wrappers can aggregate, and cover at least lazy_load_tables=1 or Alias in a regression test.
  • [src/Storages/ObjectStorage/StorageObjectStorage.cpp:180] now treats every mode >= ATTACH as lazy-init. For IcebergLocal / DeltaLakeLocal, that skips the only eager local-path validation: StorageObjectStorageConfiguration::check still only validates the format in [src/Storages/ObjectStorage/StorageObjectStorageConfiguration.cpp:348], while the user_files_path guard lives in DataLakeConfiguration::assertLocalPathCorrect and is reached only from update, lazyInitializeIfNeeded, create, or prepareReadingFromFormat in [src/Storages/ObjectStorage/DataLakes/DataLakeConfiguration.h:111], [src/Storages/ObjectStorage/DataLakes/DataLakeConfiguration.h:130], [src/Storages/ObjectStorage/DataLakes/DataLakeConfiguration.h:158], and [src/Storages/ObjectStorage/DataLakes/DataLakeConfiguration.h:464]. As a result, ATTACH TABLE ... ENGINE = IcebergLocal('/tmp/outside') now succeeds and stores a table definition that the engine rejects only on first use instead of failing the DDL with PATH_ACCESS_DENIED. Suggested fix: keep the cheap local-path check eager on ATTACH for ObjectStorageType::Local data lakes before do_lazy_init short-circuits the update path, and add a focused regression test.
Tests
  • ⚠️ The new coverage proves the direct DeltaLake* / Iceberg* paths, but it does not exercise system.tables through a loaded StorageTableProxy / Alias, nor an ATTACH of IcebergLocal / DeltaLakeLocal outside user_files_path. Those two focused tests would close the remaining gaps above.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions:

  1. Make the system.tables no-I/O guarantee hold through wrapper/proxy storages as well as direct data-lake tables.
  2. Restore DDL-time rejection for forbidden local data-lake paths on ATTACH.

LLVM Coverage Report

Measured on commit 4b3598e.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.20% 81.20% +0.00%

Changed lines: Changed C/C++ lines covered: 30/32 (93.75%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 1, 2026
scanhex12 and others added 3 commits September 1, 2026 21:39
The test harness runs the script directly, so without the executable bit it
fails with `Permission denied` and return code 126.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The style check requires queries against `system.tables` to be constrained to a
database. Both tests attach into a `Memory` database named `d`, so filter on it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
&& (args.table_id.table_name.ends_with("_s3") || args.table_id.table_name.ends_with("_s3queue")))
configuration->force_anonymous_load_fallback = true;

const bool lazy_init = args.mode >= LoadingStrictnessLevel::ATTACH;

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.

ATTACH here still covers fresh user-supplied full definitions, not only metadata replay. For IcebergLocal / DeltaLakeLocal, the user_files_path guard is enforced in DataLakeConfiguration::update / lazyInitializeIfNeeded via assertLocalPathCorrect, and StorageObjectStorageConfiguration::check does not run that check. With lazy_init = true, ATTACH TABLE t (x UInt64) ENGINE = IcebergLocal('/tmp/outside') stops failing at DDL time and only gets rejected on first read.

Could we keep the local-path validation eager for fresh ATTACH queries, or restrict lazy init to replayed metadata / short-syntax ATTACH?

@clickhouse-gh

clickhouse-gh Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4b3598e3b with master 55c256363 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

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

Job report

`StorageObjectStorage::totalRows` and `totalBytes` skipped the storage only
when no metadata object had been created yet. For DeltaLake the metadata object
exists right after `ATTACH`, while the delta-kernel snapshot state is resolved
lazily, so scanning `system.tables` still built that state and read the table
metadata from the storage. When the storage was gone, every scan raised one
exception per table, which `StorageSystemTables` swallowed and logged, and
`05056_datalake_system_tables_does_not_read_storage` counted those log lines
and failed in every build.

Ask the metadata whether the table state is already resolved in memory
(`hasLoadedTableState`) instead of whether the metadata object exists.

`04762_datalake_concurrent_metadata_update` used a `system.tables` scan to
republish the metadata under `allow_experimental_delta_kernel_rs=1`; it now
runs `DESCRIBE TABLE` for that, because the scan no longer loads anything.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117584&sha=abcbf1f01ac5b34cc3f5b0741c9905cd674721b0&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29
Related: #117584

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@kssenii kssenii self-assigned this Sep 2, 2026
@scanhex12
scanhex12 marked this pull request as draft September 2, 2026 16:13
Comment thread src/Storages/IStorage.h Outdated
/// Whether `totalRows` and `totalBytes` are answered from memory, without reading the storage.
/// `system.tables` must never read the storage, so it reports unknown totals for the storages
/// that answer false here.
virtual bool hasCheapTotals() const { return true; }

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.

hasCheapTotals() is now the only guard that keeps system.tables off storage, but this default true leaks through delegating storages. StorageAlias::totalRows / totalBytes, StorageProxy::totalRows / totalBytes (and therefore StorageTableProxy), StorageMerge::totalRows / totalBytes, and StorageBuffer::totalRows all forward to child tables without overriding hasCheapTotals(). So SELECT total_rows FROM system.tables on a wrapper around DeltaLakeLocal / IcebergLocal can still reach StorageObjectStorage::totalRows() and do the remote configuration->update() that this PR is trying to avoid.

Could we make delegating / aggregate storages forward or compose hasCheapTotals() too, or default this flag to false and opt in only the storages whose totals are guaranteed memory-only?

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.

The current isDataLake() guard still misses wrapper rows.

StorageSystemTables now checks only the outer storage at src/Storages/System/StorageSystemTables.cpp:945, but StorageTableProxy, StorageAlias, StorageMerge, and StorageBuffer do not forward that classification. A concrete trace is:

  • StorageSystemTables calls table->totalRows(...) at src/Storages/System/StorageSystemTables.cpp:951 because the outer wrapper reports isDataLake() == false.
  • StorageTableProxy::totalRows then forwards to the nested table once it has already been materialized (src/Storages/StorageTableProxy.h:170-175).
  • For a nested Iceberg* / DeltaLake* table, that reaches StorageObjectStorage::totalRows, which still does configuration->update(...) before reading totals (src/Storages/ObjectStorage/StorageObjectStorage.cpp:582-595).

So SELECT total_rows, total_bytes FROM system.tables can still touch a dead data-lake backend through a loaded proxy/alias/merge/buffer table, which is the same no-storage-access contract gap as before.

The `StorageObjectStorage` constructor resolves the table state, and for a data lake that
means building the metadata: `DeltaLakeMetadataDeltaKernel` -> `S3KernelHelper` ->
`S3::Client::getRegionForBucket` -> `HeadBucket`. A connection error is retryable, and the
S3 client retries it 501 times with a delay growing to 5 s, so a single table whose bucket
had gone away held the constructor for tens of minutes. The same constructor runs for every
table the server attaches at start, which is what kept a service in "Starting" for 17 to 35
minutes.
ClickHouse/support-escalation#8579

A table attached from its metadata already knows its columns, so nothing has to be read to
attach it. Defer the resolution to the first use of the table, as the constructor already
does for the hive partitioning sample path.

Measured on a server holding one `DeltaLakeS3` table whose endpoint does not answer:
start to "Ready for connections" goes from tens of minutes to 93 ms, with no request sent
to the endpoint; reading the table still reports the failure.

The new integration test freezes the MinIO container and restarts the server: without this
change the server does not answer again and the test fails on a client timeout.

`05056` covers both halves of the guarantee now (nothing is read to attach the tables, and
nothing is read to list them in `system.tables`), so it is renamed after what it states.
The tests it replaces used the `*Local` engines, which never build an S3 client and so
never showed the retries.

Related: #117584

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@scanhex12
scanhex12 marked this pull request as ready for review September 3, 2026 14:08
scanhex12 and others added 2 commits September 3, 2026 14:18
`S3ReadRequestAttempts` and `S3WriteRequestAttempts` stay at zero even for a request that
is really sent, so the probe passed no matter what the attach did. `S3ReadRequestsCount`
and `S3ReadRequestsErrors` are the ones `PocoHTTPClient::makeRequestInternalImpl` raises,
before the request goes out and again when it fails, so a refused connection is counted
too; match every `S3*Request*` event to catch the write side as well.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@scanhex12 scanhex12 changed the title Fix attach tables for data lakes Fix attach tables & total rows stats for data lakes Sep 3, 2026
Comment thread src/Storages/IStorage.h Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 4, 2026
…emory`

Address review: `totalRows`/`totalBytes` already mean "cheaply known", so a new
virtual claiming every storage has totals in memory is misleading. `system.tables`
now simply skips the totals for data lake tables via the existing `isDataLake`.
Also rename `attaching_described_table` to `is_attach`.

#117584

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@scanhex12
scanhex12 requested a review from kssenii September 4, 2026 17:42
scanhex12 and others added 3 commits September 7, 2026 22:54
Review of #117584: the flag does not change between the columns of one row, so
read it before the loop that walks them.

The startup test is skipped when the database disk is remote. That job flavour
keeps the server's own metadata in the same MinIO the test pauses, so the server
cannot start for a reason that has nothing to do with the table: it retries
`http://minio1:9001/root-db-disk?...prefix=test-default|node1/__meta` until the
start times out.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`test_startup_with_unavailable_bucket` restarts the server with the table's
object storage paused. With `CLICKHOUSE_USE_DATABASE_DISK=1` the server keeps
its own database metadata on an S3 disk in the same MinIO
(`helpers/remote_database_disk.xml`, bucket `root-db-disk`), so pausing MinIO
stopped the start for a reason that has nothing to do with the table:

  S3 request to: http://minio1:9001/root-db-disk?list-type=2&max-keys=1&prefix=test-default%7Cnode1%2F__meta, aws sdk attempt: 3
  S3ClientRetryStrategy: Attempt 3/501 failed with retryable error: Timeout

Skipping that flavour would drop the test from half of the integration jobs.
The cluster already runs Azurite, and the database disk is always in MinIO, so
put the table in Azurite and pause `azurite1` instead - MinIO stays up and the
test behaves the same everywhere.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 39 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 93ad53e7-3649-46b9-a183-0f6bfbc94edb
  • MIRAI run: c829d033-bf13-41c7-b494-9373040f5296
  • PR check IDs:
    • clickbench_58534_1788892867
    • clickbench_58540_1788892867
    • clickbench_58546_1788892868
    • tpch_adapted_1_official_58557_1788892868
    • tpch_adapted_1_official_58570_1788892867
    • tpch_adapted_1_official_58604_1788892867

@scanhex12
scanhex12 added this pull request to the merge queue Sep 8, 2026
Merged via the queue into master with commit c0f1e15 Sep 8, 2026
175 checks passed
@scanhex12
scanhex12 deleted the fix_attach_detach branch September 8, 2026 21:46
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 8, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@scanhex12 @kssenii — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

@scanhex12 scanhex12 added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 18, 2026
scanhex12 added a commit that referenced this pull request Sep 18, 2026
Cherry pick #117584 to 26.6: Fix attach tables & total rows stats for data lakes
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 18, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 28, 2026
lazerg pushed a commit to lazerg/ClickHouse that referenced this pull request Nov 12, 2026
…tables

`system.tables` skipped `totalRows`/`totalBytes` of a data lake table with
a caller-side `isDataLake()` check (ClickHouse#117584). Engines that forward those
calls to another table (`Alias`, `Merge`, `Buffer`, materialized views,
`StorageTableProxy`, `StorageTableFunctionProxy`) keep the `IStorage`
default `isDataLake() == false`, so `system.tables` still reached
`StorageObjectStorage::totalRowsInSnapshot`/`totalBytes`, which refresh the
metadata from the object storage. On an unreachable bucket every
`system.tables` scan paid the S3 retry budget once per wrapper table.

`StorageObjectStorage` cannot tell that call apart from the ones that need
the refresh (trivial `count()` through a wrapper, `DROP TABLE ... IF EMPTY`),
so the caller's intent now travels on the argument every forwarder already
passes through unchanged: the `ContextPtr`. The context `system.tables`
reads totals with (the copy without sequential consistency, renamed
`totals_context`) sets a new `Context` field,
`totals_without_storage_access`. It is a field rather than a setting, like
`is_automatic_parallel_replicas_probe`, so no query can set it, and the
`ContextData` copy constructor keeps it. `StorageObjectStorage` and
`StorageObjectStorageCluster` return `nullopt` before touching the metadata
when it is set, and the `isDataLake()` checks in `StorageSystemTables` are
removed, so the storage that does the I/O decides for every wrapper.

Alternatives not taken: an explicit argument on `totalRows`/`totalBytes`
changes ~21 storage classes for the same semantics; overriding
`isDataLake()` in `StorageAlias`/`StorageMerge` misses the other wrappers
and changes the engine classification policy code reads.

Extends `05056` with an `Alias` + `Merge` over `IcebergS3` on a gone
endpoint: master sends 40 S3 requests (MinIO), the fix sends none.

Closes ClickHouse#118941

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

7 participants