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

Add ability to skip read-only replicas for INSERT into Distributed engine #59176

Merged
merged 21 commits into from
Mar 27, 2024

Conversation

azat
Copy link
Collaborator

@azat azat commented Jan 24, 2024

Changelog category (leave one):

  • Improvement

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

Add ability to skip read-only replicas for INSERT into Distributed engine (Controlled with distributed_insert_skip_read_only_replicas setting, by default OFF - backward compatible)

Sometimes replica may be readonly for a long time, and this will make
some INSERT queries fail, but it does not make sense to INSERT into
readonly replica, so let's ignore them.

But note, that this will require to extend TableStatus (not extend, but
introduce new version), that will have is_readonly field.

Also before background INSERT into Distributed does not uses
getManyChecked() which means that they do not request TableStatus
packet, while now they would, though this is minor (just a note).

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-improvement Pull request with some product improvements label Jan 24, 2024
@robot-clickhouse-ci-1
Copy link
Contributor

robot-clickhouse-ci-1 commented Jan 24, 2024

This is an automated comment for commit 4eafb86 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
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
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests❌ failure
Successful checks
Check nameDescriptionStatus
A SyncThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
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✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ 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
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. Integrational 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✅ 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
Mergeable CheckChecks if all other necessary checks are successful✅ success
PR CheckThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ 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

@azat azat force-pushed the dist/readonly-replicas branch 5 times, most recently from 05d599a to dba12a9 Compare January 25, 2024 16:28
@azat azat marked this pull request as ready for review January 25, 2024 16:28
@azat
Copy link
Collaborator Author

azat commented Jan 28, 2024

Test failures does not looks related:

Stateless tests (debug) [2/5] — fail: 1, passed: 1164, skipped: 10

  • 01459_manual_write_to_replicas

Stateless tests (debug) [3/5] — fail: 2, passed: 1237, skipped: 22

  • 01508_partition_pruning_long
  • 02125_lz4_compression_bug

Upgrade check (debug) — Logical error thrown (see clickhouse-server.log or logical_errors.txt)
Upgrade check (tsan) — Logical error thrown (see clickhouse-server.log or logical_errors.txt)

@devcrafter devcrafter self-assigned this Jan 30, 2024
src/Client/ConnectionEstablisher.cpp Outdated Show resolved Hide resolved
@azat azat force-pushed the dist/readonly-replicas branch 3 times, most recently from c47efd1 to 6d6129c Compare February 11, 2024 14:56
@azat
Copy link
Collaborator Author

azat commented Feb 13, 2024

Stateless tests (tsan, s3 storage) [3/5] — fail: 1, passed: 1223, skipped: 38

Timeout exceeded while receiving data from server. Waited for 300 seconds, timeout is 300 seconds

@azat azat requested a review from devcrafter February 15, 2024 11:59
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.

I think, the new behavior requires a setting. In general, writing into a currently read-only replication table is covered by insert retries.

The question is what semantic we want to bring with the new setting
(1) - prefer insert into currently non-read-only replicas
or
(2) - use only non-read-only replicas

AFAIU, the current implementation is about (1)

src/Client/ConnectionEstablisher.cpp Outdated Show resolved Hide resolved
src/Client/ConnectionPoolWithFailover.h Outdated Show resolved Hide resolved
src/Common/ProfileEvents.cpp Outdated Show resolved Hide resolved
src/Common/PoolWithFailoverBase.h Outdated Show resolved Hide resolved
src/Core/ProtocolDefines.h Outdated Show resolved Hide resolved
src/Core/ProtocolDefines.h Show resolved Hide resolved
src/Interpreters/TablesStatus.h Show resolved Hide resolved
src/Storages/Distributed/DistributedAsyncInsertBatch.cpp Outdated Show resolved Hide resolved
src/Storages/Distributed/DistributedAsyncInsertBatch.cpp Outdated Show resolved Hide resolved
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.

I think, the new behavior requires a setting. In general, writing into a currently read-only replication table is covered by insert retries.

The question is what semantic we want to bring with the new setting
(1) - prefer insert into currently non-read-only replicas
or
(2) - use only non-read-only replicas

AFAIU, the current implementation is about (1)

devcrafter

This comment was marked as duplicate.

@azat
Copy link
Collaborator Author

azat commented Feb 15, 2024

I think, the new behavior requires a setting. In general, writing into a currently read-only replication table is covered by insert retries.

My thinking was that since it only prefers non-read-only replicas, there is no need in a separate setting, but I'm OK with adding one.

The question is what semantic we want to bring with the new setting
(1) - prefer insert into currently non-read-only replicas
or
(2) - use only non-read-only replicas

And yes, if there will be a setting then we can add a enum for it, i.e. prefer, no, yes or similar

AFAIU, the current implementation is about (1)

Yes.

@devcrafter
Copy link
Member

AFAIU, the current implementation is about (1)

Yes.

Let's keep it. Doubt that we need (2) actually

@azat
Copy link
Collaborator Author

azat commented Feb 15, 2024

Let's keep it. Doubt that we need (2) actually

Do you still think that extra setting make sense?

@devcrafter
Copy link
Member

devcrafter commented Feb 15, 2024

Let's keep it. Doubt that we need (2) actually

Do you still think that extra setting make sense?

Hard to say, but at least there will be a way to control behavior. I guess there could be cases which benefit or not from this behavior (I guess it's mostly about load distribution). For example, if several long-running insert queries are thrown while some replicas will reconnect to zk, the inserts will be assigned to non-read-only replicas, i.e. load could not be distributed well.

When the user definitely knows that some replicas will be read-only for a long time, then it is worth excluding read-only replicas upfront. But then, we're talking about option (2) 🤔

@azat
Copy link
Collaborator Author

azat commented Feb 22, 2024

Okay, since you are also struggling about new setting for this functionality, I've added enum, distributed_insert_replicas_preferences=PREFER_NON_READ_ONLY/NO_PREFERENCES.

And also addressed all of your comments.

@azat
Copy link
Collaborator Author

azat commented Feb 24, 2024

Test failures does not looks related:

Stress test (debug) — Killed by signal (in clickhouse-server.log)
Stress test (tsan) — Killed by signal (in clickhouse-server.log)

@azat azat force-pushed the dist/readonly-replicas branch 2 times, most recently from 014a019 to 52f7dd3 Compare March 24, 2024 15:47
azat added 21 commits March 26, 2024 11:19
…rite-once)

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Sometimes replica may be readonly for a long time, and this will make
some INSERT queries fail, but it does not make sense to INSERT into
readonly replica, so let's ignore them.

But note, that this will require to extend TableStatus (not extend, but
introduce new version), that will have is_readonly field.

Also before background INSERT into Distributed does not uses
getManyChecked() which means that they do not request TableStatus
packet, while now they would, though this is minor (just a note).

v2: Add a note about max_replica_delay_for_distributed_queries for INSERT
v3: Skip read-only replicas for async INSERT into Distributed
v4: Remove extra @insert parameter for ConnectionPool*::get*
    It make sense only when the table name had passed --
    ConnectionPoolWithFailover::getManyChecked()
v5: rebase on top LoggerPtr
v6: rebase
v7: rebase
v8: move TryResult::is_readonly into the end

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Now, since there is connection probing, the error changed from
UNKNOWN_TABLE to ALL_CONNECTION_TRIES_FAILED, though I'm not sure that
this good...

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
…ributed

v2: replace without s3_plain disk
v3: add check for DistributedConnectionReadOnlyReplica
v4: set insert_keeper_max_retries=0
v5: do not set insert_keeper_max_retries=0
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
That was the changes that looks OK for the initial patchset version, but
not now, after all review comments.

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
…rt_skip_read_only_replicas

v2: fix test
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
…und_robin LB)

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
…plica

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
@@ -289,7 +290,8 @@ void DistributedAsyncInsertBatch::sendSeparateFiles(const SettingsChanges & sett
parent.storage.getContext()->getOpenTelemetrySpanLog());

auto timeouts = ConnectionTimeouts::getTCPTimeoutsWithFailover(insert_settings);
auto connection = parent.pool->get(timeouts);
auto result = parent.pool->getManyCheckedForInsert(timeouts, insert_settings, PoolMode::GET_ONE, parent.storage.remote_storage.getQualifiedName());
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit strange to introduce getManyCheckedForInsert (get many) which only used with PoolMode::GET_ONE (get one). But it looks fine since requires minimal changes in implementation.

@devcrafter devcrafter merged commit 15a0f53 into ClickHouse:master Mar 27, 2024
233 of 236 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 27, 2024
@azat azat deleted the dist/readonly-replicas branch March 27, 2024 12:43
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 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.

None yet

4 participants