Add drop replica alter support#10679
Conversation
|
It should not be possible to remove active replica this way, only stale/inactive. |
| */ | ||
| void drop() override; | ||
|
|
||
| /** Removes a specific replica from Zookeeper. If replica is local, it works same as `drop` method. |
There was a problem hiding this comment.
Other code and comments tell it is impossible to drop local replica. Incorrect comment?
There was a problem hiding this comment.
Yes. I will fix the comment, the local replica can only drop by DROP TABLE
| ALTER TABLE [db].name DROP REPLICA replica_name; | ||
| ``` | ||
|
|
||
| Queries will remove the replica path in zookeeper, it's useful when you want to decrease your replica factor. It will only drop the inactive replica, and it can't drop local replica, please use `DROP TABLE`. |
There was a problem hiding this comment.
What happens with data on that replica? It remains on remote server?
There was a problem hiding this comment.
Yes, it remains. We can't control that. The main reason we call DROP REPLICA is that we should enable remove the 'dead' replica.
|
BTW What's I'll look into the |
It's about a mirror of ClickHouse source code that is automatically created in bigger internal monorepository. You don't have to worry about this check. |
|
For somewhat reason, newly added integration test does not pass. |
|
Maybe it should be implemented as |
Good idea, I will consider it later. (Now I am just a little busy about work) |
Yes, I have implemented the way to replace the |
| Replicas can be dropped using following syntax: | ||
|
|
||
| ```sql | ||
| SYSTEM DROP REPLICA replica_name; |
| SYSTEM DROP REPLICA replica_name FROM TABLE database.table; | ||
| ``` | ||
|
|
||
| Queries will remove the replica path in zookeeper, it's useful when you want to decrease your replica factor. It will only drop the inactive/stale replica, and it can't drop local replica, please use `SYSTEM DROP REPLICA` for that. |
There was a problem hiding this comment.
If I understand correctly, it's useful to remove metadata of dead replica from ZooKeeper. The right way to decrease replication factor is DROP TABLE.
src/Parsers/ASTSystemQuery.cpp
Outdated
| }; | ||
|
|
||
| auto print_drop_replica = [&] { | ||
| settings.ostr << " " << (settings.hilite ? hilite_identifier : "") |
| else if (!query.database.empty()) | ||
| { | ||
| auto databases = DatabaseCatalog::instance().getDatabases(); | ||
| auto it = databases.find(query.database); |
There was a problem hiding this comment.
DatabaseCatalog::instance().getDatabase(query.database)
| { | ||
| storage_replicated->getStatus(status); | ||
|
|
||
| if (status.replica_path.compare(query.replica_zk_path + "/replicas/" + status.replica_name) == 0) |
There was a problem hiding this comment.
If local table with such replica_path exists and DROP TABLE should be used, then it's better to throw exception right here without call of StorageReplicatedMergeTree::dropReplica(...)
| LOG_INFO(log, "Removing replica {}", remote_replica_path); | ||
| /// It may left some garbage if replica_path subtree are concurently modified | ||
| auto zookeeper = context.getZooKeeper(); | ||
| zookeeper->tryRemoveRecursive(remote_replica_path); |
There was a problem hiding this comment.
We should check that replica is not active before removing it. Also we probably should remove it the same way as StorageReplicatedMergeTree::dropReplica(...) does. It can be done by extracting some part of StorageReplicatedMergeTree::dropReplica(...) to static method.
| throw Exception("Table was not dropped because ZooKeeper session has expired.", ErrorCodes::TABLE_WAS_NOT_DROPPED); | ||
|
|
||
| if (is_drop_table) | ||
| replica_is_active_node = nullptr; |
There was a problem hiding this comment.
Isn't it done in StorageReplicatedMergeTree::shutdown() which calls ReplicatedMergeTreeRestartingThread::partialShutdown()?
8b6a31e to
340b300
Compare
Fix style && build
Fix integration-tests
update doc Increase timeout to release the zookeeper Ephemeral nodes Fix code comment use PartitionManager make integrations test passed
fix test_drop_replica fix drop replica '/path/to/zk/' ending in '/' and update doc
fix removeReplicaByZKPath fix bug: add zkpath empty judge fix: rewrite code delete useless code. fix:ast fromat fix bug add test_drop_replica add drop_replica doc add drop databse checkAccess refactor dropReplica update tests add static method StorageReplicatedMergeTree::dropReplicaByZkPath update doc and delete useless code fix conflict fix doc fix doc fix StorageReplicatedMergeTree::dropReplica fix bug delete useless code
|
Thanks for adding this! |
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
Changelog category (leave one):
If the replicated table has 3 replicas, but one replica is crashed and never be back to normal again, we should enable to remove this replica by alter commands.
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Add
Alter table drop replica replica_namesupport. This fixes #7080.Detailed description / Documentation draft:
Already in this commit.
.