USearch Integration#1
USearch Integration#1davvard wants to merge 7 commits intorschu1ze:hnsw-indexfrom davvard:hnsw-index
Conversation
|
Copypasting some notes from elsewhere: "There are a few things to polish:
|
|
@davvard Will look at this PR now but may I ask you first to
The main reason I am asking (besides a simpler code flow) is that my fork of ClickHouse (current PR) has no CI tests configured, we would only know about issues with tests when I'd make another PR from my fork to to upstream. |
|
It would be nice if you could also update the docs in docs/en/engines/table-engines/mergetree-family/annindexes.md. |
rschu1ze
left a comment
There was a problem hiding this comment.
Looks good upon a first look. That the implementation on ClickHouse side is very similar to Annoy certainly helps :-)
| #include <IO/WriteHelpers.h> | ||
| #include <IO/ReadHelpers.h> | ||
| #include <numeric> | ||
| #include <IO/ReadHelpers.h> |
There was a problem hiding this comment.
It's good practice to #include the corresponding header file (MergeTreeIndices.h) first.
EDIT: I guess that was clang-format's fault. Please turn it off (*) or make it use the .clang-format file in the top-level directory of the ClickHouse repository.
(*) ClickHouse CI is quite relaxed about code formatting. It only complains about rough misformatting (trailing spaces, braces not being on a new line) but it does not run clang-format.
| size_t getDimensions() const; | ||
| }; | ||
|
|
||
| template <unum::usearch::metric_kind_t metric_ak> |
There was a problem hiding this comment.
Minor: What does ak stand for? Would just metric work as well?
There was a problem hiding this comment.
OK I will write metric in the new PR
| # include <Common/typeid_cast.h> | ||
|
|
||
|
|
||
| using namespace unum::usearch; |
There was a problem hiding this comment.
Maybe a matter of personal preference, but I generally prefer not using using namespace as it hides some details. (and besides using namespace, I still find a lot of unum::usearch::... in this file)
There was a problem hiding this comment.
Yes, I prefer not to use using namespace too. It appeared by accident
Update check-large-objects.sh to be language neutral
Fixes integration test_reload_certificate/test.py::test_first_than_second_cert --- E Exception: Sanitizer assert found for instance ================== E WARNING: ThreadSanitizer: data race (pid=1) E Write of size 8 at 0x7b2800025d30 by thread T2 (mutexes: write M0, write M1): E #0 free <null> (clickhouse+0x709a3e5) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #1 CRYPTO_free build_docker/./contrib/openssl/crypto/mem.c:282:5 (clickhouse+0x2015f8ea) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #2 EVP_PKEY_free build_docker/./contrib/openssl/crypto/evp/p_lib.c:1809:5 (clickhouse+0x2012a751) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#3 Poco::Crypto::EVPPKey::~EVPPKey() build_docker/./base/poco/Crypto/src/EVPPKey.cpp:121:17 (clickhouse+0x1d00ffa9) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#4 DB::CertificateReloader::Data::~Data() build_docker/./src/Server/CertificateReloader.h:71:12 (clickhouse+0x194fb42d) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#5 std::__1::default_delete<DB::CertificateReloader::Data const>::operator()[abi:v15000](DB::CertificateReloader::Data const*) const build_docker/./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:48:5 (clickhouse+0x194fb42d) E ClickHouse#6 std::__1::__shared_ptr_pointer<DB::CertificateReloader::Data const*, std::__1::default_delete<DB::CertificateReloader::Data const>, std::__1::allocator<DB::CertificateReloader::Data const>>::__on_zero_shared() build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:263:5 (clickhouse+0x194fb42d) E ClickHouse#7 std::__1::__shared_count::__release_shared[abi:v15000]() build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:174:9 (clickhouse+0x194fade0) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#8 std::__1::__shared_weak_count::__release_shared[abi:v15000]() build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:215:27 (clickhouse+0x194fade0) E ClickHouse#9 std::__1::shared_ptr<DB::CertificateReloader::Data const>::~shared_ptr[abi:v15000]() build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:702:23 (clickhouse+0x194fade0) E ClickHouse#10 std::__1::shared_ptr<DB::CertificateReloader::Data const>::operator=[abi:v15000](std::__1::shared_ptr<DB::CertificateReloader::Data const>&&) build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:723:9 (clickhouse+0x194fade0) E ClickHouse#11 MultiVersion<DB::CertificateReloader::Data>::set(std::__1::unique_ptr<DB::CertificateReloader::Data const, std::__1::default_delete<DB::CertificateReloader::Data const>>&&) build_docker/./src/Common/MultiVersion.h:76:25 (clickhouse+0x194fade0) E ClickHouse#12 DB::CertificateReloader::tryLoad(Poco::Util::AbstractConfiguration const&) build_docker/./src/Server/CertificateReloader.cpp:83:18 (clickhouse+0x194f94ca) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#13 DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_6::operator()(Poco::AutoPtr<Poco::Util::AbstractConfiguration>, bool) const build_docker/./programs/server/Server.cpp:1546:45 (clickhouse+0xf384df7) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#14 decltype(std::declval<DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_6&>()(std::declval<Poco::AutoPtr<Poco::Util::AbstractConfiguration>>(), std::declval<bool>())) std::__1::__invoke[abi:v15000]<DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_6&, Poco::AutoPtr<Poco::Util::AbstractConfiguration>, bool>(DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_6&, Poco::AutoPtr<Poco::Util::AbstractConfiguration>&&, bool&&) build_docker/./contrib/llvm-project/libcxx/include/__functional/invoke.h:394:23 (clickhouse+0xf3827a9) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#15 void std::__1::__invoke_void_return_wrapper<void, true>::__call<DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_6&, Poco::AutoPtr<Poco::Util::AbstractConfiguration>, bool>(DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_6&, Poco::AutoPtr<Poco::Util::AbstractConfiguration>&&, bool&&) build_docker/./contrib/llvm-project/libcxx/include/__functional/invoke.h:479:9 (clickhouse+0xf3827a9) E ClickHouse#16 std::__1::__function::__default_alloc_func<DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_6, void (Poco::AutoPtr<Poco::Util::AbstractConfiguration>, bool)>::operator()[abi:v15000](Poco::AutoPtr<Poco::Util::AbstractConfiguration>&&, bool&&) build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:235:12 (clickhouse+0xf3827a9) E ClickHouse#17 void std::__1::__function::__policy_invoker<void (Poco::AutoPtr<Poco::Util::AbstractConfiguration>, bool)>::__call_impl<std::__1::__function::__default_alloc_func<DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_6, void (Poco::AutoPtr<Poco::Util::AbstractConfiguration>, bool)>>(std::__1::__function::__policy_storage const*, Poco::AutoPtr<Poco::Util::AbstractConfiguration>&&, bool) build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:716:16 (clickhouse+0xf3827a9) E ClickHouse#18 std::__1::__function::__policy_func<void (Poco::AutoPtr<Poco::Util::AbstractConfiguration>, bool)>::operator()[abi:v15000](Poco::AutoPtr<Poco::Util::AbstractConfiguration>&&, bool&&) const build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:848:16 (clickhouse+0x19fd2cbe) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#19 std::__1::function<void (Poco::AutoPtr<Poco::Util::AbstractConfiguration>, bool)>::operator()(Poco::AutoPtr<Poco::Util::AbstractConfiguration>, bool) const build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:1187:12 (clickhouse+0x19fd2cbe) E ClickHouse#20 DB::ConfigReloader::reloadIfNewer(bool, bool, bool, bool) build_docker/./src/Common/Config/ConfigReloader.cpp:150:13 (clickhouse+0x19fd2cbe) E ClickHouse#21 DB::ConfigReloader::reload() build_docker/./src/Common/Config/ConfigReloader.h:51:21 (clickhouse+0xf38767c) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#22 DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_13::operator()() const build_docker/./programs/server/Server.cpp:1731:31 (clickhouse+0xf38767c) E ClickHouse#23 decltype(std::declval<DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_13&>()()) std::__1::__invoke[abi:v15000]<DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_13&>(DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_13&) build_docker/./contrib/llvm-project/libcxx/include/__functional/invoke.h:394:23 (clickhouse+0xf38767c) E ClickHouse#24 void std::__1::__invoke_void_return_wrapper<void, true>::__call<DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_13&>(DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_13&) build_docker/./contrib/llvm-project/libcxx/include/__functional/invoke.h:479:9 (clickhouse+0xf38767c) E ClickHouse#25 std::__1::__function::__default_alloc_func<DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_13, void ()>::operator()[abi:v15000]() build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:235:12 (clickhouse+0xf38767c) E ClickHouse#26 void std::__1::__function::__policy_invoker<void ()>::__call_impl<std::__1::__function::__default_alloc_func<DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)::$_13, void ()>>(std::__1::__function::__policy_storage const*) build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:716:16 (clickhouse+0xf38767c) E ClickHouse#27 std::__1::__function::__policy_func<void ()>::operator()[abi:v15000]() const build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:848:16 (clickhouse+0x16907aa0) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#28 std::__1::function<void ()>::operator()() const build_docker/./contrib/llvm-project/libcxx/include/__functional/function.h:1187:12 (clickhouse+0x16907aa0) E ClickHouse#29 DB::Context::reloadConfig() const build_docker/./src/Interpreters/Context.cpp:4357:5 (clickhouse+0x16907aa0) E ClickHouse#30 DB::InterpreterSystemQuery::execute() build_docker/./src/Interpreters/InterpreterSystemQuery.cpp:577:29 (clickhouse+0x17e78c19) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#31 DB::executeQueryImpl(char const*, char const*, std::__1::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) build_docker/./src/Interpreters/executeQuery.cpp:1195:40 (clickhouse+0x17e3e462) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#32 DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum) build_docker/./src/Interpreters/executeQuery.cpp:1374:26 (clickhouse+0x17e39837) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#33 DB::TCPHandler::runImpl() build_docker/./src/Server/TCPHandler.cpp:518:54 (clickhouse+0x195cc651) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#34 DB::TCPHandler::run() build_docker/./src/Server/TCPHandler.cpp:2329:9 (clickhouse+0x195e8707) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#35 Poco::Net::TCPServerConnection::start() build_docker/./base/poco/Net/src/TCPServerConnection.cpp:43:3 (clickhouse+0x1d00d942) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#36 Poco::Net::TCPServerDispatcher::run() build_docker/./base/poco/Net/src/TCPServerDispatcher.cpp:115:20 (clickhouse+0x1d00e1b1) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#37 Poco::PooledThread::run() build_docker/./base/poco/Foundation/src/ThreadPool.cpp:188:14 (clickhouse+0x1d20f2e6) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#38 Poco::(anonymous namespace)::RunnableHolder::run() build_docker/./base/poco/Foundation/src/Thread.cpp:45:11 (clickhouse+0x1d20d5af) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#39 Poco::ThreadImpl::runnableEntry(void*) build_docker/./base/poco/Foundation/src/Thread_POSIX.cpp:335:27 (clickhouse+0x1d20ba69) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E E Previous atomic write of size 4 at 0x7b2800025d30 by thread T3 (mutexes: write M2): E #0 CRYPTO_DOWN_REF build_docker/./contrib/openssl/include/internal/refcount.h:51:12 (clickhouse+0x2012a6e6) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E #1 EVP_PKEY_free build_docker/./contrib/openssl/crypto/evp/p_lib.c:1795:5 (clickhouse+0x2012a6e6) E #2 ssl_cert_clear_certs build_docker/./contrib/openssl/ssl/ssl_cert.c:246:9 (clickhouse+0x1ffafd37) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#3 ssl_cert_free build_docker/./contrib/openssl/ssl/ssl_cert.c:277:5 (clickhouse+0x1ffafd37) E ClickHouse#4 ossl_ssl_connection_free build_docker/./contrib/openssl/ssl/ssl_lib.c:1458:5 (clickhouse+0x1ffba6af) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#5 SSL_free build_docker/./contrib/openssl/ssl/ssl_lib.c:1417:9 (clickhouse+0x1ffb920e) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#6 Poco::Net::SecureSocketImpl::reset() build_docker/./base/poco/NetSSL_OpenSSL/src/SecureSocketImpl.cpp:583:3 (clickhouse+0x1cfaac60) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#7 Poco::Net::SecureSocketImpl::~SecureSocketImpl() build_docker/./base/poco/NetSSL_OpenSSL/src/SecureSocketImpl.cpp:80:3 (clickhouse+0x1cfaac60) E ClickHouse#8 Poco::Net::SecureStreamSocketImpl::~SecureStreamSocketImpl() build_docker/./base/poco/NetSSL_OpenSSL/src/SecureStreamSocketImpl.cpp:52:1 (clickhouse+0x1cfb15dd) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#9 Poco::Net::SecureStreamSocketImpl::~SecureStreamSocketImpl() build_docker/./base/poco/NetSSL_OpenSSL/src/SecureStreamSocketImpl.cpp:43:1 (clickhouse+0x1cfb15dd) E ClickHouse#10 Poco::RefCountedObject::release() const build_docker/./base/poco/Foundation/include/Poco/RefCountedObject.h:86:13 (clickhouse+0x1cffc81e) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#11 Poco::Net::Socket::~Socket() build_docker/./base/poco/Net/src/Socket.cpp:68:10 (clickhouse+0x1cffc81e) E ClickHouse#12 Poco::Net::StreamSocket::~StreamSocket() build_docker/./base/poco/Net/src/StreamSocket.cpp:63:1 (clickhouse+0x1d009c39) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#13 Poco::Net::TCPConnectionNotification::~TCPConnectionNotification() build_docker/./base/poco/Net/src/TCPServerDispatcher.cpp:43:2 (clickhouse+0x1d00ef50) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#14 Poco::Net::TCPConnectionNotification::~TCPConnectionNotification() build_docker/./base/poco/Net/src/TCPServerDispatcher.cpp:42:2 (clickhouse+0x1d00ef50) E ClickHouse#15 Poco::RefCountedObject::release() const build_docker/./base/poco/Foundation/include/Poco/RefCountedObject.h:86:13 (clickhouse+0x1d00e203) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#16 Poco::AutoPtr<Poco::Notification>::~AutoPtr() build_docker/./base/poco/Foundation/include/Poco/AutoPtr.h:91:19 (clickhouse+0x1d00e203) E ClickHouse#17 Poco::Net::TCPServerDispatcher::run() build_docker/./base/poco/Net/src/TCPServerDispatcher.cpp:122:3 (clickhouse+0x1d00e203) E ClickHouse#18 Poco::PooledThread::run() build_docker/./base/poco/Foundation/src/ThreadPool.cpp:188:14 (clickhouse+0x1d20f2e6) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#19 Poco::(anonymous namespace)::RunnableHolder::run() build_docker/./base/poco/Foundation/src/Thread.cpp:45:11 (clickhouse+0x1d20d5af) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E ClickHouse#20 Poco::ThreadImpl::runnableEntry(void*) build_docker/./base/poco/Foundation/src/Thread_POSIX.cpp:335:27 (clickhouse+0x1d20ba69) (BuildId: 706d92b17db171493f293d517643f726ee1b7b1e) E
This commit adresses below leaksan find. I tried to reproduce this locally but 02802_clickhouse_disks_s3_copy.sh but couldn't. clickhouse-disks did not do anything useful (it would not even print logging), neither with a standard build nor with a leaksan build. Could not find further documentation of it or even what this tool is supposed to do, perhaps it is just for internal use. Also, - line numbers in the leaksan report were partially missing, - I am not really sure how Sha256HMACOpenSSLImpl::Calculate is calling into hmac_init (there must be some sort of static initialization somewhere but I did not find it), and - my fix is in a weird place due to other restrictions (see the commit in the aws-sdk-cpp contrib repo). The chance that this fix fixes the leak are low. If it doesn't work, add "# Tag no-asan" + a comment to 02802_clickhouse_disks_s3_copy.sh and don't worry further. EDIT: The commit fixes the issue, everything is good. https://s3.amazonaws.com/clickhouse-test-reports/59870/b452e3d1ab87b8cc5810693aeea28f69ad28d671/stateless_tests__asan__[3_4].html 2024-03-19 08:34:03 ================================================================= 2024-03-19 08:34:03 ==13149==ERROR: LeakSanitizer: detected memory leaks 2024-03-19 08:34:03 2024-03-19 08:34:03 Direct leak of 904 byte(s) in 1 object(s) allocated from: 2024-03-19 08:34:03 #0 0x55f9cb5a18ee in malloc (/usr/bin/clickhouse+0xa9a48ee) (BuildId: b3766b865d6580f6dcba75acf37673d4aeedc2b6) 2024-03-19 08:34:03 #1 0x55fa01e34070 in CRYPTO_malloc build_docker/./contrib/openssl/crypto/mem.c:202:11 2024-03-19 08:34:03 #2 0x55fa01e34070 in CRYPTO_zalloc build_docker/./contrib/openssl/crypto/mem.c:222:11 2024-03-19 08:34:03 ClickHouse#3 0x55fa01d6dcca in ossl_err_get_state_int build_docker/./contrib/openssl/crypto/err/err.c:691:17 2024-03-19 08:34:03 ClickHouse#4 0x55fa01d71748 in ERR_set_mark build_docker/./contrib/openssl/crypto/err/err_mark.c:19:10 2024-03-19 08:34:03 ClickHouse#5 0x55fa01f4735b in ossl_prov_digest_load_from_params build_docker/./contrib/openssl/providers/common/provider_util.c:194:5 2024-03-19 08:34:03 ClickHouse#6 0x55fa01ff467a in hmac_set_ctx_params build_docker/./contrib/openssl/providers/implementations/macs/hmac_prov.c:307:10 2024-03-19 08:34:03 ClickHouse#7 0x55fa01ff3ef2 in hmac_init build_docker/./contrib/openssl/providers/implementations/macs/hmac_prov.c:169:37 2024-03-19 08:34:03 ClickHouse#8 0x55f9fb83c75b in Aws::Utils::Crypto::Sha256HMACOpenSSLImpl::Calculate(Aws::Utils::Array<unsigned char> const&, Aws::Utils::Array<unsigned char> const&) (/usr/bin/clickhouse+0x3ac3f75b) (BuildId: b3766b865d6580f6dcba75acf37673d4aeedc2b6) 2024-03-19 08:34:03 ClickHouse#9 0x55f9fb82ebeb in Aws::Utils::Crypto::Sha256HMAC::Calculate(Aws::Utils::Array<unsigned char> const&, Aws::Utils::Array<unsigned char> const&) (/usr/bin/clickhouse+0x3ac31beb) (BuildId: b3766b865d6580f6dcba75acf37673d4aeedc2b6) 2024-03-19 08:34:03 ClickHouse#10 0x55f9fb6d5afd in Aws::Client::AWSAuthV4Signer::ComputeHash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) const (/usr/bin/clickhouse+0x3aad8afd) (BuildId: b3766b865d6580f6dcba75acf37673d4aeedc2b6) 2024-03-19 08:34:03 ClickHouse#11 0x55f9fb6e0bad in Aws::Client::AWSAuthV4Signer::SignRequest(Aws::Http::HttpRequest&, char const*, char const*, bool) const (/usr/bin/clickhouse+0x3aae3bad) (BuildId: b3766b865d6580f6dcba75acf37673d4aeedc2b6) 2024-03-19 08:34:03 ClickHouse#12 0x55f9fb72651d in bool smithy::components::tracing::TracingUtils::MakeCallWithTiming<bool>(std::__1::function<bool ()>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, smithy::components::tracing::Meter const&, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>>&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) (/usr/bin/clickhouse+0x3ab2951d) (BuildId: b3766b865d6580f6dcba75acf37673d4aeedc2b6) 2024-03-19 08:34:03 ClickHouse#13 0x55f9fb70adcb in Aws::Client::AWSClient::AttemptOneRequest(std::__1::shared_ptr<Aws::Http::HttpRequest> const&, Aws::AmazonWebServiceRequest const&, char const*, char const*, char const*) const (/usr/bin/clickhouse+0x3ab0ddcb) (BuildId: b3766b865d6580f6dcba75acf37673d4aeedc2b6) 2024-03-19 08:34:03 ClickHouse#14 0x55f9fb6fdb17 in Aws::Client::AWSClient::AttemptExhaustively(Aws::Http::URI const&, Aws::AmazonWebServiceRequest const&, Aws::Http::HttpMethod, char const*, char const*, char cons
CI: https://s3.amazonaws.com/clickhouse-test-reports/75848/479ca9b0a40fa32074501bea7d9eb7d369f3ddd4/integration_tests__tsan__2_6_.html <details> <summary>Race</summary> ``` E Exception: Sanitizer assert found for instance ================== E WARNING: ThreadSanitizer: data race (pid=8) E Write of size 8 at 0x726000005c78 by thread T585 (mutexes: write M0, write M1): E #0 std::__1::enable_if<is_move_constructible<DB::SnapshotFileInfo*>::value && is_move_assignable<DB::SnapshotFileInfo*>::value, void>::type std::__1::swap[abi:ne180100]<DB::SnapshotFileInfo*>(DB::SnapshotFileInfo*&, DB::SnapshotFileInfo*&) build_docker/./contrib/llvm-project/libcxx/include/__utility/swap.h:44:7 (clickhouse+0x1dad0fb6) (BuildId: eb398fb9d76a60d418ba7222d10f730fae2208dc) E #1 std::__1::shared_ptr<DB::SnapshotFileInfo>::swap[abi:ne180100](std::__1::shared_ptr<DB::SnapshotFileInfo>&) build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:694:5 (clickhouse+0x1dad0fb6) E #2 std::__1::shared_ptr<DB::SnapshotFileInfo>::operator=[abi:ne180100](std::__1::shared_ptr<DB::SnapshotFileInfo>&&) build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:663:32 (clickhouse+0x1dad0fb6) E ClickHouse#3 DB::KeeperStateMachine<DB::KeeperStorage<DB::SnapshotableHashTable<DB::KeeperMemNode>>>::save_logical_snp_obj(nuraft::snapshot&, unsigned long&, nuraft::buffer&, bool, bool) build_docker/./src/Coordination/KeeperStateMachine.cpp:846:30 (clickhouse+0x1dad0fb6) E Previous read of size 8 at 0x726000005c78 by thread T572: E #0 std::__1::shared_ptr<DB::SnapshotFileInfo>::shared_ptr[abi:ne180100](std::__1::shared_ptr<DB::SnapshotFileInfo> const&) build_docker/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:565:82 (clickhouse+0x1daea9b2) (BuildId: eb398fb9d76a60d418ba7222d10f730fae2208dc) E #1 DB::KeeperStateMachine<DB::KeeperStorage<DB::SnapshotableHashTable<DB::KeeperMemNode>>>::create_snapshot(nuraft::snapshot&, std::__1::function<void (bool&, std::__1::shared_ptr<std::exception>&)>&)::'lambda'(std::__1::variant<std::__1::shared_ptr<DB::KeeperStorageSnapshot<DB::KeeperStorage<DB::SnapshotableHashTable<DB::KeeperMemNode>>>>, std::__1::shared_ptr<DB::KeeperStorageSnapshot<DB::KeeperStorage<DB::RocksDBContainer<DB::KeeperRocksNode>>>>>&&, bool)::operator()(std::__1::variant<std::__1::shared_ptr<DB::KeeperStorageSnapshot<DB::KeeperStorage<DB::SnapshotableHashTable<DB::KeeperMemNode>>>>, std::__1::shared_ptr<DB::KeeperStorageSnapshot<DB::KeeperStorage<DB::RocksDBContainer<DB::KeeperRocksNode>>>>>&&, bool) const build_docker/./src/Coordination/KeeperStateMachine.cpp:803:22 (clickhouse+0x1daea9b2) ``` </details> v2: guard latest_snapshot_meta and latest_snapshot_buf as well (thanks to @davenger)
CI found [1] data-race:
WARNING: ThreadSanitizer: data race (pid=2462)
Write of size 8 at 0x7250003046d8 by thread T638:
#0 std::__1::unique_ptr<ThreadFromGlobalPoolImpl<true, true>, std::__1::default_delete<ThreadFromGlobalPoolImpl<true, true>>>::reset[abi:ne190107](ThreadFromGlobalPoolImpl<true, true>*) build_docker/./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:290:20 (clickhouse+0x1b7cb690) (BuildId: 4a160c0aae7301fdf3b5d5fc2cec3707e5318bfa)
#1 std::__1::unique_ptr<ThreadFromGlobalPoolImpl<true, true>, std::__1::default_delete<ThreadFromGlobalPoolImpl<true, true>>>::operator=[abi:ne190107](std::__1::unique_ptr<ThreadFromGlobalPoolImpl<true, true>, std::__1::default_delete<ThreadFromGlobalPoolImpl<true, true>>>&&) build_docker/./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:232:5 (clickhouse+0x1b7cb690)
#2 DB::ObjectStorageQueueMetadata::startup() build_docker/./src/Storages/ObjectStorageQueue/ObjectStorageQueueMetadata.cpp:173:32 (clickhouse+0x1b7cb690)
ClickHouse#3 DB::StorageObjectStorageQueue::startup() build_docker/./src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp:269:25 (clickhouse+0x1b89f8d6) (BuildId: 4a160c0aae7301fdf3b5d5fc2cec3707e5318bfa)
Previous read of size 8 at 0x7250003046d8 by thread T659:
#0 std::__1::unique_ptr<ThreadFromGlobalPoolImpl<true, true>, std::__1::default_delete<ThreadFromGlobalPoolImpl<true, true>>>::operator bool[abi:ne190107]() const build_docker/./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:279:19 (clickhouse+0x1b7cb4b8) (BuildId: 4a160c0aae7301fdf3b5d5fc2cec3707e5318bfa)
#1 DB::ObjectStorageQueueMetadata::startup() build_docker/./src/Storages/ObjectStorageQueue/ObjectStorageQueueMetadata.cpp:172:10 (clickhouse+0x1b7cb4b8)
#2 DB::StorageObjectStorageQueue::startup() build_docker/./src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp:269:25 (clickhouse+0x1b89f8d6) (BuildId: 4a160c0aae7301fdf3b5d5fc2cec3707e5318bfa)
[1]: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=77841&sha=42886968f1af877d77394c74cf07e0bf9dcbda45&name_0=PR&name_1=Integration+tests+%28tsan%2C+6%2F6%29
The reason is pretty obvious, the tables in test_registry shares the
same metadata object and on server restart may try to initialize it
twice, that leads to a data-race above.
…path)
This time I tested it with sanitizers:
$ ../tests/clickhouse-test shebang
Using queries from '/src/ch/clickhouse/tests/queries' directory
Connecting to ClickHouse server... OK
Connected to server 25.7.1.1 @ 9042a93 master
Found 1 parallel tests and 0 sequential tests
Running about 1 stateless tests (Process-3).
02203_shebang: [ FAIL ] 0.33 sec.
Reason: having stderror:
Path: /src/ch/clickhouse/tests/queries/0_stateless/test_ggjjtc06/clickhouse-351von_4.10890
==================
WARNING: ThreadSanitizer: data race (pid=10890)
Write of size 4 at 0x5555569e9718 by thread T2:
#0 thread2_func <null> (test-tsan+0xe7f68)
Previous write of size 4 at 0x5555569e9718 by thread T1:
#0 thread1_func <null> (test-tsan+0xe7f28)
Location is global 'shared_var' of size 4 at 0x5555569e9718 (test-tsan+0x1495718)
Thread T2 (tid=10893, running) created by main thread at:
#0 pthread_create /src/llvm/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1051:3 (test-tsan+0x640da)
#1 main <null> (test-tsan+0xe7fc5)
Thread T1 (tid=10892, finished) created by main thread at:
#0 pthread_create /src/llvm/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1051:3 (test-tsan+0x640da)
#1 main <null> (test-tsan+0xe7fae)
SUMMARY: ThreadSanitizer: data race (/tmp/test-tsan+0xe7f68) in thread2_func
==================
ThreadSanitizer: reported 1 warnings
stdout:
1
Database: test_ggjjtc06
Having 1 errors! 0 tests passed. 0 tests skipped. 0.34 s elapsed (Process-3).
All tests have finished.
And "Fatal" logs:
$ ../tests/clickhouse-test shebang
Using queries from '/src/ch/clickhouse/tests/queries' directory
Connecting to ClickHouse server... OK
Connected to server 25.7.1.1 @ 9042a93 master
Found 1 parallel tests and 0 sequential tests
Running about 1 stateless tests (Process-3).
02203_shebang: [ FAIL ] 0.33 sec.
Reason: having stderror:
Path: /src/ch/clickhouse/tests/queries/0_stateless/test_grqdqc9f/clickhouse-p8a4uip4
foo
stdout:
1
Having 1 errors! 0 tests passed. 0 tests skipped. 0.34 s elapsed (Process-3).
All tests have finished.
Fixes: ClickHouse#82234
Otherwise it may lead to data-race:
WARNING: ThreadSanitizer: data race (pid=26127)
Write of size 6 at 0x7298000099e8 by main thread:
0 __tsan_memcpy <null> (clickhouse-82444-tsan+0x8be71be) (BuildId: e5eeeb8fc2a0ab65c098bb1f3db89853f2439448)
1 DB::SettingsTraits::Data::operator=(DB::SettingsTraits::Data const&) ci/tmp/build/./src/Core/Settings.cpp:6978:1 (clickhouse-82444-tsan+0x192ae4f9) (BuildId: e5eeeb8fc2a0ab65c098bb1f3db89853f2439448)
2 DB::BaseSettings<DB::SettingsTraits>::operator=(DB::BaseSettings<DB::SettingsTraits> const&) ci/tmp/build/./src/Core/BaseSettings.h:109:60 (clickhouse-82444-tsan+0x190f2bcc) (BuildId: e5eeeb8fc2a0ab65c098bb1f3db89853f2439448)
3 DB::SettingsImpl::operator=(DB::SettingsImpl const&) ci/tmp/build/./src/Core/Settings.cpp:6984:8 (clickhouse-82444-tsan+0x190f2bcc)
4 DB::Settings::operator=(DB::Settings const&) ci/tmp/build/./src/Core/Settings.cpp:7191:11 (clickhouse-82444-tsan+0x190f2bcc)
5 DB::Context::setSettings(DB::Settings const&) ci/tmp/build/./src/Interpreters/Context.cpp:2635:15 (clickhouse-82444-tsan+0x1aa94c0a) (BuildId: e5eeeb8fc2a0ab65c098bb1f3db89853f2439448)
6 DB::ClientBase::processParsedSingleQuery(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::shared_ptr<DB::IAST>, bool&, unsigned long)::$_0::operator()() const ci/tmp/build/./src/Client/ClientBase.cpp:2184:9 (clickhouse-82444-tsan+0x1df0f4d7) (BuildId: e5eeeb8fc2a0ab65c098bb1f3db89853f2439448)
7 BasicScopeGuard<DB::ClientBase::processParsedSingleQuery(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::shared_ptr<DB::IAST>, bool&, unsigned long)::$_0>::invoke() ci/tmp/build/./base/base/../base/scope_guard.h:101:9 (clickhouse-82444-tsan+0x1df0f4d7)
8 BasicScopeGuard<DB::ClientBase::processParsedSingleQuery(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::shared_ptr<DB::IAST>, bool&, unsigned long)::$_0>::~BasicScopeGuard() ci/tmp/build/./base/base/../base/scope_guard.h:50:26 (clickhouse-82444-tsan+0x1df0f4d7)
9 DB::ClientBase::processParsedSingleQuery(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::shared_ptr<DB::IAST>, bool&, unsigned long) ci/tmp/build/./src/Client/ClientBase.cpp:2249:5 (clickhouse-82444-tsan+0x1df021ca) (BuildId: e5eeeb8fc2a0ab65c098bb1f3db89853f2439448)
Previous read of size 1 at 0x7298000099e8 by thread T4:
#0 DB::SettingFieldNumber<bool>::operator bool() const ci/tmp/build/./src/Core/SettingsFields.h:40:36 (clickhouse-82444-tsan+0x1b114e5f) (BuildId: e5eeeb8fc2a0ab65c098bb1f3db89853f2439448)
#1 DB::ThreadStatus::finalizePerformanceCounters() ci/tmp/build/./src/Interpreters/ThreadStatusExt.cpp:547:17 (clickhouse-82444-tsan+0x1b114e5f)
#2 DB::ThreadStatus::detachFromGroup() ci/tmp/build/./src/Interpreters/ThreadStatusExt.cpp:375:5 (clickhouse-82444-tsan+0x1b113aec) (BuildId: e5eeeb8fc2a0ab65c098bb1f3db89853f2439448)
ClickHouse#3 DB::CurrentThread::detachFromGroupIfNotDetached() ci/tmp/build/./src/Interpreters/ThreadStatusExt.cpp:716:21 (clickhouse-82444-tsan+0x1b1119b3) (BuildId: e5eeeb8fc2a0ab65c098bb1f3db89853f2439448)
ClickHouse#4 DB::ThreadGroupSwitcher::~ThreadGroupSwitcher() ci/tmp/build/./src/Interpreters/ThreadStatusExt.cpp:261:9 (clickhouse-82444-tsan+0x1b1119b3)
ClickHouse#5 DB::ThreadPoolCallbackRunnerLocal<void, ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true>>, std::__1::function<void ()>>::operator()(std::__1::function<void ()>&&, Priority, std::__1::optional<unsigned long>)::'lambda'()::operator()() ci/tmp/build/./src/Common/threadPoolCallbackRunner.h:179:9 (clickhouse-82444-tsan+0x14beafde) (BuildId: e5eeeb8fc2a0ab65c098bb1f3db89853f2439448)
Thread T4 'ThreadPool' (tid=26133, running) created by thread T3 at:
...
12 DB::ThreadPoolCallbackRunnerLocal<void, ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true>>, std::__1::function<void ()>>::operator()(std::__1::function<void ()>&&, Priority, std::__1::optional<unsigned long>) ci/tmp/build/./src/Common/threadPoolCallbackRunner.h:188:22 (clickhouse-82444-tsan+0x14be522d) (BuildId: e5eeeb8fc2a0ab65c098bb1f3db89853f2439448)
13 DB::ParallelParsingInputFormat::scheduleParserThreadForUnitWithNumber(unsigned long) ci/tmp/build/./src/Processors/Formats/Impl/ParallelParsingInputFormat.h:287:9 (clickhouse-82444-tsan+0x1e495627) (BuildId: e5eeeb8fc2a0ab65c098bb1f3db89853f2439448)
14 DB::ParallelParsingInputFormat::segmentatorThreadFunction(std::__1::shared_ptr<DB::ThreadGroup>) ci/tmp/build/./src/Processors/Formats/Impl/ParallelParsingInputFormat.cpp:45:13 (clickhouse-82444-tsan+0x1e495627)
Refs: https://pastila.nl/?0001fdef/9a58e9d59c32d45100a481de26dccf68#T4iNrMFUnu4F2hWST5wLdQ==
==13==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 112 byte(s) in 1 object(s) allocated from:
#0 0x562de572644f in malloc (/home/ubuntu/actions-runner/_work/ClickHouse/ClickHouse/ci/tmp/unit_tests_dbms+0xb7c744f) (BuildId: ece9c88fdfe6a6e98d1a0ed8ab535e80c258c855)
#1 0x562e12f3f8d7 in get_testing_kernel_expression (/home/ubuntu/actions-runner/_work/ClickHouse/ClickHouse/ci/tmp/unit_tests_dbms+0x38fe08d7) (BuildId: ece9c88fdfe6a6e98d1a0ed8ab535e80c258c855)
CI: https://s3.amazonaws.com/clickhouse-test-reports/PRs/84084/a27e4fcb365a35641c75fc886c90dafc8418b812//unit_tests_asan/job.log
Add promql parser #1: Add contrib and build scripts
This PR implements the USearch integration. It's already feature-compatible with Annoy-backed vector-search, but can be easily extended to support more metrics, and allow on-the-fly quantization.