Skip to content

require finalize() call before d-tor for all writes buffers#50395

Merged
CheSema merged 15 commits intoClickHouse:masterfrom
CheSema:better-log
Jun 21, 2023
Merged

require finalize() call before d-tor for all writes buffers#50395
CheSema merged 15 commits intoClickHouse:masterfrom
CheSema:better-log

Conversation

@CheSema
Copy link
Copy Markdown
Member

@CheSema CheSema commented May 31, 2023

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

d-tor can be called without finalize() call only when exception happened.
Remove finalize() calls from compression buffers d-tors.

Continuation for #50274

Blocks #50907

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

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-not-for-changelog This PR should not be mentioned in the changelog label May 31, 2023
@robot-clickhouse-ci-2
Copy link
Copy Markdown
Contributor

robot-clickhouse-ci-2 commented May 31, 2023

This is an automated comment for commit 4d08df8 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🟢 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
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🟢 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

@CheSema
Copy link
Copy Markdown
Member Author

CheSema commented May 31, 2023

strange, the build from fast test fails with

2023.05.31 16:49:18.020907 [ 3401093 ] {} <Error> Application: Code: 137. DB::Exception: DiskFactory: the disk 's3_disk' has unknown disk type: s3: Cannot attach table `system`.`transactions_info_log` from metadata file /var/lib/clickhouse/store/919/919947d0-287e-4b77-9e05-124e38bafc57/transactions_info_log.sql from query ATTACH TABLE system.transactions_info_log UUID '39ef021f-4561-4646-a910-d7befd47097a' (`type` Enum8('Begin' = 1, 'Commit' = 2, 'Rollback' = 3, 'AddPart' = 10, 'LockPart' = 11, 'UnlockPart' = 12), `event_date` Date, `event_time` DateTime64(6), `thread_id` UInt64, `query_id` String, `tid` Tuple(UInt64, UInt64, UUID), `tid_hash` UInt64, `csn` UInt64, `database` String, `table` String, `uuid` UUID, `part` String) ENGINE = MergeTree PARTITION BY toYYYYMM(event_date) ORDER BY (event_date, event_time) SETTINGS index_granularity = 8192. (UNKNOWN_ELEMENT_IN_CONFIG), Stack trace (when copying this message, always include the lines below):
stack ``` 0. /fasttest-workspace/build/./contrib/llvm-project/libcxx/include/exception:134: Poco::Exception::Exception(String const&, int) @ 0x000000001342b5f2 in /home/ubuntu/work/local-ch/clickhouse.1 1. /fasttest-workspace/build/./src/Common/Exception.cpp:92: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x000000000d020ad5 in /home/ubuntu/work/local-ch/clickhouse.1 2. DB::Exception::Exception(int, FormatStringHelperImpl::type, std::type_identity::type>, String const&, String const&) @ 0x000000000878fffd in /home/ubuntu/work/local-ch/clickhouse.1 3. /fasttest-workspace/build/./src/Disks/DiskFactory.cpp:34: DB::DiskFactory::create(String const&, Poco::Util::AbstractConfiguration const&, String const&, std::shared_ptr, std::map, std::less, std::allocator>>> const&) const @ 0x000000001135e4d3 in /home/ubuntu/work/local-ch/clickhouse.1 4. /fasttest-workspace/build/./src/Disks/DiskSelector.cpp:49: DB::DiskSelector::initialize(Poco::Util::AbstractConfiguration const&, String const&, std::shared_ptr) @ 0x00000000114db2b9 in /home/ubuntu/work/local-ch/clickhouse.1 5. /fasttest-workspace/build/./contrib/llvm-project/libcxx/include/string:1499: DB::Context::getDiskSelector(std::lock_guard&) const @ 0x00000000114a755f in /home/ubuntu/work/local-ch/clickhouse.1 6. /fasttest-workspace/build/./src/Interpreters/Context.cpp:3409: DB::Context::getStoragePolicySelector(std::lock_guard&) const @ 0x0000000011492bd4 in /home/ubuntu/work/local-ch/clickhouse.1 7. /fasttest-workspace/build/./src/Interpreters/Context.cpp:3341: DB::Context::getStoragePolicy(String const&) const @ 0x00000000114a78d1 in /home/ubuntu/work/local-ch/clickhouse.1 8. /fasttest-workspace/build/./src/Storages/MergeTree/MergeTreeData.cpp:0: DB::MergeTreeData::getStoragePolicy() const @ 0x00000000126dca71 in /home/ubuntu/work/local-ch/clickhouse.1 9. /fasttest-workspace/build/./src/Storages/MergeTree/MergeTreeData.h:915: DB::MergeTreeData::initializeDirectoriesAndFormatVersion(String const&, bool, String const&, bool) @ 0x00000000126d86a1 in /home/ubuntu/work/local-ch/clickhouse.1 10. /fasttest-workspace/build/./src/Storages/StorageMergeTree.cpp:115: DB::StorageMergeTree::StorageMergeTree(DB::StorageID const&, String const&, DB::StorageInMemoryMetadata const&, bool, std::shared_ptr, String const&, DB::MergeTreeData::MergingParams const&, std::unique_ptr>, bool) @ 0x0000000012972af2 in /home/ubuntu/work/local-ch/clickhouse.1 11. /fasttest-workspace/build/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:1460: std::shared_ptr std::allocate_shared[abi:v15000], DB::StorageID const&, String const&, DB::StorageInMemoryMetadata&, bool const&, std::shared_ptr&, String&, DB::MergeTreeData::MergingParams&, std::unique_ptr>, bool const&, void>(std::allocator const&, DB::StorageID const&, String const&, DB::StorageInMemoryMetadata&, bool const&, std::shared_ptr&, String&, DB::MergeTreeData::MergingParams&, std::unique_ptr>&&, bool const&) @ 0x0000000012972459 in /home/ubuntu/work/local-ch/clickhouse.1 12. /fasttest-workspace/build/./src/Storages/MergeTree/registerStorageMergeTree.cpp:0: DB::create(DB::StorageFactory::Arguments const&) @ 0x000000001296f83a in /home/ubuntu/work/local-ch/clickhouse.1 13. /fasttest-workspace/build/./src/Storages/StorageFactory.cpp:225: DB::StorageFactory::get(DB::ASTCreateQuery const&, String const&, std::shared_ptr, std::shared_ptr, DB::ColumnsDescription const&, DB::ConstraintsDescription const&, bool) const @ 0x000000001235dd1b in /home/ubuntu/work/local-ch/clickhouse.1 14. /fasttest-workspace/build/./contrib/llvm-project/libcxx/include/string:2067: DB::createTableFromAST(DB::ASTCreateQuery, String const&, String const&, std::shared_ptr, bool) @ 0x00000000112e450b in /home/ubuntu/work/local-ch/clickhouse.1 15. /fasttest-workspace/build/./src/Databases/DatabaseOrdinary.cpp:0: DB::DatabaseOrdinary::loadTableFromMetadata(std::shared_ptr, String const&, DB::QualifiedTableName const&, std::shared_ptr const&, DB::LoadingStrictnessLevel) @ 0x00000000112ff4c6 in /home/ubuntu/work/local-ch/clickhouse.1 16. /fasttest-workspace/build/./src/Databases/TablesLoader.cpp:197: void std::__function::__policy_invoker::__call_impl>&, std::shared_ptr, std::vector> const&, unsigned long)::$_0, void ()>>(std::__function::__policy_storage const*) @ 0x000000001158a4d0 in /home/ubuntu/work/local-ch/clickhouse.1 17. /fasttest-workspace/build/./base/base/../base/wide_integer_impl.h:796: ThreadPoolImpl>::worker(std::__list_iterator, void*>) @ 0x000000000d0da200 in /home/ubuntu/work/local-ch/clickhouse.1 18. /fasttest-workspace/build/./src/Common/ThreadPool.cpp:0: ThreadFromGlobalPoolImpl::ThreadFromGlobalPoolImpl>::scheduleImpl(std::function, Priority, std::optional, bool)::'lambda0'()>(void&&)::'lambda'()::operator()() @ 0x000000000d0dcf59 in /home/ubuntu/work/local-ch/clickhouse.1 19. /fasttest-workspace/build/./base/base/../base/wide_integer_impl.h:796: ThreadPoolImpl::worker(std::__list_iterator) @ 0x000000000d0d7c3e in /home/ubuntu/work/local-ch/clickhouse.1 20. /fasttest-workspace/build/./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:302: void* std::__thread_proxy[abi:v15000]>, void ThreadPoolImpl::scheduleImpl(std::function, Priority, std::optional, bool)::'lambda0'()>>(void*) @ 0x000000000d0db68e in /home/ubuntu/work/local-ch/clickhouse.1 21. ? @ 0x00007fe612353b43 in ? 22. ? @ 0x00007fe6123e5a00 in ? (version 23.5.1.1) ```

@CheSema CheSema force-pushed the better-log branch 7 times, most recently from 19f4c20 to d5b4ce2 Compare June 5, 2023 08:48
@CheSema CheSema force-pushed the better-log branch 6 times, most recently from 79446d7 to 3bc4cad Compare June 14, 2023 19:33
@CheSema CheSema marked this pull request as ready for review June 16, 2023 14:38
@CheSema CheSema changed the title add error log message when no finalize called before d-tor require finalize call before d-tor for all writes buffers Jun 16, 2023
@CheSema CheSema changed the title require finalize call before d-tor for all writes buffers require finalize() call before d-tor for all writes buffers Jun 16, 2023
@Avogar Avogar self-assigned this Jun 16, 2023

/// Simply do nothing, can be used to measure amount of written bytes.
class NullWriteBuffer : public BufferWithOwnMemory<WriteBuffer>, boost::noncopyable
class NullWriteBuffer : public WriteBuffer, boost::noncopyable
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I remember that we have a butch of WriteBuffers that don't require finalize at all. Like NullWriteBuffer, WriteBufferFromArena, MemoryWriteBuffer, WriteBufferFromPocoSocket, etc. and sometimes we use just base class WriteBuffer to read from pointer. I see you added WriteBufferFromPointer for this purpose, but AFAIU we still have to call no-op finalize for them (otherwise there will be assert int ~WriteBuffer). In my old PR I tried to solve it by introcuding new base class WriteBufferWithoutFinalize that sets is_finalize_required flag in WriteBuffer to false and used it as base class instead of just WriteBuffer when needed. What do you think about it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it is good idea. It help to reduce the number of no-op finalize calls.
But I do not address this in that PR. Your proposal I could do in the following changes.

Comment on lines +16 to +17
/// It is totally OK to destroy instance without finalization when an exception occurs
/// However it is suspicious to destroy instance without finalization at the green path
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wow, that's a great idea about exceptions, I didn't think about it and tried to add try/catch in many places :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants