Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReplicatedMergeTree tables as readonly until attach is finished #40148

Merged
merged 20 commits into from
Aug 25, 2022

Conversation

antonio2368
Copy link
Member

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

During startup and ATTACH call, ReplicatedMergeTree tables will be readonly until the ZooKeeper connection is made and the setup is finished.

@tavplubix this is the basic idea. Hope it's okay.
Closes #40105

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

@robot-ch-test-poll robot-ch-test-poll added the pr-improvement Pull request with some product improvements label Aug 12, 2022
@tavplubix
Copy link
Member

Btw, we already have test for this, you only need to uncomment it:

# main_node.query("CREATE TABLE startup.rmt (n int) ENGINE=ReplicatedMergeTree order by n")
main_node.query("CREATE TABLE startup.rmt (n int) ENGINE=MergeTree order by n")

@antonio2368 antonio2368 changed the title [WIP] ReplicatedMergeTree tables as readonly until attach is finished ReplicatedMergeTree tables as readonly until attach is finished Aug 12, 2022
@antonio2368 antonio2368 marked this pull request as ready for review August 16, 2022 13:12
src/Storages/MergeTree/ReplicatedMergeTreeAttachThread.cpp Outdated Show resolved Hide resolved
tests/integration/test_replicated_database/test.py Outdated Show resolved Hide resolved
src/Storages/StorageReplicatedMergeTree.cpp Outdated Show resolved Hide resolved
src/Storages/StorageReplicatedMergeTree.cpp Outdated Show resolved Hide resolved
src/Storages/MergeTree/MergeTreeSettings.h Outdated Show resolved Hide resolved
src/Storages/MergeTree/ReplicatedMergeTreeAttachThread.cpp Outdated Show resolved Hide resolved
src/Storages/MergeTree/ReplicatedMergeTreeAttachThread.cpp Outdated Show resolved Hide resolved
Comment on lines 82 to 84
/// In old tables this node may missing or be empty
String replica_metadata;
const bool replica_metadata_exists = withRetries([&] { return zookeeper->tryGet(replica_path + "/metadata", replica_metadata); });
Copy link
Member

@tavplubix tavplubix Aug 18, 2022

Choose a reason for hiding this comment

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

Such tables are probably too old and we can remove compatibility with them and throw an exception that says that upgrade from 20.3 and older to 22.9 and newer should be done through an intermediate version.

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe we can remove this in a different PR to focus on the main part of this PR?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we can do it in separate PR. Btw, removal of this code will fix a bug: #30826 (comment)

src/Storages/MergeTree/ReplicatedMergeTreeAttachThread.cpp Outdated Show resolved Hide resolved
src/Storages/StorageReplicatedMergeTree.h Outdated Show resolved Hide resolved
@antonio2368 antonio2368 marked this pull request as draft August 19, 2022 10:29
@antonio2368 antonio2368 marked this pull request as ready for review August 20, 2022 20:36
@antonio2368
Copy link
Member Author

@tavplubix I tried to make it as simple as possible PTAL.

src/Storages/MergeTree/ReplicatedMergeTreeAttachThread.cpp Outdated Show resolved Hide resolved
src/Storages/MergeTree/ReplicatedMergeTreeAttachThread.cpp Outdated Show resolved Hide resolved
bool maybe_has_metadata_in_zookeeper = false;
{
std::lock_guard lock{initialization_mutex};
maybe_has_metadata_in_zookeeper = !initialization_done || !has_metadata_in_zookeeper.has_value() || *has_metadata_in_zookeeper;
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to check initialization_done here? Seems like !has_metadata_in_zookeeper.has_value() is enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

But has_metadata_in_zookeeper isn't an atomic and can change in parallel in AttachThread.
Am I missing something?

Copy link
Member

Choose a reason for hiding this comment

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

shutdown() must be called before drop() and shutdown() stops AttachThread, so it cannot change in parallel

Copy link
Member Author

Choose a reason for hiding this comment

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

okay
then the shutdown call in drop gives a different impression.
Should that be an assert then? (that shutdown was called)

Copy link
Member

Choose a reason for hiding this comment

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

Hm, this shutdown() call is from 2014 and it's not clear why it was added (b4d85c1). AFAIK, now we always call shutdown() before dropping (or detaching) a table

Should that be an assert then? (that shutdown was called)

Yep

Copy link
Member Author

Choose a reason for hiding this comment

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

https://s3.amazonaws.com/clickhouse-test-reports/40148/797e21761ab3e2eb1c019da71e44400898125f68/stress_test__debug_.html

It seems assert fails.
I think it's connected to the case when CH gets restarted before the table is dropped. On the next start, it will be read from metadata_dropped, recreated, and not started. Because of that shutdown won't be called.
Did I miss something?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I forgot about this case. In this case we don't need to call shutdown() because startup() was not called (so either AttachThread was not started at all or it was already stopped)

src/Storages/MergeTree/ReplicatedMergeTreeAttachThread.cpp Outdated Show resolved Hide resolved
src/Storages/StorageReplicatedMergeTree.cpp Outdated Show resolved Hide resolved
@antonio2368
Copy link
Member Author

ClickHouse Stateless Tests (debug) [3/3] - 02405_pmj_issue_40335 seems flaky
cc @vdimir it was added with #40581

@tavplubix
Copy link
Member

Performance Comparison Aarch64 - something weird with docker:

docker: error during connect: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.41/containers/create": EOF.
See 'docker run --help'.

Tests on the prev commit were fine (except the assertion), so I think we can merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-improvement Pull request with some product improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ReplicatedMergeTree tables should be able to start up if ZooKeeper is configured but unavailable
3 participants