Skip to content

Add drop replica alter support#10679

Merged
tavplubix merged 10 commits intoClickHouse:masterfrom
sundy-li:drop_replica2
Jun 24, 2020
Merged

Add drop replica alter support#10679
tavplubix merged 10 commits intoClickHouse:masterfrom
sundy-li:drop_replica2

Conversation

@sundy-li
Copy link
Copy Markdown
Contributor

@sundy-li sundy-li commented May 5, 2020

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • New Feature

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_name support. This fixes #7080.

Detailed description / Documentation draft:
Already in this commit.
.

@blinkov blinkov added doc-alert pr-feature Pull request with new product feature labels May 5, 2020
@sundy-li sundy-li marked this pull request as ready for review May 6, 2020 04:05
@filimonov
Copy link
Copy Markdown
Contributor

It should not be possible to remove active replica this way, only stale/inactive.

@filimonov
Copy link
Copy Markdown
Contributor

#7080

*/
void drop() override;

/** Removes a specific replica from Zookeeper. If replica is local, it works same as `drop` method.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other code and comments tell it is impossible to drop local replica. Incorrect comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens with data on that replica? It remains on remote server?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it remains. We can't control that. The main reason we call DROP REPLICA is that we should enable remove the 'dead' replica.

@sundy-li
Copy link
Copy Markdown
Contributor Author

sundy-li commented May 8, 2020

BTW What's Yandex synchronization check? I can't look into the Details.

I'll look into the Integration tests, seems the Ephemeral node /is_acitve not released when we kill the node_1_2

@alexey-milovidov
Copy link
Copy Markdown
Member

What's Yandex synchronization check?

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.

@alexey-milovidov
Copy link
Copy Markdown
Member

For somewhat reason, newly added integration test does not pass.

@tavplubix
Copy link
Copy Markdown
Member

Maybe it should be implemented as SYSTEM query instead of ALTER?
Something like SYSTEM DROP REPLICA 'replica_name' FROM table_name to remove dead replica of existing table and SYSTEM DROP REPLICA 'replica_name' FROM '/path/to/table/in/zk/' to remove dead replica of some table, which does not exists on the local server.
The second query will be useful to remove garbage from ZooKeeper after the local replica was dropped, but metadata of dead replica are left.

@sundy-li
Copy link
Copy Markdown
Contributor Author

Maybe it should be implemented as SYSTEM query instead of ALTER?
Something like SYSTEM DROP REPLICA 'replica_name' FROM table_name to remove dead replica of existing table and SYSTEM DROP REPLICA 'replica_name' FROM '/path/to/table/in/zk/' to remove dead replica of some table, which does not exists on the local server.
The second query will be useful to remove garbage from ZooKeeper after the local replica was dropped, but metadata of dead replica are left.

Good idea, I will consider it later. (Now I am just a little busy about work)

@amudong
Copy link
Copy Markdown
Contributor

amudong commented May 26, 2020

Maybe it should be implemented as SYSTEM query instead of ALTER?
Something like SYSTEM DROP REPLICA 'replica_name' FROM table_name to remove dead replica of existing table and SYSTEM DROP REPLICA 'replica_name' FROM '/path/to/table/in/zk/' to remove dead replica of some table, which does not exists on the local server.
The second query will be useful to remove garbage from ZooKeeper after the local replica was dropped, but metadata of dead replica are left.

Yes, I have implemented the way to replace the ALTER query with SYSTEM, and support the two calling methods you mentioned. I will commit it later.Also, we want to add some methods like SYSTEM DROP REPLICA 'replica_name', SYSTEM DROP REPLICA 'replica_name' FROM DATABASE 'database_name' and SYSTEM DROP REPLICA 'replica_name' FROM TABLE 'database_name.table_name' .

Replicas can be dropped using following syntax:

```sql
SYSTEM DROP REPLICA replica_name;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

};

auto print_drop_replica = [&] {
settings.ostr << " " << (settings.hilite ? hilite_identifier : "")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not an identifier

else if (!query.database.empty())
{
auto databases = DatabaseCatalog::instance().getDatabases();
auto it = databases.find(query.database);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DatabaseCatalog::instance().getDatabase(query.database)

{
storage_replicated->getStatus(status);

if (status.replica_path.compare(query.replica_zk_path + "/replicas/" + status.replica_name) == 0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it done in StorageReplicatedMergeTree::shutdown() which calls ReplicatedMergeTreeRestartingThread::partialShutdown()?

@sundy-li sundy-li marked this pull request as draft June 20, 2020 12:56
@amudong amudong force-pushed the drop_replica2 branch 2 times, most recently from 8b6a31e to 340b300 Compare June 22, 2020 15:27
sundy-li and others added 8 commits June 23, 2020 12:12
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
@tavplubix tavplubix mentioned this pull request Jun 23, 2020
tavplubix added a commit that referenced this pull request Jun 24, 2020
@tavplubix tavplubix merged commit 2a51286 into ClickHouse:master Jun 24, 2020
@cw9
Copy link
Copy Markdown
Contributor

cw9 commented Jun 27, 2020

Thanks for adding this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SYSTEM DROP REPLICA

8 participants