Skip to content

Rework parallel replicas settings#63151

Merged
nikitamikhaylov merged 8 commits intomasterfrom
parallel-replicas-beta
Sep 25, 2024
Merged

Rework parallel replicas settings#63151
nikitamikhaylov merged 8 commits intomasterfrom
parallel-replicas-beta

Conversation

@alexey-milovidov
Copy link
Member

@alexey-milovidov alexey-milovidov commented Apr 30, 2024

Changelog category (leave one):

  • Improvement

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

Reworked settings that control the behavior of parallel replicas algorithms. A quick recap: ClickHouse has four different algorithms for parallel reading involving multiple replicas, which is reflected in the setting parallel_replicas_mode, the default value for it is read_tasks
Additionally, the toggle-switch setting enable_parallel_replicas has been added.

This PR is backward-incompatible for the following parallel replicas mode:

  • Sample key;
  • Custom key by hash;
  • Custom key by range;
    Which means that this feature cannot be used correctly in a mixed-versioned cluster.

This closes: #63521


Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

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

CI Settings (Only check the boxes if you know what you are doing):

  • Allow: All Required Checks
  • Allow: Stateless tests
  • Allow: Stateful tests
  • Allow: Integration Tests
  • Allow: Performance tests
  • Allow: All Builds
  • Allow: batch 1, 2 for multi-batch jobs
  • Allow: batch 3, 4, 5, 6 for multi-batch jobs

  • Exclude: Style check
  • Exclude: Fast test
  • Exclude: All with ASAN
  • Exclude: All with TSAN, MSAN, UBSAN, Coverage
  • Exclude: All with aarch64, release, debug

  • Do not test
  • Woolen Wolfdog
  • Upload binaries for special builds
  • Disable merge-commit
  • Disable CI cache

@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-improvement Pull request with some product improvements label Apr 30, 2024
@robot-ch-test-poll3
Copy link
Contributor

robot-ch-test-poll3 commented Apr 30, 2024

This is an automated comment for commit 7b19c65 with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help❌ failure
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc❌ error
Successful checks
Check nameDescriptionStatus
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@alexey-milovidov
Copy link
Member Author

Currently, there are four modes for parallel replicas:

  1. Sample key;
  2. Task-based;
  3. Custom key by hash;
  4. Custom key by range;

Confusingly, the "sample key" mode is available even without use_parallel_replicas,
and the choice between "custom key" and "task-based" modes is determined by setting the value of "parallel_replicas_custom_key".

We should introduce a new setting "parallel_replicas_mode" which will decide between these modes.

Copy link
Member

@devcrafter devcrafter left a comment

Choose a reason for hiding this comment

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

LGTM

@nikitamikhaylov nikitamikhaylov self-assigned this May 6, 2024
@nikitamikhaylov
Copy link
Member

@alexey-milovidov Parallel replicas modes 1, 3, and 4 are currently working on top of distributed table. While task-based parallel replicas work on top of MergeTree. We should unify this as well.

Copy link
Member

@nikitamikhaylov nikitamikhaylov left a comment

Choose a reason for hiding this comment

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

Let's make the parallel replicas with custom key work on top of MergeTree first and introduce the setting parallel_replicas_mode: #63521

@devcrafter
Copy link
Member

Let's make the parallel replicas with custom key work on top of MergeTree first and introduce the setting parallel_replicas_mode: #63521

Unifying settings and implementing custom key on top of MergeTree are 2 different things and can be done independently

@nikitamikhaylov nikitamikhaylov force-pushed the parallel-replicas-beta branch from 81445ce to e73981e Compare May 29, 2024 19:18
@nikitamikhaylov nikitamikhaylov force-pushed the parallel-replicas-beta branch 4 times, most recently from 877a77c to 03e0a27 Compare June 11, 2024 21:38
@devcrafter devcrafter self-requested a review June 13, 2024 10:46
@nikitamikhaylov nikitamikhaylov force-pushed the parallel-replicas-beta branch 2 times, most recently from a2b1420 to bd581df Compare July 12, 2024 13:28
@nikitamikhaylov nikitamikhaylov force-pushed the parallel-replicas-beta branch 2 times, most recently from b635db2 to 1532779 Compare July 19, 2024 13:36
@nikitamikhaylov nikitamikhaylov force-pushed the parallel-replicas-beta branch 4 times, most recently from 275fab3 to cf9f64e Compare August 6, 2024 19:25
@nikitamikhaylov
Copy link
Member

nikitamikhaylov commented Aug 6, 2024

Useful finding:

https://s3.amazonaws.com/clickhouse-test-reports/63151/d64f13986ef04857050172cbc3036965f9ca7b60/ast_fuzzer__asan_.html

2024.08.07 00:26:54.738669 [ 1546 ] {} <Fatal> BaseDaemon: ########## Short fault info ############
2024.08.07 00:26:54.738780 [ 1546 ] {} <Fatal> BaseDaemon: (version 24.8.1.1633, build id: 428AB0B301DE65FE3D27067128ED0F62D73AE5DF, git hash: ef640edaf7507f96ee4f3958ab1a2856518f76dd) (from thread 1541) Received signal -3
2024.08.07 00:26:54.738900 [ 1546 ] {} <Fatal> BaseDaemon: Signal description: sanitizer trap
2024.08.07 00:26:54.738950 [ 1546 ] {} <Fatal> BaseDaemon: Sanitizer trap.
2024.08.07 00:26:54.739002 [ 1546 ] {} <Fatal> BaseDaemon: Stack trace: 0x000055fb123b95f7 0x000055fb12958bf4 0x000055fb0209b536 0x000055fb02082eef 0x000055fb02085d85 0x000055fb02086a18 0x000055fb23246c9f 0x000055fb2323c568 0x000055fb2323beb9 0x000055fb1d8b0fa5 0x000055fb130c544c 0x000055fb124f7661 0x000055fb124fe97d 0x000055fb124f111d 0x000055fb124fafdf 0x000055fb0207c059 0x00007fda21531ac3 0x00007fda215c3850
2024.08.07 00:26:54.739061 [ 1546 ] {} <Fatal> BaseDaemon: ########################################
2024.08.07 00:26:54.739301 [ 1546 ] {} <Fatal> BaseDaemon: (version 24.8.1.1633, build id: 428AB0B301DE65FE3D27067128ED0F62D73AE5DF, git hash: ef640edaf7507f96ee4f3958ab1a2856518f76dd) (from thread 1541) (query_id: e63d3293-50f6-4e6c-a252-6f81401d92ee) (query: DROP TABLE distributed_01099_b) Received signal sanitizer trap (-3)
2024.08.07 00:26:54.739418 [ 1546 ] {} <Fatal> BaseDaemon: Sanitizer trap.
2024.08.07 00:26:54.739493 [ 1546 ] {} <Fatal> BaseDaemon: Stack trace: 0x000055fb123b95f7 0x000055fb12958bf4 0x000055fb0209b536 0x000055fb02082eef 0x000055fb02085d85 0x000055fb02086a18 0x000055fb23246c9f 0x000055fb2323c568 0x000055fb2323beb9 0x000055fb1d8b0fa5 0x000055fb130c544c 0x000055fb124f7661 0x000055fb124fe97d 0x000055fb124f111d 0x000055fb124fafdf 0x000055fb0207c059 0x00007fda21531ac3 0x00007fda215c3850
2024.08.07 00:26:54.776471 [ 1546 ] {} <Fatal> BaseDaemon: 0. ./build_docker/./src/Common/StackTrace.cpp:349: StackTrace::tryCapture() @ 0x000000001abf75f7
2024.08.07 00:26:54.844364 [ 1546 ] {} <Fatal> BaseDaemon: 1. ./build_docker/./src/Common/SignalHandlers.cpp:183: sanitizerDeathCallback() @ 0x000000001b196bf4
2024.08.07 00:26:54.907350 [ 1546 ] {} <Fatal> BaseDaemon: 2. __sanitizer::Die() @ 0x000000000a8d9536
2024.08.07 00:26:54.939228 [ 1546 ] {} <Fatal> BaseDaemon: 3. ? @ 0x000000000a8c0eef
2024.08.07 00:26:54.971210 [ 1546 ] {} <Fatal> BaseDaemon: 4. __asan::ReportGenericError(unsigned long, unsigned long, unsigned long, unsigned long, bool, unsigned long, unsigned int, bool) @ 0x000000000a8c3d85
2024.08.07 00:26:55.004483 [ 1546 ] {} <Fatal> BaseDaemon: 5. __asan_report_load8 @ 0x000000000a8c4a18
2024.08.07 00:26:55.151312 [ 1546 ] {} <Fatal> BaseDaemon: 6.0. inlined from ./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:594: shared_ptr
2024.08.07 00:26:55.151448 [ 1546 ] {} <Fatal> BaseDaemon: 6.1. inlined from ./src/Common/PoolBase.h:74: Entry
2024.08.07 00:26:55.151497 [ 1546 ] {} <Fatal> BaseDaemon: 6.2. inlined from ./src/Common/PoolWithFailoverBase.h:72: TryResult
2024.08.07 00:26:55.151547 [ 1546 ] {} <Fatal> BaseDaemon: 6. ./build_docker/./src/Storages/Distributed/DistributedAsyncInsertDirectoryQueue.cpp:416: DB::DistributedAsyncInsertDirectoryQueue::processFile(String&, DB::SettingsChanges const&) @ 0x000000002ba84c9f
2024.08.07 00:26:55.253871 [ 1546 ] {} <Fatal> BaseDaemon: 7. ./build_docker/./src/Storages/Distributed/DistributedAsyncInsertDirectoryQueue.cpp:377: DB::DistributedAsyncInsertDirectoryQueue::processFiles(DB::SettingsChanges const&) @ 0x000000002ba7a568
2024.08.07 00:26:55.355965 [ 1546 ] {} <Fatal> BaseDaemon: 8.0. inlined from ./contrib/llvm-project/libcxx/include/__mutex_base:100: ~lock_guard
2024.08.07 00:26:55.356072 [ 1546 ] {} <Fatal> BaseDaemon: 8. ./build_docker/./src/Storages/Distributed/DistributedAsyncInsertDirectoryQueue.cpp:158: DB::DistributedAsyncInsertDirectoryQueue::flushAllData(DB::SettingsChanges const&) @ 0x000000002ba79eb9
2024.08.07 00:26:55.495013 [ 1546 ] {} <Fatal> BaseDaemon: 9. ./contrib/llvm-project/libcxx/include/__functional/function.h:0: ? @ 0x00000000260eefa5
2024.08.07 00:26:55.683620 [ 1546 ] {} <Fatal> BaseDaemon: 10. ./contrib/llvm-project/libcxx/include/future:0: std::packaged_task<void ()>::operator()() @ 0x000000001b90344c
2024.08.07 00:26:55.745427 [ 1546 ] {} <Fatal> BaseDaemon: 11. ./contrib/llvm-project/libcxx/include/__functional/function.h:0: ? @ 0x000000001ad35661
2024.08.07 00:26:55.783427 [ 1546 ] {} <Fatal> BaseDaemon: 12. ./src/Common/ThreadPool.h:252: ThreadFromGlobalPoolImpl<false, true>::ThreadFromGlobalPoolImpl<void ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true>>::scheduleImpl<void>(std::function<void ()>, Priority, std::optional<unsigned long>, bool)::'lambda0'()>(void&&)::'lambda'()::operator()() @ 0x000000001ad3c97d
2024.08.07 00:26:55.823890 [ 1546 ] {} <Fatal> BaseDaemon: 13. ./contrib/llvm-project/libcxx/include/__functional/function.h:0: ? @ 0x000000001ad2f11d
2024.08.07 00:26:55.879551 [ 1546 ] {} <Fatal> BaseDaemon: 14.0. inlined from ./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:302: std::unique_ptr<std::tuple<std::unique_ptr<std::__thread_struct, std::default_delete<std::__thread_struct>>, void ThreadPoolImpl<std::thread>::scheduleImpl<void>(std::function<void ()>, Priority, std::optional<unsigned long>, bool)::'lambda0'()>, std::default_delete<std::tuple<std::unique_ptr<std::__thread_struct, std::default_delete<std::__thread_struct>>, void ThreadPoolImpl<std::thread>::scheduleImpl<void>(std::function<void ()>, Priority, std::optional<unsigned long>, bool)::'lambda0'()>>>::reset[abi:v15007](std::tuple<std::unique_ptr<std::__thread_struct, std::default_delete<std::__thread_struct>>, void ThreadPoolImpl<std::thread>::scheduleImpl<void>(std::function<void ()>, Priority, std::optional<unsigned long>, bool)::'lambda0'()>*)
2024.08.07 00:26:55.879665 [ 1546 ] {} <Fatal> BaseDaemon: 14.1. inlined from ./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:259: ~unique_ptr
2024.08.07 00:26:55.879720 [ 1546 ] {} <Fatal> BaseDaemon: 14. ./contrib/llvm-project/libcxx/include/thread:297: void* std::__thread_proxy[abi:v15007]<std::tuple<std::unique_ptr<std::__thread_struct, std::default_delete<std::__thread_struct>>, void ThreadPoolImpl<std::thread>::scheduleImpl<void>(std::function<void ()>, Priority, std::optional<unsigned long>, bool)::'lambda0'()>>(void*) @ 0x000000001ad38fdf
2024.08.07 00:26:55.913567 [ 1546 ] {} <Fatal> BaseDaemon: 15. asan_thread_start(void*) @ 0x000000000a8ba059
2024.08.07 00:26:55.913674 [ 1546 ] {} <Fatal> BaseDaemon: 16. ? @ 0x00007fda21531ac3
2024.08.07 00:26:55.913717 [ 1546 ] {} <Fatal> BaseDaemon: 17. ? @ 0x00007fda215c3850
2024.08.07 00:26:55.913771 [ 1546 ] {} <Fatal> BaseDaemon: Integrity check of the executable skipped because the reference checksum could not be read.
2024.08.07 00:26:56.956668 [ 1546 ] {} <Fatal> BaseDaemon: Changed settings: receive_timeout = 10., receive_data_timeout_ms = 10000, use_hedged_requests = false, allow_suspicious_low_cardinality_types = true, skip_unavailable_shards = true, parallel_distributed_insert_select = 1, log_queries = true, table_function_remote_max_addresses = 200, max_execution_time = 10., max_memory_usage = 10000000000, log_comment = '/workspace/ch/tests/queries/0_stateless/01099_parallel_distributed_insert_select.sql', send_logs_level = 'fatal', prefer_localhost_replica = true, allow_introspection_functions = true, allow_deprecated_syntax_for_merge_tree = true, enable_parallel_replicas = 0, max_parallel_replicas = 3, parallel_replicas_mode = 'sampling_key', parallel_replicas_count = 0, parallel_replica_offset = 2, cluster_for_parallel_replicas = 'parallel_replicas', parallel_replicas_for_non_replicated_merge_tree = true, parallel_replicas_min_number_of_rows_per_replica = 1000, allow_experimental_analyzer = true

@nikitamikhaylov nikitamikhaylov force-pushed the parallel-replicas-beta branch from d64f139 to b72088e Compare August 8, 2024 16:27
@nikitamikhaylov nikitamikhaylov force-pushed the parallel-replicas-beta branch 2 times, most recently from 999f2ed to 328db3d Compare August 22, 2024 10:59
@nikitamikhaylov nikitamikhaylov changed the title Parallel replicas feature is Beta Rework parallel replicas settings Sep 25, 2024
@nikitamikhaylov nikitamikhaylov added the pr-backward-incompatible Pull request with backwards incompatible changes label Sep 25, 2024
@nikitamikhaylov nikitamikhaylov added this pull request to the merge queue Sep 25, 2024
Merged via the queue into master with commit 2003f91 Sep 25, 2024
@nikitamikhaylov nikitamikhaylov deleted the parallel-replicas-beta branch September 25, 2024 16:42
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 25, 2024
{"join_to_sort_minimum_perkey_rows", 0, 40, "The lower limit of per-key average rows in the right table to determine whether to rerange the right table by key in left or inner join. This setting ensures that the optimization is not applied for sparse table keys"},
{"join_to_sort_maximum_table_rows", 0, 10000, "The maximum number of rows in the right table to determine whether to rerange the right table by key in left or inner join"},
{"allow_experimental_join_right_table_sorting", false, false, "If it is set to true, and the conditions of `join_to_sort_minimum_perkey_rows` and `join_to_sort_maximum_table_rows` are met, rerange the right table by key to improve the performance in left or inner hash join"},
{"mongodb_throw_on_unsupported_query", false, true, "New setting."},
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have different values for a new setting?

Copy link
Member

Choose a reason for hiding this comment

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

bool is_plain_merge_tree = storage && storage->isMergeTree() && !storage->supportsReplication();
if (is_plain_merge_tree && settings[Setting::allow_experimental_parallel_reading_from_replicas] > 0
&& !settings[Setting::parallel_replicas_for_non_replicated_merge_tree])
&& !settings[Setting::allow_experimental_parallel_reading_from_replicas])
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a typo? This AND condition will always be false. Or this is fine?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this is a typo.

zvonand pushed a commit to Altinity/ClickHouse that referenced this pull request Dec 17, 2024
Enmk pushed a commit to Altinity/ClickHouse that referenced this pull request Dec 22, 2024
github-merge-queue bot pushed a commit that referenced this pull request Dec 24, 2024
robot-ch-test-poll added a commit that referenced this pull request Dec 24, 2024
robot-ch-test-poll added a commit that referenced this pull request Dec 24, 2024
robot-ch-test-poll added a commit that referenced this pull request Dec 24, 2024
robot-clickhouse-ci-2 added a commit that referenced this pull request Dec 24, 2024
robot-ch-test-poll2 added a commit that referenced this pull request Dec 24, 2024
devcrafter added a commit that referenced this pull request Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backward-incompatible Pull request with backwards incompatible changes pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify the way how all the modes for parallel replicas are enabled and used

7 participants