feat: add replicated parameter for ClickHouse connection - #835
Conversation
|
Thanks for the PR, @egorsavkin-plb. You said "modern Replicated table engine" but I think you meant "modern Replicated database engine" that you get when you create the database using You're absolutely right that in most situations, you won't use I spent some time testing the behaviour against a two node cluster on ClickHouse 22.8 (what our current CI pipeline tests against) and 26.8 (current LTS). Results were identical on both. A few things I'd like to discuss: In self-hosted ClickHouse, the
|
| Version | Error Code | Error Message |
|---|---|---|
| 22.8 | Code: 62 | Macro 'uuid' and empty arguments of ReplicatedMergeTree are supported only for ON CLUSTER queries with Atomic database engine. (SYNTAX_ERROR) |
| 26.8 | Code: 36 | Macro 'uuid' in engine arguments is only supported when the UUID is explicitly specified, used within an ON CLUSTER query, or when using the Replicated database engine. (BAD_ARGUMENTS) |
With ENGINE = Replicated(...) on the CREATE DATABASE it works exactly as you describe: the DDL propagates to every replica with no ON CLUSTER required and the migrations table appears on all of them, and rows replicate as intended.
How do you feel about checking the engine type of the database, e.g., using select engine from system.databases where name = ?, and making sure it's Replicated or Shared before proceeding with the replicated parameter behavior, and raising an error otherwise? I don't have a Cloud account to verify the Shared case, so if you're running there I'd welcome confirmation.
The zoo_path branch is not fail safe
The two branches behave in opposite ways on an Atomic database, which I don't think is intentional:
-
replicatedon its own emitsReplicatedReplacingMergeTree(ts)and fails loudly, as above. Cryptic, but safe. -
replicatedwithzoo_pathset emitsReplicatedReplacingMergeTree('<zoo_path>', '{replica}', ts), which is perfectly valid SQL withoutON CLUSTER. It succeeds, and creates the migrations table on exactly the one node dbmate connected to, and only that node. No error, and the migrations table now lives only on a single node of a cluster instead of being replicated across all nodes. Anything that later connects to a different node sees no migrations table.
I'd prefer this to be prevented in the code than only documented in a README, if possible. The same engine check mentioned above could be used to catch this.
dbmate can't create the database this feature needs
CreateDatabase issues a bare create database with no engine clause, which produces an Atomic (or Shared, in the case of ClickHouse Cloud) database. So dbmate cannot itself create a database that replicated will work against in a self-hosted setup. The user has to have pre-created it with ENGINE = Replicated(...). Worth stating explicitly in the docs, since dbmate create is otherwise expected to just work.
Smaller things
-
If
on_clusterandreplicatedare both present: the code takes theOnClusterbranch and silently ignoresreplicated. I'd make that an explicit error rather than a silent precedence rule. -
extractZookeeperPathtreatszoo_path=(present but empty) as unset, because it testszookeeperPath == ""rather thanv.Has(...). Probably fine, but worth making this clear by including a test case that shows this is the intended and expected behavior. -
Please remove the version bump in
version.go. Version bumps are handled as part of the release process.
One more thing ...
For anyone following #783: I checked, and the table's ZooKeeper path inside a Replicated database still comes from default_replica_path using the server macros, not from the database engine's own shard and replica arguments. On my test cluster it resolved to /clickhouse/tables/<uuid>/shard-01. So the {shard} concern discussed over in that issue applies here too, and this PR's no zoo_path branch inherits it.
…ne gate, mutual exclusion for on_cluster and replicated, readme
b76bed6 to
b0afe20
Compare
|
Thanks, @egorsavkin-plb, this addresses everything from the earlier review: the engine check now covers both the bare ... One thing I can't verify myself: I only have access to self-hosted ClickHouse, so I've only exercised the If that checks out (or if you haven't had a chance to test Cloud and that's fine too), this looks ready to merge from my side. |
|
@dossy Unfortunately I also don't have the access to CH Cloud, so couldn't verify this case... |
|
Going to merge this as it shouldn't break backwards-compatibility as it's new functionality, and if anyone who has ClickHouse Cloud tests this and finds it doesn't work right, they can open a new issue. |
This PR adds support for the modern Replicated table engine in the ClickHouse without the
ON CLUSTERclause, which is often incompatible with the replicated databases. Wired this asreplicatedconnection parameter and then reused zoo_path parameter.Previously to avoid the issues we would need to do this manually, which defeats the purpose of the dbmate: