Repository navigation
Fix server startup after an interrupted CREATE OR REPLACE on a plain_rewritable database disk - #123832
Conversation
…at database load `CREATE OR REPLACE TABLE`, `REPLACE TABLE` and `CREATE TABLE ... AS SELECT` on an `Atomic` database fill a `_tmp_replace_<hash>_<suffix>` table, rename it to the target and, after an exchange, drop it. On a `plain_rewritable` database disk a file move is a copy of the object followed by a removal of the source, so a kill between the two leaves both metadata files. They carry one table UUID, and every later start of the server fails with `Mapping for table with UUID=... already exists ... (TABLE_ALREADY_EXISTS)` until the file is removed by hand. Since the `system.all_*` union tables are created by default, every fresh server runs several such statements at its first system log flush. The temporary table is only ever the source of these moves, so when its metadata file is a byte-identical copy of the destination of one of them, the move was interrupted after the copy. The destination is either `<T>.sql` of the same database, where `T` is the table whose name hash the temporary name carries, or the `metadata_dropped` file of the temporary table itself. `DatabaseOnDisk::iterateMetadataFiles` now removes such a source (or only skips it on a read-only disk) before parsing the metadata, which completes the move. Any other file is untouched: a temporary table without a copy still loads, and a copy under an unrelated name is still a UUID collision. The interrupted emulated `EXCHANGE` (`<file>_tmp_rename_exchange`) and user `RENAME`/`DROP` are not covered: the loader cannot tell their direction. 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; 1 finding; 1 full pass + 1 fix round + 1 delta recheck with 0 findings).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20261004-060100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261004-033200 |
|
Workflow [PR], commit [4b3a852] Summary: ✅
AI ReviewSummaryThis PR teaches Final Verdict
LLVM Coverage ReportMeasured on commit 4b3a852.
Changed lines: Changed C/C++ lines covered: 39/41 (95.12%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes3 object files changed (+33.58 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 units7 translation units recompiled, 14 s compile time in total, 7 of them have a recent master baseline. |
…e#123902 The arm was added by ClickHouse#123832, whose CI ran before ClickHouse#123902 was merged. ClickHouse#123902 makes `DatabaseOrdinary::loadTablesMetadata` remove a deferred `_tmp_replace_*` metadata file whose UUID matches any table of the database, whatever its name, and its test 05325 expects the server to start in that case. So a copy of the temporary table's metadata under an unrelated name (`u.sql`) is no longer a UUID collision: the server starts, and the arm's `start_clickhouse(expected_to_fail=True)` failed on every master run. The arm now expects the start with `t` and `u` (which keeps the data), the temporary file removed, and the message of the ClickHouse#123902 rule for this file. That message can only be logged if the copy rule of ClickHouse#123832 left the file alone, so the arm still checks that the copy rule only handles destinations of the temporary table's own moves. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The merge queue is meant to fail fast, so its targeted checks stop at 3 failed tests (`--max-failures 3` for `clickhouse-test`, `--maxfail` for pytest, with the sequential integration phase getting what remains of the limit and dropped once it is reached), do not rerun the failed integration tests, and stop at 20 minutes from their start, the budget of the merge-queue flaky check, instead of 30. Reaching the time limit stops the tests without failing the job, as before. The merge-queue flaky check keeps its 20-minute limit and 5 failures. The changed stateless tests and those `master` changed after the PR's last CI run run only in the merge-queue flaky check, which already reruns them since #126406; the targeted integration check reruns the integration test modules `master` changed. Related: #123832 Related: #125292
Related: #87656
Related: #117943
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the server failing to start with
TABLE_ALREADY_EXISTS(UUID collision) after it was killed duringCREATE OR REPLACE TABLE,REPLACE TABLEorCREATE TABLE ... AS SELECTin anAtomicdatabase whose metadata is on aplain_rewritabledisk.Description
On 26.8.10.6, a server whose
Atomicdatabase keeps its metadata on aplain_rewritabledisk (database_disk) cannot start after it is killed duringCREATE OR REPLACE TABLE: every start fails withCode: 57 ... UUID collision ... (TABLE_ALREADY_EXISTS). Since #117943 the server runs such statements itself for thesystem.all_*tables at its first log flush, which is how master CI hit it: Integration tests (amd_asan_ubsan, db disk, 8/8),test_dictionary_allow_read_expired_keys/test_dict_get.py::test_simple_dict_get.The statement renames its
_tmp_replace_*table to the target and, after an exchange, drops it. Onplain_rewritablea move copies the object and then removes the source, so a kill in between leaves two metadata files with the same UUID.DatabaseOnDisk::iterateMetadataFilesnow removes a_tmp_replace_*metadata file that is byte-identical to the destination of one of its own moves: the<table>.sqlwhose name hash the temporary name carries, or itsmetadata_droppedfile. This completes the move, next to the cleanup of this move's other leftovers from #88006. Any other file is left as is.Not covered: a kill inside the emulated
EXCHANGE(DiskObjectStorage::renameExchange, used when the target exists) leaves<file>_tmp_rename_exchange, and startup still fails withINCORRECT_FILE_NAME(measured): between its second and third move the other name is recorded nowhere. A userRENAMEorDROPleaves the same kind of copy, but the loader cannot tell which way it was going. @ tuanpach, should the exchange emulation record its counterpart so that it can be recovered at load?Tests:
test_database_diskkills the server at thecreate_or_replace_before_renamefailpoint and replays the copy step on the CI database disk. The publish and drop leftovers fail to start on master and on 26.8.10.6 and pass with the fix; a second publish case uses a target named like a temporary table. A copy under an unrelated name still fails. 10 of 10 module runs are green.Workflow [PR]
Sync PR [sync-upstream/pr/123832]
Version info
26.10.1.2161-master(included in26.10and later)