Repository navigation
Refuse a second writable table_disk table on one disk root - #124298
Conversation
A table with `table_disk = true` keeps its parts and its root files (`format_version.txt`, `detached/`, `deduplication_logs/`, mutation entries) at the root of its disk, so two writable tables on one root overwrite and delete each other's data (issue ClickHouse#98512), and the stress test's AST fuzzer clones of such a table (`<name>__fuzz_N`, same disk) raced the original's `DROP` and left a metadata entry whose object was gone (`S3_ERROR` No such key on `__root/format_version.txt` in `Stress test (arm_release)`). CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124103&sha=60474c44812b8fadcb983207ab8e87a4a1af41f5&name_0=PR&name_1=Stress%20test%20%28arm_release%29 PR: ClickHouse#124103 A writable `table_disk` table now owns the root of its disk (storage endpoint + namespace + disk path; nested paths conflict) until the instance is destroyed; another writable table on that root is refused with `BAD_ARGUMENTS`. Read-only and write-once disks are not owners, so the one-writer/many-readers setup keeps working. The root is not released when `dropAllData` finishes: the rest of the drop (`dropReplica`, removing `store/<uuid>` and the metadata) can still throw and re-queue the table, and after a restart the dropped table is rebuilt from `metadata_dropped` before the other tables are loaded, so a released root could be taken by another table whose parts the retried drop would then delete. `DatabaseCatalog` destroys the dropped storage before it notifies the `DROP ... SYNC` waiters, so `DROP ... SYNC` followed by a `CREATE` on the same disk works; the new `database_catalog_drop_finally_after_notify` failpoint pauses the drop job right after that notification, so a test can check it. A table dropped or detached without `SYNC` keeps the root until its instance is gone, and the error says to retry after that (`SYNC` waits for it). An `ALTER` cannot change the disk or the storage policy of a `table_disk` table: the new disks would join the table without being owned, and `RESET SETTING disk` moved the table onto the `default` disk with the server's data directory as its data path, so a later `DROP TABLE` deleted that whole directory. The default database of `clickhouse-local` is a writable `Overlay` over an `Atomic` database, which keeps a detached table instance until no query uses it. `Overlay` did not forward `checkDetachedTableNotInUse` and `waitDetachedTableNotInUse`, so an `ATTACH` did not first destroy the unused detached instance and `DETACH ... SYNC` did not wait; with the ownership above that refused `DETACH TABLE t; ATTACH TABLE t`. Both are now forwarded to every member, as the server's `Atomic` database does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex) plus my own cold passes; rounds 1-6 (heads Round 7 (
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261006-183200 |
|
Workflow [PR], commit [e156982] Summary: ✅
AI ReviewSummaryThis PR closes the main corruption path behind Missing context / blind spots
Final Verdict
LLVM Coverage ReportMeasured on commit e156982.
Changed lines: Changed C/C++ lines covered: 72/75 (96.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes8 object files changed (+43.96 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units245 translation units recompiled, 2576 s compile time in total, 245 of them have a recent master baseline. |
|
@groeneai @alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Closes: #98512
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A writable disk with
table_disk = truenow holds the data of only one table: creating or attaching another table on the same path of the same storage, or on a path inside or above it, throwsBAD_ARGUMENTS; tables over a read-only disk on that path are still allowed. Previously such tables returned each other's rows, lost inserts and deleted each other's files. A table dropped or detached withoutSYNCkeeps its disk until its instance is gone. AnALTERcan no longer change the disk of such a table. If existing metadata has two such writers, the table loaded second fails to load: before upgrading, recreate all but one of them over a read-only disk. Closes #98512.Description
On 26.3.42.3 and 26.8.18.2, two tables with
table_disk = trueon one writableplain_rewritabledisk return each other's rows and lose inserts; with twocachedisks over ones3_plain_rewritabledisk (#98512) reading the first table fails withCANNOT_READ_ALL_DATA.Found as
S3_ERROR No such keyinStress test (arm_release)on #124103 (report): the AST fuzzer cloned the 05137 table asdedup__fuzz_Non the same disk, the original'sDROPdeleted__root/format_version.txtbetween a clone's blob write and its metadata commit.Change:
MergeTreeData: a writabletable_disktable owns its disk root until the instance is destroyed.ALTERcannot change the disk of atable_disktable: on master,RESET SETTING diskput it on the server's data directory, whichDROP TABLEthen deleted.DatabaseCatalog: a dropped table is destroyed beforeDROP ... SYNCreturns.DatabaseOverlay(clickhouse-local's default database) forwards the detached-table check and wait, soDETACH t; ATTACH tworks there.With
async_load_databases = 0, such existing metadata stops the server from starting.Not covered: a config reload that makes a read-only disk over an owned root writable. The reload skips the check
DiskSelectorruns at startup; I can add it to the reload if wanted.Validation: both new tests fail on master, pass with the fix; with the AST fuzzer on, 05137 left two
dedup__fuzz_Nwriters on master, none with the fix.Raw timed lines from the stress server log (clone `dedup__fuzz_4` = query 46b07e5e, the original's drop = thread 67164)
Workflow [PR]
Sync PR [sync-upstream/pr/124298]
Version info
26.11.1.114-master(included in26.11and later)