Skip to content

DatabaseDataLake: Restore onelake_bearer_token, lazy init for internal create - #109724

Merged
alesapin merged 5 commits into
masterfrom
asya/restore_token
Jul 10, 2026
Merged

alesapin merged 5 commits into
masterfrom
asya/restore_token

Conversation

@asya-ch

@asya-ch asya-ch commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator

The parameter onelake_bearer_token was recently added (#109104) and reverted (#109597). The issue is that a node would try to create databases on startup, and if it encountered an expired token, would fail to start up. The fix is to use lazy initialization for internal creates.

I have manually verified on real instances that it fixes the issue.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Version info

  • Merged into: 26.7.1.754 (included in 26.7 and later)
  • Backported to: 26.6.2.159, 26.5.7.2

/*lazy_init=*/args.create_query.attach);
/// Internal creates (`RESTORE DATABASE`, shared catalog) shouldn't do network I/O.
/// We don't want an unreachable or unauthorized catalog to block replica startup.
/*lazy_init=*/args.create_query.attach || args.is_internal);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is the fix.

@clickhouse-gh

clickhouse-gh Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [119165f]

Summary: ✅


AI Review

Summary

This PR restores onelake_bearer_token support for DataLakeCatalog and makes internal OneLake database creation lazy so an expired token no longer blocks metadata loading. I did not find a new correctness issue in the implementation itself, but the PR still does not prove the reported startup regression is fixed: the new coverage only exercises fresh CREATE DATABASE and query/masking paths on a running server.

Tests
  • ⚠️ Add a focused regression for the contract in the PR description: create a persisted OneLake DataLakeCatalog, restart ClickHouse with an expired or invalid bearer token, and verify startup still succeeds. If lazy RESTORE DATABASE is also intended to be part of the contract, add the analogous restore case or document that restore is intentionally metadata-only and may leave an unusable catalog until credentials are rotated.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required action: add an in-repo regression test for the startup path this PR claims to fix.

@asya-ch
asya-ch force-pushed the asya/restore_token branch from 463c116 to 69b6274 Compare July 7, 2026 22:17
@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jul 7, 2026
@mintlify

mintlify Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ClickHouse-docs 🟢 Ready View Preview Jul 8, 2026, 3:35 AM


@only_onelake
def test_onelake_read_with_bearer_token(node, catalog_manager, sales_table):
"""Read table data authenticating only with onelake_bearer_token.

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 reported bug is the metadata-load path: a persisted OneLake DataLakeCatalog with a stale bearer token should no longer block ClickHouse startup. None of the new tests exercises that path, though: they all cover fresh CREATE DATABASE + query behavior on a running server.

Because the behavior switch is args.internal in DatabaseDataLake, this bug can regress without any of these tests failing. Please add a focused regression test that creates a OneLake catalog, restarts the node, and verifies startup succeeds. If restore is meant to be lazy too, add the analogous RESTORE DATABASE case as well.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have a test. Will add to the other repo once this PR is merged.

/// On ATTACH (server startup / user `ATTACH DATABASE`) or internal creates (restore),
// defer catalog construction to first use: building it can perform network I/O or credential validation
// that must not block startup. On CREATE build eagerly so misconfiguration (including a restricted
// server-credential catalog) is reported immediately.

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.

small point, looks like some lines are starting with "//" instead of "///"

@SmitaRKulkarni SmitaRKulkarni 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.

LGTM

@clickhouse-gh

clickhouse-gh Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.80% 85.80% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.90% 77.90% +0.00%

Changed lines: Changed C/C++ lines covered: 37/95 (38.95%) · Uncovered code

Full report · Diff report

@alesapin alesapin self-assigned this Jul 10, 2026
@alesapin
alesapin enabled auto-merge July 10, 2026 13:50
@alesapin
alesapin added this pull request to the merge queue Jul 10, 2026
Merged via the queue into master with commit 06136da Jul 10, 2026
175 checks passed
@alesapin
alesapin deleted the asya/restore_token branch July 10, 2026 14:08
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 10, 2026
larryluogit pushed a commit to ClibMouse/ClickHouse that referenced this pull request Jul 29, 2026
When catalog credentials expire (e.g. an expired `onelake_bearer_token`
for the OneLake catalog), a query to a table in a `DataLakeCatalog`
database failed with `UNKNOWN_TABLE` instead of the real authentication
error, and system tables like `system.iceberg_files` silently returned
an empty result.

`RestCatalog::tryGetTableMetadata` now treats only HTTP 404 as "table
does not exist" and propagates any other error (401/403 for expired or
invalid credentials, 5xx, ...). `DatabaseDataLake` table listing now
propagates catalog errors when `show_data_lake_catalogs_in_system_tables = 1`
instead of degrading to an empty listing.

Related: ClickHouse#109724

Co-Authored-By: Claude Fable 5 <[email protected]>
@alesapin alesapin added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Jul 30, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jul 30, 2026
asya-ch added a commit that referenced this pull request Aug 3, 2026
…for internal create

Resolve conflicts against 26.6:

- Keep `getBearerToken`; the `OneLakeCatalog::getAuthHeaders` user-agent
  override (#108117) is not in 26.6 and is unrelated to this fix.
- Drop `allow_server_credentials_in_user_queries` and
  `is_loading_from_existing_metadata` from the `DatabaseDataLake`
  constructor call; both come from #106855, which is not backported to
  26.6 and whose credential restriction is deliberately left out.
- Thread the existing `internal` flag from `InterpreterCreateQuery`
  through `DatabaseFactory` (the plumbing from 274f167, without the
  S3 credential restriction). Required by `lazy_init` for internal
  creates; both 26.6 call sites, `loadMetadata` and `RestorerFromBackup`,
  already set the flag.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
robot-clickhouse-ci-1 added a commit that referenced this pull request Aug 3, 2026
Cherry pick #109724 to 26.6: DatabaseDataLake: Restore onelake_bearer_token, lazy init for internal create
robot-clickhouse added a commit that referenced this pull request Aug 3, 2026
asya-ch added a commit that referenced this pull request Aug 4, 2026
Resolve cherry-pick conflicts for the 26.5 backport of
#109724

Kept: the `onelake_bearer_token` setting, its masking entry, the
`OneLakeCatalog` bearer-token auth path (adapted to 26.5, where
`access_token` is a `std::optional` rather than a `MultiVersion`), the
Azure `StaticCredential` read path, the CREATE-time check for exactly one
OneLake authentication method, docs and integration tests.

Dropped as inapplicable to 26.5:
- the `lazy_init` / `args.internal` change. 26.5 predates eager catalog
  initialization: `DatabaseDataLake` builds its catalog on first use in
  `getCatalog` for every path, including internal creates from
  `RESTORE DATABASE`, so there is nothing to defer.
- the `OneLakeCatalog::getAuthHeaders` user-agent override and the
  `Documentation` argument of `registerDatabase`, neither of which exists
  on 26.5. The bearer-token note is still delivered via
  `docs/en/engines/database-engines/datalake.md`.
- everything related to `s3_allow_server_credentials_in_user_queries` and
  `is_loading_from_existing_metadata`.
robot-clickhouse added a commit that referenced this pull request Aug 4, 2026
Cherry pick #109724 to 26.5: DatabaseDataLake: Restore onelake_bearer_token, lazy init for internal create
robot-clickhouse added a commit that referenced this pull request Aug 4, 2026
asya-ch added a commit that referenced this pull request Aug 4, 2026
Resolve conflicts for the 26.3 backport of #109724, keeping only the
`onelake_bearer_token` half.

- `RestCatalog.h`/`.cpp`: keep `getBearerToken` and the bearer-token branch of the
  `OneLakeCatalog` constructor; drop the `OneLakeCatalog::getAuthHeaders` override
  (from #108117, not backported). On 26.3 `access_token` is `std::optional<AccessToken>`,
  so assign it directly.
- `DatabaseDataLake.cpp`: drop the lazy-init half. 26.3 predates eager catalog
  initialization -- the constructor only calls `validateSettings` and `getCatalog` builds
  the catalog on first access, so every path is already lazy.
- Drop the e2e test changes: `tests/integration/test_e2e_catalogs/` and
  `tests/integration/helpers/catalog_manager_onelake.py` do not exist on 26.3.

The resulting C++ change is identical to the merged 26.5 resolution (137209f).
robot-ch-test-poll4 added a commit that referenced this pull request Aug 4, 2026
Cherry pick #109724 to 26.3: DatabaseDataLake: Restore onelake_bearer_token, lazy init for internal create
robot-clickhouse added a commit that referenced this pull request Aug 4, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 4, 2026
alesapin added a commit that referenced this pull request Aug 4, 2026
Backport #109724 to 26.5: DatabaseDataLake: Restore onelake_bearer_token, lazy init for internal create
asya-ch added a commit that referenced this pull request Aug 4, 2026
Backport #109724 to 26.6: DatabaseDataLake: Restore onelake_bearer_token, lazy init for internal create
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
DatabaseDataLake: Restore onelake_bearer_token, lazy init for internal create

This branch was successfully deployed

1 active deployment
staging - docs — 119165f5 Deployed Jul 10, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore 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-not-for-changelog This PR should not be mentioned in the changelog 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.

6 participants