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

Fix: possible race condition on EXCHANGE TABLES query #61135

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

yakov-olkhovskiy
Copy link
Member

Changelog category (leave one):

  • Improvement

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

Fixed possible race condition when EXCHANGE TABLES executed in parallel.

closes #61072

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

robot-ch-test-poll3 commented Mar 10, 2024

This is an automated comment for commit f0d55ea 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
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests❌ failure
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ failure
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ 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
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
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
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 alexey-milovidov self-assigned this Mar 10, 2024
@alexey-milovidov
Copy link
Member

Add a test that has a chance to reproduce the problem at least occasionally.

@@ -12,6 +12,7 @@ class IStorage;

using ConstStoragePtr = std::shared_ptr<const IStorage>;
using StoragePtr = std::shared_ptr<IStorage>;
using StorageWeakPtr = std::weak_ptr<IStorage>;
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 not allowed to use std::weak_ptr<IStorage> because we rely on std::shared_ptr<IStorage>::unique()

Copy link
Member

Choose a reason for hiding this comment

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

Instead of saving StoragePtr, we can save StorageID with resolved UUID

Copy link
Member Author

Choose a reason for hiding this comment

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

it's exactly the point to not keep shared_ptr here - since on HTTP requests session can be preserved it would block database from DROP - making it weak_ptr doesn't block it and we don't need to keep it cached beyond session so it should be safe

Copy link
Member

Choose a reason for hiding this comment

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

there's a race condition

@tavplubix tavplubix self-assigned this Mar 20, 2024
@@ -912,6 +912,23 @@ String Context::getFilesystemCacheUser() const
return shared->filesystem_cache_user;
}

DatabaseAndTable Context::getOrCacheStorage(const StorageID & id, std::function<DatabaseAndTable()> f, std::optional<Exception> * exception) const
Copy link
Member

Choose a reason for hiding this comment

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

We could cache it in Context::resolveStorageID, but a new method is fine too

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we want to enforce this cache everywhere where we call to Context::resolveStorageID - at least having a query context is a condition we need to use this cache.

Copy link
Member

Choose a reason for hiding this comment

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

We can check this condition in resolveStorageID

return storage;
}

auto storage = f();
Copy link
Member

Choose a reason for hiding this comment

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

Consider a better name

{
DatabaseAndTable storage = DatabaseCatalog::instance().tryGetByUUID(storage_id->uuid);
if (exception && !storage.second)
exception->emplace(Exception(ErrorCodes::UNKNOWN_TABLE, "Table {} does not exist anymore - maybe it was dropped", id.getNameForLogs()));
Copy link
Member

Choose a reason for hiding this comment

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

Currently, a query will fail if it requests a table the second time, but the table was dropped after the first get. But we can improve it later

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we need to improve it - if table was dropped concurrently then query is better to be interrupted than trying to reposes the table from drop queue - at this point we don't even know who is holding it from physical deletion...

Copy link
Member

Choose a reason for hiding this comment

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

We do know, see addStorageHolder

@tavplubix
Copy link
Member

@yakov-olkhovskiy, restarting CI by merging master is pointless. It will not fix the failures. For two reasons:

  • Many tests are broken in master after enabling the new analyzer. They are not fixed yet and will fail again. But even unrelated failures are worth attention.
  • Some failures are actually related to the changes in this PR. Please check all CI failures on 0eae42a and 242dc60

@tavplubix tavplubix added the do not test disable testing on pull request label Apr 3, 2024
@yakov-olkhovskiy
Copy link
Member Author

@tavplubix Mergeable check was failing because build failures like this:
https://github.com/ClickHouse/ClickHouse/actions/runs/8530457581/job/23379706220#step:9:107
I got an impression that there is something wrong with CI and restarting would help

Some failures are actually related to the changes in this PR. Please check all CI failures on 0eae42a and 242dc60

I'm not sure I see anything related... could you point it out please?

@tavplubix
Copy link
Member

tavplubix commented Apr 3, 2024

I'm not sure I see anything related... could you point it out please?

@yakov-olkhovskiy please check everything, and you will see. If you don't see it - try to debug every failure until you see.

Just checking everything (and trying to debug) is always a good idea because we should not ignore failures even if they are unrelated (but in this case some of them are).

@yakov-olkhovskiy
Copy link
Member Author

@tavplubix found it... "Tests are not finished" is a confusing status though...

@yakov-olkhovskiy yakov-olkhovskiy removed the do not test disable testing on pull request label Apr 6, 2024
@yakov-olkhovskiy yakov-olkhovskiy added the force tests Force test ignoring fast test output. label Apr 8, 2024
@yakov-olkhovskiy
Copy link
Member Author

...fast test is getting hung and logs don't show proper stack traces - I added "force tests" label to check it with thread sanitizer...

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

Successfully merging this pull request may close these issues.

EXCHANGE TABLES query can produce race condition
4 participants