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

Fixes Join data was released in grace_hash join algorithm #51382

Merged
merged 2 commits into from Jun 29, 2023

Conversation

lgbo-ustc
Copy link
Contributor

@lgbo-ustc lgbo-ustc commented Jun 25, 2023

Changelog category (leave one):

  • Improvement

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

Issue #50220 reports a core in grace_hash join. We finally reproduce the exception on local, and found that the issue is related to the failure of creating temporary file. Somehow this is triggered in #49816 #49483.

2023.06.25 09:36:04.935602 [ 9318 ] {8df8fbde-0a53-46b8-85bf-2810c4c30935} <Error> TCPHandler: Code: 241. DB::Exception: Memory tracker (for query): fault injected. Would use 108.38 MiB (attempt to allocate chunk of 1048927 bytes), maximum: 9.31 GiB: While executing DelayedJoinedBlocksTransform. (MEMORY_LIMIT_EXCEEDED), Stack trace (when copying this message, always include the lines below):

0. std::exception::capture() @ 0x000000002af43e55 in /usr/bin/clickhouse
1. ./build_docker/./base/poco/Foundation/src/Exception.cpp:28: Poco::Exception::Exception(String const&, int) @ 0x0000000048a8d485 in /usr/bin/clickhouse
2. ./build_docker/./src/Common/Exception.cpp:92: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x00000000375cea0b in /usr/bin/clickhouse
3. ./build_docker/./contrib/llvm-project/libcxx/include/string:1499: DB::Exception::Exception<char const*, char const*, String, long&, String>(int, FormatStringHelperImpl<std::type_identity<char const*>::type, std::type_identity<char const*>::type, std::type_identity<String>::type, std::type_identity<long&>::type, std::type_identity<String>::type>, char const*&&, char const*&&, String&&, long&, String&&) @ 0x00000000375e159a in /usr/bin/clickhouse
4. ./build_docker/./src/Common/MemoryTracker.cpp:0: MemoryTracker::allocImpl(long, bool, MemoryTracker*) @ 0x00000000375e04b3 in /usr/bin/clickhouse
5. ./build_docker/./src/Common/MemoryTracker.cpp:369: MemoryTracker::allocImpl(long, bool, MemoryTracker*) @ 0x00000000375e0016 in /usr/bin/clickhouse
6. ./build_docker/./src/Common/CurrentMemoryTracker.cpp:59: CurrentMemoryTracker::allocImpl(long, bool) @ 0x00000000375818d4 in /usr/bin/clickhouse
7. ./build_docker/./src/Common/Allocator.h:103: DB::Memory<Allocator<false, false>>::alloc(unsigned long) @ 0x000000003763ca3c in /usr/bin/clickhouse
8. ./build_docker/./src/IO/BufferWithOwnMemory.h:159: DB::BufferWithOwnMemory<DB::WriteBuffer>::BufferWithOwnMemory(unsigned long, char*, unsigned long) @ 0x000000003763c814 in /usr/bin/clickhouse
9. ./build_docker/./src/Compression/CompressedWriteBuffer.cpp:67: DB::CompressedWriteBuffer::CompressedWriteBuffer(DB::WriteBuffer&, std::shared_ptr<DB::ICompressionCodec>, unsigned long) @ 0x0000000043b6b3f7 in /usr/bin/clickhouse
10. ./build_docker/./src/Interpreters/TemporaryDataOnDisk.cpp:150: DB::TemporaryFileStream::OutputWriter::OutputWriter(std::unique_ptr<DB::WriteBuffer, std::default_delete<DB::WriteBuffer>>, DB::Block const&) @ 0x0000000045875cdb in /usr/bin/clickhouse
11. ./build_docker/./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:0: DB::TemporaryFileStream::TemporaryFileStream(std::unique_ptr<DB::TemporaryFileOnDisk, std::default_delete<DB::TemporaryFileOnDisk>>, DB::Block const&, DB::TemporaryDataOnDisk*) @ 0x00000000458714f7 in /usr/bin/clickhouse
12. ./build_docker/./src/Interpreters/TemporaryDataOnDisk.cpp:89: DB::TemporaryDataOnDisk::createStream(DB::Block const&, unsigned long) @ 0x0000000045870fe3 in /usr/bin/clickhouse
13. ./build_docker/./src/Interpreters/GraceHashJoin.cpp:395: DB::GraceHashJoin::addBucket(std::vector<std::shared_ptr<DB::GraceHashJoin::FileBucket>, std::allocator<std::shared_ptr<DB::GraceHashJoin::FileBucket>>>&) @ 0x0000000044977a7a in /usr/bin/clickhouse
14. ./build_docker/./src/Interpreters/GraceHashJoin.cpp:384: DB::GraceHashJoin::rehashBuckets(unsigned long) @ 0x000000004497df12 in /usr/bin/clickhouse
15. ./build_docker/./contrib/llvm-project/libcxx/include/vector:951: DB::GraceHashJoin::addJoinedBlockImpl(DB::Block) @ 0x000000004497a038 in /usr/bin/clickhouse
16. ./build_docker/./src/Interpreters/GraceHashJoin.cpp:0: DB::GraceHashJoin::getDelayedBlocks() @ 0x0000000044981d7a in /usr/bin/clickhouse
17. ./build_docker/./src/Processors/Transforms/JoiningTransform.cpp:468: DB::DelayedJoinedBlocksTransform::work() @ 0x0000000047718fe0 in /usr/bin/clickhouse
18. ./build_docker/./src/Processors/Executors/ExecutionThreadContext.cpp:50: DB::ExecutionThreadContext::executeTask() @ 0x00000000471f67b0 in /usr/bin/clickhouse
19. ./build_docker/./src/Processors/Executors/PipelineExecutor.cpp:255: DB::PipelineExecutor::executeStepImpl(unsigned long, std::atomic<bool>*) @ 0x00000000471e5a1b in /usr/bin/clickhouse
20. ./build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:833: void std::__function::__policy_invoker<void ()>::__call_impl<std::__function::__default_alloc_func<DB::PipelineExecutor::spawnThreads()::$_0, void ()>>(std::__function::__policy_storage const*) @ 0x00000000471e76e5 in /usr/bin/clickhouse
21. ./build_docker/./base/base/../base/wide_integer_impl.h:796: ThreadPoolImpl<ThreadFromGlobalPoolImpl<false>>::worker(std::__list_iterator<ThreadFromGlobalPoolImpl<false>, void*>) @ 0x000000003771db60 in /usr/bin/clickhouse
22. ./build_docker/./src/Common/ThreadPool.cpp:0: ThreadFromGlobalPoolImpl<false>::ThreadFromGlobalPoolImpl<void ThreadPoolImpl<ThreadFromGlobalPoolImpl<false>>::scheduleImpl<void>(std::function<void ()>, Priority, std::optional<unsigned long>, bool)::'lambda0'()>(void&&)::'lambda'()::operator()() @ 0x0000000037722faf in /usr/bin/clickhouse
23. ./build_docker/./base/base/../base/wide_integer_impl.h:796: ThreadPoolImpl<std::thread>::worker(std::__list_iterator<std::thread, void*>) @ 0x000000003771aa20 in /usr/bin/clickhouse
24. ./build_docker/./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:302: void* std::__thread_proxy[abi:v15000]<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*) @ 0x000000003771ffea in /usr/bin/clickhouse
25. ? @ 0x00007f6939eb7609 in ?
26. __clone @ 0x00007f6939ddc133 in ?

When the exception happen, all the threads of the query process are not stopped immediately at the same time, there is still a thread trying to use the hash_join which has been released in the the thread with exceptions. So the core happens.

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/

@lgbo-ustc
Copy link
Contributor Author

lgbo-ustc commented Jun 25, 2023

@vdimir we think we have found the cause in #50220

There is a settings in stress.py

ci/stress.py:        client_options.append("memory_tracker_fault_probability=0.001")

@lgbo-ustc lgbo-ustc marked this pull request as ready for review June 25, 2023 07:30
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 25, 2023
@alexey-milovidov
Copy link
Member

The "bug fix" category requires a test.
Either add a test, or (if it is not possible), change to Improvement.

@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-bugfix Pull request with bugfix, not backported by default label Jun 25, 2023
@robot-ch-test-poll1
Copy link
Contributor

robot-ch-test-poll1 commented Jun 25, 2023

This is an automated comment for commit aab86da 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 🔴 failure

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🟢 success
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🟢 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 image for serversThe check to build and optionally push the mentioned image to docker hub🟢 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🔴 failure
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
Push to DockerhubThe check for building and pushing the CI related docker images to docker hub🟢 success
SQLancerFuzzing tests that detect logical bugs with SQLancer tool🟢 success
SqllogicRun clickhouse on the sqllogic test set against sqlite and checks that all statements are passed🟢 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🔴 failure
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors🔴 failure
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

@lgbo-ustc lgbo-ustc force-pushed the grace_hash_join_debug_2306 branch 2 times, most recently from fd2170e to a45c53f Compare June 25, 2023 07:47
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-improvement Pull request with some product improvements and removed pr-bugfix Pull request with bugfix, not backported by default labels Jun 25, 2023
@lgbo-ustc lgbo-ustc force-pushed the grace_hash_join_debug_2306 branch 4 times, most recently from 07167ee to 0280106 Compare June 25, 2023 12:28
@lgbo-ustc
Copy link
Contributor Author

@alexey-milovidov would you trigger this ci ?

@alexey-milovidov
Copy link
Member

I've asked our engineer why the CI has not triggered automatically.
I will wait for his answer because he should see it.

@Felixoid
Copy link
Member

Felixoid commented Jun 26, 2023

Changes in tests/CI prohibit autostart by can be tested. Each push must be reviewed by the assignee

@vdimir vdimir self-assigned this Jun 26, 2023
Copy link
Member

@vdimir vdimir left a comment

Choose a reason for hiding this comment

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

Such a great catch!

@clickhouse-ci clickhouse-ci bot added manual approve Manual approve required to run CI labels Jun 26, 2023
@lgbo-ustc
Copy link
Contributor Author

@vdimir please help trigger the CI

@Felixoid
Copy link
Member

woop woop

image

@lgbo-ustc
Copy link
Contributor Author

@vdimir There are 3 failures, seems not relate to this pr

@vdimir
Copy link
Member

vdimir commented Jun 28, 2023

Right now, we are attempting to fix flaky tests in CI. PRs with any failures are blocked from being merged. We are currently collecting the fixes in the following pull request: #51494. Since this issue has been reproduced in stress tests, I might add the fixes from this PR to the PR addressing the failures, otherwise postpone the merging.

@qoega qoega merged commit e2241b8 into ClickHouse:master Jun 29, 2023
253 of 257 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can be tested Allows running workflows for external contributors manual approve Manual approve required to run CI pr-improvement Pull request with some product improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants