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

Create ZK ancestors optimistically #52195

Merged
merged 5 commits into from
Jul 20, 2023

Conversation

Algunenano
Copy link
Member

Changelog category (leave one):

  • Improvement

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

  • Create ZK ancestors optimistically

Documentation entry for user-facing changes


When creating ZK ancestors, instead of going from root to last node, attempt to do it backwards as create leaves first.

For example, when creating ancestors for /clickhouse/zero_copy/zero_copy_s3/c5b2eca0-b037-49a3-89b9-3ecad815f413/all_64146_64153_1/ the old behaviour would be:

CREATE REQUEST /clickhouse
CREATE REQUEST /clickhouse/zero_copy
CREATE REQUEST /clickhouse/zero_copy/zero_copy_s3
CREATE REQUEST /clickhouse/zero_copy/zero_copy_s3/c5b2eca0-b037-49a3-89b9-3ecad815f413
CREATE REQUEST /clickhouse/zero_copy/zero_copy_s3/c5b2eca0-b037-49a3-89b9-3ecad815f413/all_64146_64153_1

The new behaviour is optimistic and tries the last node first and only in case of failure it navigates the tree.

  • New behaviour, best case scenario: Only one request (either it already exists or the parent exists and it's created):
CREATE REQUEST /clickhouse/zero_copy/zero_copy_s3/c5b2eca0-b037-49a3-89b9-3ecad815f413/all_64146_64153_1
  • New behaviour, worst case scenario: Whole tree.
CREATE REQUEST /clickhouse/zero_copy/zero_copy_s3/c5b2eca0-b037-49a3-89b9-3ecad815f413/all_64146_64153_1
CREATE REQUEST /clickhouse/zero_copy/zero_copy_s3/c5b2eca0-b037-49a3-89b9-3ecad815f413
CREATE REQUEST /clickhouse/zero_copy/zero_copy_s3
CREATE REQUEST /clickhouse/zero_copy
CREATE REQUEST /clickhouse
CREATE REQUEST /clickhouse/zero_copy
CREATE REQUEST /clickhouse/zero_copy/zero_copy_s3
CREATE REQUEST /clickhouse/zero_copy/zero_copy_s3/c5b2eca0-b037-49a3-89b9-3ecad815f413
CREATE REQUEST /clickhouse/zero_copy/zero_copy_s3/c5b2eca0-b037-49a3-89b9-3ecad815f413/all_64146_64153_1

The worst case is much worse (2x requests), but the best case is much better (1 vs 5 requests). The thing is that the best case happens way more often than the worst (which never happens in fact as some parent nodes are always created earlier in the process).

This should help reducing the load in ZK caused by merges with zero copy replication, which requires an exclusive lock via ZK (tryCreateZeroCopyExclusiveLock):

  • The first replicas doing the merge only has to create the last node (the part name), as the rest of the tree is already there. 5 ZK calls vs 1.
  • Other replicas don't need to create anything as the last node already exists. 5 calls vs 1.

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-improvement Pull request with some product improvements label Jul 17, 2023
@robot-clickhouse-ci-1
Copy link
Contributor

robot-clickhouse-ci-1 commented Jul 17, 2023

This is an automated comment for commit b8f73db with description of existing statuses. It's updated for the latest CI running
The full report is available here
The overall status of the commit is 🟡 pending

Check nameDescriptionStatus
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR🟡 pending
Mergeable CheckChecks if all other necessary checks are successful🟢 success
Push to DockerhubThe check for building and pushing the CI related docker images to docker hub🟢 success

@nikitamikhaylov nikitamikhaylov self-assigned this Jul 17, 2023
@Algunenano
Copy link
Member Author

Algunenano commented Jul 18, 2023

Failures look related to the change:

helpers.client.QueryRuntimeException: Client failed! Return code: 231, stderr: Received exception from server (version 23.7.1):
E           Code: 999. DB::Exception: Received from 172.16.6.6:9000. Coordination::Exception. Coordination::Exception: Session expired, path: /d. Stack trace:
E           
E           0. ./build_docker/./contrib/llvm-project/libcxx/include/exception:134: Poco::Exception::Exception(String const&, int) @ 0x0000000043de0293 in /usr/bin/clickhouse
E           1. ./build_docker/./src/Common/Exception.cpp:94: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x0000000024496d30 in /usr/bin/clickhouse
E           2. ./build_docker/./contrib/llvm-project/libcxx/include/string:1499: Coordination::Exception::Exception(String const&, Coordination::Error, int) @ 0x000000003c689933 in /usr/bin/clickhouse
E           3. ./build_docker/./contrib/llvm-project/libcxx/include/string:1499: Coordination::Exception::Exception(Coordination::Error, String const&) @ 0x000000003c68ae2e in /usr/bin/clickhouse
E           4. ./build_docker/./src/Common/ZooKeeper/ZooKeeper.cpp:0: zkutil::ZooKeeper::createAncestors(String const&) @ 0x000000003c6a00c7 in /usr/bin/clickhouse

I'm having a look.

Edit: Fixed now. It was incorrectly rejecting paths without ancestors (e.g. /t).

@Algunenano
Copy link
Member Author

Failures:

@nikitamikhaylov nikitamikhaylov merged commit 10b6fc9 into ClickHouse:master Jul 20, 2023
6 of 8 checks passed
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.

3 participants