Repository navigation
Allow attach as replicated for Ordinary databases - #118757
alexey-milovidov merged 34 commits into
Conversation
|
Workflow [PR], commit [e716f02] Summary: ✅
AI ReviewSummaryThis PR extends Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit e716f02.
Changed lines: Changed C/C++ lines covered: 191/211 (90.52%) · Uncovered code |
…nversion-ordinary
…Ordinary-database check The PR removed the query asserting that `ATTACH TABLE ... AS REPLICATED` is rejected for `Ordinary` databases, but the reference file still expected seven lines of output, so Fast test failed with "result differs with reference". CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118757&sha=bcaa82ad9544289b69b70f95bcbe6a23bcab4737&name_0=PR&name_1=Fast%20test PR: ClickHouse#118757 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes18 object files changed (+73.97 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 units85 translation units recompiled, 844 s compile time in total, 85 of them have a recent master baseline. |
…ses against a live detached storage `convertMergeTreeTableIfPossible` skipped the detached-table liveness check for `Ordinary` databases, because their tables have no UUID to key `checkDetachedTableNotInUse` by. But an `Ordinary` table can still carry `txn_version.txt` files after `RENAME TABLE` from an `Atomic` database, and `clearTransactionMetadata` must not delete them while the previous storage instance is alive: its parts check those files in `assertHasValidVersionMetadata` on destruction. `DatabaseOrdinary` now remembers detached storages by table name (weak references, so the tracking never extends their lifetime) and offers `checkDetachedTableByNameNotInUse` / `waitDetachedTableByNameNotInUse`, which the conversion uses for `Ordinary` databases the same way it uses the UUID-keyed guard for `Atomic`. A storage that was renamed after being detached no longer identifies as the table, so `RENAME TABLE` does not block a later re-attach. Test `05214_attach_as_replicated_ordinary_implicit_transaction` renames a table with parts written under implicit transactions from `Atomic` to `Ordinary`, detaches it, and converts it to replicated and back. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…nversion-ordinary
…ble in the liveness guard A plain `ATTACH TABLE` of an `Ordinary` table does not wait for the previous detached instance (there is no UUID to key the generic wait on), so `DETACH` -> `ATTACH` -> `DETACH` can leave two live detached instances with the same name. `insert_or_assign` dropped the older one, so `ATTACH ... AS REPLICATED` waited only for the newer instance and could still delete `txn_version.txt` under the parts of the older one. Track the instances in a multimap and wait until none of them is alive; expired entries are pruned on every detach and check. Test 05214 now re-attaches the table once before the conversion, so the guard sees two instances of the same name. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…eMergeTree.cpp` too
`replication.mdx` is the rendered form of the `Documentation{...}` block of `ReplicatedMergeTree`,
so the `convert_to_replicated` path for an `Ordinary` database and the one-time
`default_replica_path` expansion belong in the source text as well.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 The only red check on e6d93a0, Stress test (arm_release), is unrelated to this PR: the server failed to restart on |
…LE ... AS REPLICATED` statement docs The structured docs of the statement live in `ParserCreateQuery.cpp` and are rendered into `docs/reference/statements/attach.mdx`; they still described only the generic behavior. Say that `Atomic` and `Ordinary` databases are supported, that for `Ordinary` a UUID is generated and `default_replica_path` is expanded once, and that further replicas must reuse the resulting explicit path. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 @groeneai, the only red check on faa602f, Stress test (arm_asan_ubsan, s3), is unrelated to this PR: |
…onvert_to_replicated`
`checkReplicaPathExists` expanded `default_replica_path` on its own and asked
`getZooKeeper` (the default cluster) whether the path exists. A template that
addresses an auxiliary Keeper, `<name>:/clickhouse/tables/{uuid}/{shard}`,
therefore probed the wrong cluster with the prefixed string, so the restart
conversion failed there, while the table itself would later resolve the path
through `TableZnodeInfo` and use the right cluster. The conversion now reuses
the `TableZnodeInfo` that `checkReplicaPathIsSafe` already resolves, and asks
`getDefaultOrAuxiliaryZooKeeper(zookeeper_name)` about the raw path.
The new integration test `test_auxiliary_zookeeper.py` configures a chrooted
auxiliary Keeper as the `default_replica_path` target and checks, for both
`Atomic` and `Ordinary` databases, that the conversion lands in that cluster
(`system.replicas.zookeeper_name`, and the znodes under the chroot seen from
the default Keeper) and that a path already occupied only in the auxiliary
cluster makes the conversion refuse, with the prefixed path in the message.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…nversion-ordinary
…after unlocking the database mutex `DatabaseOrdinary::forgetExpiredDetachedTablesByName` locked every weak entry into a local `StoragePtr` while `DatabaseOrdinary::mutex` was held. If another thread released the last external owner during the iteration, that local pointer became the final owner and destroyed the detached storage under the database mutex, which `DatabaseAtomic::cleanupDetachedTables` deliberately avoids because such a destruction can deadlock. The sweep now hands every strong reference to a `keep_alive` container that the callers (`detachTable`, `checkDetachedTableByNameNotInUse`, `waitDetachedTableByNameNotInUse`) destroy only after the lock is released. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…dinary` table
Converting a table of an `Ordinary` database to `ReplicatedMergeTree` mints a UUID for the `{uuid}` macro of
`default_replica_path` and stores the fully expanded path as a literal, because the metadata of such a table
has no place for a UUID. On reload `TableZnodeInfo::resolve` saw no `{uuid}` macro, left `path_prefix_for_drop`
equal to the replica path, and `DROP TABLE` kept the emptied `/clickhouse/tables/<uuid>` parent znode, unlike
the same conversion in an `Atomic` database.
The literal path is the only record of that UUID, so `resolve` now recovers the owned prefix from it for
tables without a UUID of their own: the prefix ends with the last path component that is a UUID. Only
znodes that became empty are removed, as before. Test `05218_attach_as_replicated_ordinary_drop_znode`
converts, restores, reloads and drops such a table and checks the parent znode is gone.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 @groeneai, the only red check on e261595, Stress test (arm_tsan), is unrelated to this PR: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118757&sha=e26159554835816190f768f5e176d644fe6be3b1&name_0=PR&name_1=Stress%20test%20(arm_tsan) — |
…nversion-ordinary Conflicts with the new `table_readonly` refusal in `convertMergeTreeToReplicatedIfNeeded` and `convertMergeTreeTableIfPossible`: kept master's check first (before any temporary UUID is assigned for an `Ordinary` database), then this PR's `Ordinary` handling.
|
🕵 Merged |
…cument `{uuid}` in `default_replica_name`
The startup route `DatabaseOrdinary::convertMergeTreeToReplicatedIfNeeded` is a separate entrypoint from
`ATTACH TABLE ... AS REPLICATED`, so the name-in-path refusal and the `{uuid}`-in-`default_replica_name`
refusal get their own restart tests next to the existing two-UUIDs one, sharing a helper.
The `convert_to_replicated` docs now say that `{uuid}` in `default_replica_name` is not supported for any
conversion, as the `ATTACH` statement docs do.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 Pushed f9b5f26, which addresses both AI-review items: restart-path ( |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118757&sha=f9b5f26215e325b766cc74ad3b227e24f710c2e6&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%202%2F6%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.
|
|
The fix in progress is #122728 (approved, CI finished green).
|
…nversion-ordinary
|
🕵 Thanks @groeneai, and thanks for the correction: |
…`Ordinary` table
Address review: a conversion of a table of an `Ordinary` database to a
replicated engine expanded `default_replica_path` once but stored
`default_replica_name` verbatim. With a name such as
`{database}_{table}_{replica}`, the metadata kept `{database}` / `{table}`,
so on every later load `TableZnodeInfo::resolve` set `DO_NOT_ALLOW` and
`RENAME TABLE` of the converted table was refused.
Both conversion entrypoints (`ATTACH TABLE ... AS REPLICATED` and the
`convert_to_replicated` flag) now store `replica_name_for_metadata` from
the `TableZnodeInfo` that `checkReplicaPathIsSafe` already resolves, the
same way `CREATE TABLE` unfolds those macros; `{replica}` and other
macros stay unexpanded. Integration tests cover both entrypoints with a
rename and a re-attach.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Acknowledged. I found no fix in progress for either failure. I am investigating both ( |
|
|
|
…id_shaped_template`
`SHOW CREATE TABLE` is returned in `TSV`, which escapes the quotes around the engine arguments,
so the expected `'..._{replica}'` never matched. Read `engine_full` in `TSVRaw` instead.
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118757&sha=cd33c81af87c3446b2ad7981f19dec088d04c71b&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20targeted%29
ClickHouse#118757
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…onverted `Ordinary` table The owned prefix of a converted `Ordinary` table is recovered by matching its literal path against the current `default_replica_path`. When the template changes later, the match fails and the table owns only its own znode again: it keeps loading, and `DROP TABLE` leaves the minted UUID-named parent behind instead of removing anything it may not own. Document this and add a restart-after-config-change regression test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged
All 15 tests in |
…ries under test 05241_external_distinct_coalescing set max_memory_usage = 128 MiB for the whole session, so the limit also applied to the final system.query_log check. With the randomized use_uncompressed_cache = 1, that check is charged for every block it decompresses into the uncompressed cache (CachedCompressedReadBuffer::nextImpl allocates the cache cell under the query's memory tracker), and in a parallel run the granules around the four matching rows hold the ProfileEvents of many other tests. The check then failed with MEMORY_LIMIT_EXCEEDED while the queries under test were fine (Stateless tests (amd_debug, parallel) on ClickHouse#118757). Move the limit into the SETTINGS of the four queries under test, so the check runs with the job's normal limits. 05242_external_distinct_limit_remerge has the same construction (512 MiB) and gets the same change. The queries under test keep the same limit; the references are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
It is allowed to convert MergeTree tables in Ordinary databases to ReplicatedMergeTree with
ATTACH TABLE ... AS REPLICATEDorconvert_to_replicatedflag.Workflow [PR]
Sync PR [sync-upstream/pr/118757]
Version info
26.10.1.1307-master(included in26.10and later)