Skip to content

Fix LOGICAL_ERROR on UNDROP by UUID when dropped table's database changed engine - #121121

Merged
alexey-milovidov merged 11 commits into
ClickHouse:masterfrom
iliasabk:fix/undrop-uuid-source-database
Oct 30, 2026
Merged

alexey-milovidov merged 11 commits into
ClickHouse:masterfrom
iliasabk:fix/undrop-uuid-source-database

Conversation

@iliasabk

@iliasabk iliasabk commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

UNDROP TABLE db.t UUID '...' finds the dropped table by UUID alone, so the database named in the query can differ from the one the table was dropped from. DatabaseCatalog::undropTable checked the named database but resolved the metadata path through the original one. When the original database had been re-created with a non-DatabaseOnDisk engine (e.g. Memory), this threw LOGICAL_ERROR. UNDROP into a different database is now rejected with UNKNOWN_TABLE before any metadata is touched.

Closes: #121101

Changelog category (leave one):

  • Improvement

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

UNDROP TABLE ... UUID that names a database other than the one the table was dropped from now fails with UNKNOWN_TABLE instead of a LOGICAL_ERROR exception.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

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

Version info

  • Merged into: 26.11.1.947-master (included in 26.11 and later)

@CLAassistant

CLAassistant commented Sep 20, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@clickhouse-gh clickhouse-gh Bot added comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. external Author is not a member of the ClickHouse organization labels Sep 20, 2026
…a lambda

The thread-safety analysis does not see `tables_marked_dropped_mutex` held inside a
lambda that captures `this`, so reading the queue there fails the build with
`-Werror,-Wthread-safety-analysis`. Pass the queue into the lambda explicitly and
call it with the lock held, which the analysis does verify.
@iliasabk

Copy link
Copy Markdown
Contributor Author

Fixed the internal build failure: tables_marked_dropped is annotated TSA_GUARDED_BY(tables_marked_dropped_mutex), and the thread-safety analysis does not see that mutex held inside a lambda that captures this, so the search lambda failed with -Werror,-Wthread-safety-analysis. The queue is now passed into the lambda explicitly and the lambda is called with the lock held.

@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

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

One query was flagged: ClickBench Q23 improved by -45.7% (94 ms to 51 ms), and its CPU time also fell sharply. I downgraded it to not_sure because the PR only changes DatabaseCatalog::undropTable and adds a stateless test, and no benchmark SELECT executes that path. The drop in CPU time and the source median falling outside master's recent 90-100 ms range point to a difference between the source build and the base, not an effect of this PR. There are no regressions to act on.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 23 not_sure 94 51 -45.7% <0.0001 This PR only changes UNDROP TABLE handling in DatabaseCatalog, which a ClickBench SELECT never runs. The -45.7% change and the CPU drop more likely come from a build or base mismatch than from this diff.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 0d68eecf-0325-4a57-aa9e-ab93b0eee271
  • MIRAI run: a29d7ed7-d99a-4e39-b97e-2eade0ac1d0e
  • PR check IDs:
    • clickbench_2165058_1790571503
    • clickbench_2165071_1790571503
    • clickbench_2165077_1790571503
    • tpch_adapted_1_official_2165083_1790571503
    • tpch_adapted_1_official_2165114_1790571504
    • tpch_adapted_1_official_2165128_1790571504

@tuanpach tuanpach added the can be tested Allows running workflows for external contributors label Oct 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b9c6e2d]

Summary: ✅


AI Review

Summary

UNDROP TABLE ... UUID now rejects a database name that differs from the dropped table's recorded database before moving metadata or changing the dropped-table queue. The regression test covers rejection, a successful retry that preserves the data, and the original database recreated as Memory. Both previous inline findings are addressed in the current code; no actionable findings remain.

Final Verdict

Status: ✅ Approve. No required changes. The focused regression test passed in ARM stateless CI on 3818485270c7c1d2d5b0df6793c4b93ab927166c; broader CI for the current head is still running. Tests were not run locally.

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Oct 1, 2026
Comment thread src/Interpreters/DatabaseCatalog.cpp Resolved
Comment thread src/Interpreters/DatabaseCatalog.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b9c6e2dd3 with master 7aec1d41d (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 6ec1574f3; 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

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

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member

Not critical.

@alexey-milovidov

Copy link
Copy Markdown
Member

Not a bug fix.

@alexey-milovidov alexey-milovidov removed the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Oct 22, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

No need to backport.

@alexey-milovidov

Copy link
Copy Markdown
Member

The implementation is too complex. Just throw an exception that UNDROP can't be done.

@alexey-milovidov alexey-milovidov self-assigned this Oct 22, 2026
alexey-milovidov and others added 2 commits October 23, 2026 23:07
…t database

Address review: the previous fix restored the table into its original database and
re-resolved the queue entry across two critical sections, which is too complex.
Instead, `undropTable` now rejects the case when the dropped table's database differs
from the one named in the query, before touching metadata. This also covers the
`LOGICAL_ERROR` from ClickHouse#121101.

ClickHouse#121121 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Simplified as requested: undropTable is back to the master version, plus one check that throws UNKNOWN_TABLE when the dropped table's database differs from the one named in UNDROP ... UUID. Merged master; the test is updated accordingly.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 23, 2026

@alexey-milovidov alexey-milovidov 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.

Now perfect.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 The only red check, Upgrade check (amd_release) ("Changed settings are not reflected in the settings changes history": use_query_condition_cache_for_time_conditions 0 -> 1), is unrelated to this PR: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121121&sha=aa43771be7627feaa76f0db5f746aabb33a00d87&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29
It comes from master after 26.10 made the setting experimental (#127632). The fix is in progress in #127687. All review feedback here is addressed, and the PR is approved.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master to pick up the fix for the unrelated Upgrade check (amd_release) failure (#127687, now merged). No changes to the PR's own diff.

@alexey-milovidov alexey-milovidov removed the pr-bugfix Pull request with bugfix, not backported by default label Oct 26, 2026
@alexey-milovidov alexey-milovidov added the pr-improvement Pull request with some product improvements label Oct 26, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121121&sha=833601cd1a34aed4270c8c6e3f55464219fd1eaa&name_0=PR&name_1=Upgrade%20check%20(amd_release) and provide a fix in a separate PR. If the fix is already in progress, link it here.

The old released server (26.10.2) stopped accepting connections at the end of the stress phase, before the binary from this PR was installed. Every later Cannot ... left by the stress phase check failed with Connection refused. The same failure happened on 2026-10-25 in PRs #114008 and #101039. Separately, the upgraded server logs BAD_ARGUMENTS errors from StorageFileLog while loading the tables that 05318_file_log_one_bad_file left behind.

I merged master again. 05233_undrop_uuid_other_database passes locally on the merged tree. The PR's own diff is unchanged.

@groeneai

Copy link
Copy Markdown
Collaborator

This is the same failure as on #101039, and the fix is my #125706 (merged to master on 2026-10-17, not in 26.10). The mechanism is described here: #101039 (comment)

In this run (server log and dmesg.log times): at 06:59:13 two urlCluster secondary queries of 04035_url_cluster_callback_cancel_race get an injected Code: 241 that carries a Query pipeline: dump of about 52k log lines. The server's total memory goes from 11.03 GiB at 06:59:15 to 49.06 GiB at 06:59:23, and at 06:59:32 the cgroup OOM killer kills the 26.10.2.103 server (pid 3661, anon-rss:53682280kB).

The StorageFileLog errors are a consequence of that kill, not a separate bug. 05318_file_log_one_bad_file started on the old server at 06:59:17 and sent its last query at 06:59:29. On the upgraded server its directories under user_files are gone but four of its FileLog tables are still attached. The script leaves exactly that state when its DROP TABLE statements hit the dead server and its last line (rm -rf of those directories) still runs. file_log_skip, which the test creates after the other four, never got created and is not in the errors. In the last 30 days this is the only CI failure that mentions 05318 outside the PR that added the test.

So I have no new PR to send. The check stops failing this way once a 26.10 release contains #125706, which needs the v26.10-must-backport label on it (I can't set labels on this repo).

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, thanks for tracing the Upgrade check failure back to #125706. Whether to backport it to 26.10 (the v26.10-must-backport label) is for a maintainer to decide, so I'm leaving that to a human.

@groeneai, please investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121121&sha=4b7121bc4c7fa5a06e21101585dc36ae3695a776&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

05227_mutate_part_ahead_of_table_metadata_version_mergetree was added to master on 2026-10-26 by #120817. Here it printed the rewrite dropped the column: 1 where the reference expects 0: after ALTER TABLE ... DELETE ... SETTINGS mutations_sync = 2, the active part still contains the dropped column c. The test runs only clickhouse-local, and this PR changes only UNDROP TABLE handling, so the failure is unrelated. I could not reproduce it in 24 parallel local runs on current master. The PR branch is up to date with master.

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. I found no fix in progress for the 05227_mutate_part_ahead_of_table_metadata_version_mergetree failure. I'm investigating it and will follow up here with a PR (or my findings) shortly.

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is in #127925 (test only). DETACH PARTITION 1 covers the inserted part with an empty part 1_1_1_1 that still has c and stays on disk for old_parts_lifetime (480 s). Every later clickhouse-local process loads it as active, and after the DELETE startup clearEmptyParts skips it while the outdated 1_3_3_0 is loading (the guard from #98698), so it stays visible until the background rewrite of the pending mutations commits. If the system.parts_columns query runs first, it sees c.

The race did not reproduce for me either (0 of 4884 local runs), but forcing the query to run before the rewrite prints 1 in 20/20 runs without the change and 0 in 20/20 with it. The PR sets old_parts_lifetime = 0 on the test table; engine code is unchanged.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, thanks for #127925. Until it lands, the failure of 05227_mutate_part_ahead_of_table_metadata_version_mergetree stays unrelated to this PR. I merged master again; the PR's own diff is unchanged (DatabaseCatalog.cpp has not changed on master since the last merge).

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master to pick up the fix for the flaky 05227_mutate_part_ahead_of_table_metadata_version_mergetree (#127925, now merged). The PR's own diff is unchanged. The other red checks are unrelated: the Stress test (amd_tsan) data race in ClientEmbeddedRunner::clientRoutine is fixed by the open #127990, and Build profile diff failed in CI infrastructure (LogClusterNotReady).

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master to pick up the fix for the Fast test (arm_darwin) failure of 05397_clickhouse_local_locked_path_untouched (#128088, already merged). The PR's own diff is unchanged.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master. The only red check was CH Inc sync ("tests failed"). None of its failures are related to this PR, which only touches DatabaseCatalog::undropTable and adds 05233_undrop_uuid_other_database. The failures were 05339_hash_join_right_full_every_key_matched, 04077_lwd_replicated_flag, 03279_pr_3_way_joins_right_first_right, 600-second timeouts in 05296_json_shared_typed_paths_nested_types and 05298_json_shared_typed_paths_ranges under MSan, test_storage_iceberg_with_spark/test_compaction_file_size.py, and test_shared_merge_tree_lightweight_snapshot. The new commit re-runs the sync on current master. The PR's own diff is unchanged.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 30, 2026
Merged via the queue into ClickHouse:master with commit cc5af2c Oct 30, 2026
179 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. external Author is not a member of the ClickHouse organization 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.

UNDROP guard checks named db, not the queue entry's db: LOGICAL_ERROR survives

6 participants