ClickHouse/programs
Robert Schulze 5a4f21c50f
Support for Clang Thread Safety Analysis (TSA)
- TSA is a static analyzer build by Google which finds race conditions
  and deadlocks at compile time.

- It works by associating a shared member variable with a
  synchronization primitive that protects it. The compiler can then
  check at each access if proper locking happened before. A good
  introduction are [0] and [1].

- TSA requires some help by the programmer via annotations. Luckily,
  LLVM's libcxx already has annotations for std::mutex, std::lock_guard,
  std::shared_mutex and std::scoped_lock. This commit enables them
  (--> contrib/libcxx-cmake/CMakeLists.txt).

- Further, this commit adds convenience macros for the low-level
  annotations for use in ClickHouse (--> base/defines.h). For
  demonstration, they are leveraged in a few places.

- As we compile with "-Wall -Wextra -Weverything", the required compiler
  flag "-Wthread-safety-analysis" was already enabled. Negative checks
  are an experimental feature of TSA and disabled
  (--> cmake/warnings.cmake). Compile times did not increase noticeably.

- TSA is used in a few places with simple locking. I tried TSA also
  where locking is more complex. The problem was usually that it is
  unclear which data is protected by which lock :-(. But there was
  definitely some weird code where locking looked broken. So there is
  some potential to find bugs.

*** Limitations of TSA besides the ones listed in [1]:

- The programmer needs to know which lock protects which piece of shared
  data. This is not always easy for large classes.

- Two synchronization primitives used in ClickHouse are not annotated in
  libcxx:
  (1) std::unique_lock: A releaseable lock handle often together with
      std::condition_variable, e.g. in solve producer-consumer problems.
  (2) std::recursive_mutex: A re-entrant mutex variant. Its usage can be
      considered a design flaw + typically it is slower than a standard
      mutex. In this commit, one std::recursive_mutex was converted to
      std::mutex and annotated with TSA.

- For free-standing functions (e.g. helper functions) which are passed
  shared data members, it can be tricky to specify the associated lock.
  This is because the annotations use the normal C++ rules for symbol
  resolution.

[0] https://clang.llvm.org/docs/ThreadSafetyAnalysis.html
[1] https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/42958.pdf
2022-06-20 16:13:25 +02:00
..
bash-completion Add ability to pass QueryKind via clickhouse-client/local (useful for debugging) 2022-05-19 07:19:27 +03:00
benchmark Enable clang-tidy modernize-deprecated-headers & hicpp-deprecated-headers 2022-05-09 08:23:33 +02:00
client Add ability to pass QueryKind via clickhouse-client/local (useful for debugging) 2022-05-19 07:19:27 +03:00
compressor fix crash when you use clickhouse-git-import with invalid parameter 2022-04-14 23:16:02 +08:00
copier Fix some more tests. 2022-06-01 15:21:47 +00:00
disks Fixe2: allow config path at any position 2022-06-06 16:52:58 +03:00
extract-from-config add system.zookeeper_log 2021-07-09 17:05:35 +03:00
format Activate clang-tidy warning "readability-container-contains" 2022-04-18 23:53:11 +02:00
git-import Activate clang-tidy warning "readability-container-contains" 2022-04-18 23:53:11 +02:00
install More consistent use of platform macros 2022-06-10 10:22:31 +02:00
keeper Support for Clang Thread Safety Analysis (TSA) 2022-06-20 16:13:25 +02:00
keeper-converter base should not depend on Common 2022-04-29 10:26:35 +08:00
library-bridge Support for Clang Thread Safety Analysis (TSA) 2022-06-20 16:13:25 +02:00
local Merge pull request #37326 from ClickHouse/fix-marks-cache-size-cfg 2022-05-19 20:20:25 +02:00
obfuscator Revert "Fix errors of CheckTriviallyCopyableMove type" 2022-06-07 13:53:10 +02:00
odbc-bridge Support for Clang Thread Safety Analysis (TSA) 2022-06-20 16:13:25 +02:00
server Merge branch 'master' of github.com:ClickHouse/ClickHouse into llvm-14 2022-06-01 22:09:58 +02:00
static-files-disk-uploader Fix error in static-files-disk-uploader 2022-05-24 01:38:17 +02:00
su Fix split build 2022-05-25 04:24:02 +02:00
clickhouse-split-helper Move all folders inside /dbms one level up (#9974) 2020-04-02 02:51:21 +03:00
CMakeLists.txt Add basic commands for disk tool (list-disks, list, move, remove, link, copy, read, write) + tests 2022-06-06 16:52:58 +03:00
config_tools.h.in Add basic commands for disk tool (list-disks, list, move, remove, link, copy, read, write) + tests 2022-06-06 16:52:58 +03:00
embed_binary.S.in Adds a better way to include binary resources 2021-06-09 14:03:30 -07:00
main.cpp More consistent use of platform macros 2022-06-10 10:22:31 +02:00