To avoid undefined references in examples:
May 11 01:58:40 ld.lld-17: error: undefined symbol: DB::Context::hasTraceCollector() const
May 11 01:58:40 >>> referenced by ThreadStatus.cpp:132 (/build/src/Common/ThreadStatus.cpp:132)
May 11 01:58:40 >>> ThreadStatus.cpp.o:(DB::ThreadStatus::initGlobalProfiler(unsigned long, unsigned long)) in archive src/libclickhouse_common_iod.a
May 11 01:58:40 clang++-17: error: linker command failed with exit code 1 (use -v to see invocation)
Move it firstly into ThreadStatusExt and then do not try to use it from
the ThreadPool.
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
There are some places that make it possible to trigger use-after-free
from threads because some global variable had been destroyed before, for
example some logger.
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
There are lots of thread pools and simple local-vs-global is not enough
already, it is good to know which one in particular uses threads.
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
ThreadPool::setMaxThreads() can now start new threads (if there are scheduled jobs in the queue for them);
ThreadPool::setMaxFreeThreads() can now finish free threads.
Calling notify_one function with lock held would let the notified
thread immediately block again, and increase the lock contention.
This commit moves the calls of notify_one function out of critical
sections of ThreadPool, whose lock (ThreadPoolImpl::mutex) is most
extensively contended in some workloads.
- lots of static_cast
- add safe_cast
- types adjustments
- config
- IStorage::read/watch
- ...
- some TODO's (to convert types in future)
P.S. That was quite a journey...
v2: fixes after rebase
v3: fix conflicts after #42308 merged
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
When I tried to add cool new clang-tidy 14 warnings, I noticed that the
current clang-tidy settings already produce a ton of warnings. This
commit addresses many of these. Almost all of them were non-critical,
i.e. C vs. C++ style casts.