Repository navigation
Add bounded retry to BigLakeCatalogManager.create_table - #109204
alexey-milovidov merged 7 commits into
Conversation
The e2e-catalog BigLake helper's create_table performs the REST create_table + table.append with no retry of its own. pyiceberg's REST client only retries auth errors (stop_after_attempt(2), reraise), so a single transient BigLake blip (5xx ServerError, ServiceUnavailableError, CommitStateUnknownException, connection reset) propagates out and fails the module-scoped types_table fixture, taking test_primitive_types[biglake] and test_primitive_values[biglake] down together. Wrap create+append in a bounded wall-clock retry loop, mirroring the existing wait_for_table_ready and resolve_table_name patterns in the same file. Only the specific transient REST/network exceptions are retried; every other error still propagates immediately. Each attempt uses a fresh table name and best-effort drops a partially-created attempt, so a retry after a partial success can neither hit TableAlreadyExistsError nor duplicate appended rows: table creation stays exactly-once and no assertion is weakened. After the deadline the last transient error is re-raised. Create-path analogue of the glue listing-race fix (ClickHouse#108604). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260702-172300 |
|
cc @fm4v — could you review? |
|
Workflow [PR], commit [628f554] Summary: ✅ AI ReviewSummaryThis PR hardens Missing context / blind spots
Final Verdict✅ No new blocking issues found in the current diff. |
…ttempt Review of the bounded-retry added to BigLakeCatalogManager.create_table raised two correctness issues; both are fixed here. 1. Auth-expiry errors were pointless to retry. self.catalog is a RestCatalog built once in __init__ with a static bearer token; _refresh_token_if_needed refreshes only the separate GoogleOAuth2Credentials object and never pushes the new token into the already-created catalog, so retrying an expired token just resends the same stale token until the deadline. Rebuilding self.catalog mid-retry is unsafe because callers share it concurrently (test_many_tables_pagination fans create_table across a 10-thread pool). AuthorizationExpiredError and OAuthError are therefore dropped from the retried set and left to propagate. 2. Named creates were non-idempotent. The fresh-name-per-attempt guarantee only holds for the auto-generated path; a caller-supplied table_name is identical on every retry, so a retry after a partial success (create OK, append threw) could resurface as TableAlreadyExistsError or duplicate rows. Named creates now make a single attempt and let a transient error propagate as before, preserving the exact-short-name contract that test_many_tables_pagination asserts against SHOW TABLES. The bounded retry stays on the auto-generated path (the shared types_table fixture this change targets), which is idempotent. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pre-PR validation gate for the review follow-up (commit 0f487b9). This is a test-helper resilience change; the E2E BigLake suite runs only in private CI with real GCS/BigLake credentials, so there is no public CIDB signal. Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-7:20260702-183100 |
After catalog.create_table commits, any later failure (append throwing a non-transient error, or a CommitStateUnknownException from create itself) previously left a live BigLake table behind: the auto-generated path only dropped inside the transient handler, and the explicit-name path had no handler at all. The leaked table was never tracked, so cleanup_all could not empty the session namespace and test_list_tables_pagination saw stragglers. Both branches now reconcile the partial attempt FIRST -- for every exception, transient or not -- and only then decide retry (transient, auto path) vs re-raise. _drop_failed_attempt drops the table if it can and otherwise records it in _tables_created, so a drop that cannot be confirmed (BigLake async-index lag makes a just-committed table briefly invisible) still gets reaped by the end-of-session sweep. No table is ever leaked untracked. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260702-190700 |
The prior drop-or-track path registered an async-index-lagged partial table in _tables_created so cleanup_all could reap it at teardown, but cleanup_all itself did a single best-effort drop_table per tracked name and then cleared _tables_created unconditionally. If the teardown drop also failed (still not indexed, or a transient blip), the name was cleared anyway and the table was leaked -- the same leak the tracking was meant to prevent, moved to teardown. cleanup_all now retries each tracked-table drop under a bounded wall-clock deadline and retains (never clears blindly) any name whose drop it could not confirm; the namespace drop + GCS prefix delete remain the storage backstop. A tracked table is forgotten ONLY on a confirmed drop_table return -- a raised drop (transient error, or NoSuchTableError, which does not prove removal under async-index lag) keeps the name for a later retry. cleanup_table now untracks a table on a confirmed drop so cleanup_all does not re-drop (and pointlessly retry) the already-removed tables that per-test cleanup already handled (e.g. test_list_tables_pagination's 60 named tables); a failed cleanup_table drop leaves the name tracked for cleanup_all to retry. Author: Groene AI <[email protected]> Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
No public CI/CIDB signal (E2E needs real BigLake/GCS creds). Control flow validated by the fake-catalog harness (ALL 24 PROOFS PASSED). ASCII only, no product code touched. Session id: cron:clickhouse-worker-slot-2:20260702-201000 |
The cleanup_all bounded-retry loop reran drop_table through the same statically-tokened self.catalog. _refresh_token_if_needed refreshes only the separate GoogleOAuth2Credentials, never the token baked into the catalog, so once the token expired every retry resent the same stale token: a long-running test_e2e_catalogs module would sit in teardown for the full 120s deadline and still leave the tracked tables behind. Mirror what create_table already does. Add a named _AUTH_EXPIRY_ERRORS set (AuthorizationExpiredError, OAuthError, UnauthorizedError -- the same set pyiceberg's own REST client retries-then-reraises) and: - _drop_confirmed re-raises auth-expiry instead of retaining-and-retrying. - cleanup_all catches it, stops the deadline loop immediately (no burn), keeps every tracked table (never cleared), still runs the GCS storage backstop (it builds a fresh gcsfs client from the refreshed credential, so it can still reap the data files), and propagates so the teardown failure is visible. Rebuilding self.catalog mid-retry was rejected in the create_table thread: callers share it concurrently (test_many_tables_pagination fans it across a 10-thread pool), so the consistent resolution is auth-expiry-non-retryable. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The _AUTH_EXPIRY_ERRORS contract (auth-expiry is non-retryable for the static-token RestCatalog: self.catalog cannot pick up a refreshed token) was applied to create_table and cleanup_all, but the two polling helpers still treated auth-expiry as transient: wait_for_table_ready (test_many_tables_pagination path): caught the auth-expiry from load_table/list_tables in its generic handler and slept to the 120s deadline, so a mid-module token expiry burned two minutes for nothing. wait_for_table_gone (test_table_disappears_after_cleanup path): caught the same in its generic handler and returned success as if the table had disappeared, a false-positive cleanup that masks a still-present table. Both now catch _AUTH_EXPIRY_ERRORS before the generic handler and re-raise immediately, matching create_table/cleanup_all. Genuine transient errors keep the bounded-retry behavior, and a genuine load failure in wait_for_table_gone still means the table is gone.
…pace wait_for_table_gone previously treated ANY load_table exception as proof the table was gone, so a transient 5xx / connection-reset (the class create_table retries) produced a false-positive cleanup on the test_table_disappears_after _cleanup path. Now only a genuine not-found (_TABLE_GONE_ERRORS = NoSuchTableError, NoSuchNamespaceError) confirms removal; a transient failure is retried under the deadline and surfaces as TimeoutError. cleanup_all's final drop_namespace ran through the static-token catalog with a bare except Exception: pass, swallowing auth expiry. When pending is empty (the common case, since cleanup_table untracks confirmed drops) or the token expires after the per-table loop, that was the only remaining catalog call and its auth failure was silently lost. It now applies the same _AUTH_EXPIRY_ERRORS contract as the loop: run the GCS storage backstop, then propagate. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Addressed the two review comments in 628f554 (2 changes, both in Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260702-225000 |
…-table-bounded-retry Add bounded retry to BigLakeCatalogManager.create_table
test_e2e_catalogs::test_list_tables_pagination creates 60 tables through a 10-worker pool and passed an explicit table_name= to BigLakeCatalogManager.create_table. That path is single-attempt by design: PR ClickHouse#109204 added a wall-clock bounded retry to create_table but deliberately carved the caller-supplied-name path out of it, because a same-name retry can resurface its own partial attempt as TableAlreadyExistsError, so exactly-once creation cannot be guaranteed there. That reasoning still holds. The defect is that this test was the only table_name= call site in the whole repo, so it made 60 un-retried live-catalog round-trips and failed whenever any single one blipped. It does not actually need fixed names: it asserts set membership of the names it created, whatever they are. So it now lets create_table generate them and builds `expected` from the returned values. Because every retry attempt uses a fresh unique name, exactly-once creation holds by construction, which is precisely the property the carve-out protects, and the fix therefore does not depend on _drop_failed_attempt being reliable (it is best-effort by its own docstring). The named branch is left in place and unchanged. After this change it has no in-repo caller, but it is public helper API whose single-attempt contract is still correct, so removing it would be an unrelated change. Separately, NoSuchNamespaceError was retried by neither path. Its MRO is [NoSuchNamespaceError, Exception, BaseException, object]: it is not a RESTError and not a requests.RequestException, so it fell outside _TRANSIENT_CREATE_ERRORS. BigLake indexes a just-created namespace asynchronously, so the session namespace can 404 for a few seconds after create_namespace. Adding it to that tuple is safe: _TRANSIENT_CREATE_ERRORS is consumed only by create_table, while the same class in _TABLE_GONE_ERRORS is consumed only by wait_for_table_gone, so its "proof a table is gone" meaning there is untouched. A namespace that is genuinely missing still fails with the same exception, just at the existing deadline instead of immediately. Validated by fault injection against the real functions, since a live run needs GCS/BigLake credentials and the e2e suite is excluded from public CI: with table_name= a transient error raises on attempt 1, and without it the same error is retried and succeeds; reverting either change reddens its own arm, while auth-expiry errors stay non-retryable. The three pagination assertions from PR ClickHouse#104531 are untouched and still fail when the listing is truncated at the page boundary, because detection rests on 60 tables exceeding one ~50-entry page rather than on name sort order (measured identical at 2000 trials per naming scheme). Auto-naming carries a 4.1e-07 collision probability per run, and a collision raises TableAlreadyExistsError, which is not transient and so fails loudly rather than silently. Also fixes two comments naming a caller test_many_tables_pagination that has never existed; the real caller is test_list_tables_pagination.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Fixes flaky
test_e2e_catalogs/test.py::test_primitive_types[biglake]andtest_primitive_values[biglake]. Both share the module-scopedtypes_tablefixture, so both fail together when the fixture's
create_tablecall fails.Root cause.
BigLakeCatalogManager.create_tableintests/integration/helpers/catalog_manager_biglake.pyperforms the RESTcatalog.create_table(...)+table.append(data)with no retry of its own.pyiceberg 0.11.1's REST client retries only auth errors
(
retry_if_exception_type((AuthorizationExpiredError, UnauthorizedError)),stop_after_attempt(2),reraise=True), so a single transient BigLake blip(
ServerError/ServiceUnavailableError/CommitStateUnknownException,or a connection reset) propagates straight out of
create_tableand errors theshared fixture. The same file already guards this class of BigLake transience
with bounded wall-clock retry loops in
wait_for_table_readyandresolve_table_name;create_tablewas the gap.Fix. Wrap create+append in a bounded wall-clock retry loop
(
deadline = time.monotonic() + timeout, default 120s), mirroring the existingwait_for_table_ready/resolve_table_namepattern. Only the specifictransient REST/network exceptions are retried; every other error (schema/config
bugs) still propagates immediately, so no real failure is masked. Each attempt
uses a fresh table name and best-effort drops a partially-created attempt, so a
retry after a partial success can neither resurface as
TableAlreadyExistsErrornor duplicate the appended rows — creation stays exactly-once and no assertion is
weakened. After the deadline the last transient error is re-raised (fail-fast).
This is the create-path analogue of the glue listing-race fix (#108604): same
e2e-catalog helper family, same "cloud catalog transient error" theme, distinct
code path (create vs list) and backend (BigLake REST vs AWS Glue).
Validation. This E2E suite requires real BigLake / GCS credentials and does
not run in public CI, so there is no public CIDB signal and no local end-to-end
repro. The change is a defensive bounded-retry that completes an
already-established, already-reviewed pattern in the same file (it does not touch
any ClickHouse product code and masks no product bug). The retry control flow was
validated deterministically with a fake catalog injecting transient errors,
confirming all three directions: (1) the pre-fix single-attempt path raises on the
first transient blip; (2) the new path retries through transient blips and
succeeds, appending the data exactly once with no orphan tables; (3) the new path
re-raises the transient error once the deadline passes.
No related open issue found on the public tracker (private-CI-only E2E suite).
Version info
26.7.1.798(included in26.7and later)