uptrace / go-clickhouse

Golang ClickHouse client
https://clickhouse.uptrace.dev
BSD 2-Clause "Simplified" License
258 stars 27 forks source link

Migration on multiple node #72

Open AndreiCrimezniuc opened 1 year ago

AndreiCrimezniuc commented 1 year ago

Is there way to run migrations on multiple nodes? If not it would be nice to see this feature. My situation. 2 servers with two nodes in cluster. When I run all migrations to one node and then all migrations to another I face conflict like "ch is claiming " ERROR DB::Exception: Table columns structure in ZooKeeper is different from local table structure. Local columns:" because I had 10 column in tables, then added two more and all this in one node. But when I'm trying to do the same on second node it shows that Zookeeper already 'booked' this tables as 12-columns. So it needs something like - run one sql on frist node and then on second one, and then all query the same way

vmihailenco commented 1 year ago

You are probably looking for ON CLUSTER mycluster:

ALTER TABLE mytable ON CLUSTER mycluster
ADD COLUMN ...
AndreiCrimezniuc commented 1 year ago

This not gonna work. It really add alter table on all cluster, but when it runs old migrations for second nodes it shows error like "Dude, you trying to run sql for this table on second node, but you trying select field that doesn't exist because you deleted it in migrations on first node"

AndreiCrimezniuc commented 1 year ago

So for consistency it needs to make in step by step for every node

vmihailenco commented 1 year ago

You only need to run the migration once on a random node in the cluster.

AndreiCrimezniuc commented 1 year ago

I can't run migrations like INSERT ON CLUSTER. So the only one way is to be able run migrations one by one, not all. Trying to do it with you lib. It's good that most of you methods are public. We it would be nice not to invent wheel