require finalize() call before d-tor for all writes buffers#50395
require finalize() call before d-tor for all writes buffers#50395CheSema merged 15 commits intoClickHouse:masterfrom
finalize() call before d-tor for all writes buffers#50395Conversation
|
This is an automated comment for commit 4d08df8 with description of existing statuses. It's updated for the latest CI running
|
|
strange, the build from fast test fails with 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) ``` |
19f4c20 to
d5b4ce2
Compare
79446d7 to
3bc4cad
Compare
finalize() call before d-tor for all writes buffers
|
|
||
| /// 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| /// 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 |
There was a problem hiding this comment.
Wow, that's a great idea about exceptions, I didn't think about it and tried to add try/catch in many places :)
Changelog category (leave one):
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