Skip to content

Commit f07cd85

Browse files
committed
fix: enable thread sanitizer testing
1 parent b22b3c4 commit f07cd85

14 files changed

Lines changed: 237 additions & 127 deletions

File tree

.github/workflows/build_release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
env:
5353
CC: clang
5454
CXX: clang++
55-
run: ci/scripts/build_paimon.sh $(pwd) false false Release
55+
run: ci/scripts/build_paimon.sh --source_dir "$(pwd)" --build_type Release
5656
- name: Show ccache statistics
5757
if: always()
5858
run: ccache -s
@@ -78,7 +78,7 @@ jobs:
7878
env:
7979
CC: gcc-14
8080
CXX: g++-14
81-
run: ci/scripts/build_paimon.sh $(pwd) false false Release
81+
run: ci/scripts/build_paimon.sh --source_dir "$(pwd)" --build_type Release
8282
- name: Show ccache statistics
8383
if: always()
8484
run: ccache -s

.github/workflows/clang_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
env:
5454
CC: clang
5555
CXX: clang++
56-
run: ci/scripts/build_paimon.sh $(pwd) false true
56+
run: ci/scripts/build_paimon.sh --source_dir "$(pwd)" --check_clang_tidy
5757
- name: Show ccache statistics
5858
if: always()
5959
run: ccache -s

.github/workflows/gcc8_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
env:
6969
CC: gcc-8
7070
CXX: g++-8
71-
run: ci/scripts/build_paimon.sh $(pwd)
71+
run: ci/scripts/build_paimon.sh --source_dir "$(pwd)"
7272
- name: Show ccache statistics
7373
if: always()
7474
run: ccache -s

.github/workflows/gcc_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
env:
5353
CC: gcc-14
5454
CXX: g++-14
55-
run: ci/scripts/build_paimon.sh $(pwd)
55+
run: ci/scripts/build_paimon.sh --source_dir "$(pwd)"
5656
- name: Show ccache statistics
5757
if: always()
5858
run: ccache -s

.github/workflows/test_with_sanitizer.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ jobs:
3535
timeout-minutes: 120
3636
strategy:
3737
fail-fast: false
38+
matrix:
39+
include:
40+
- sanitizer: asan-ubsan
41+
sanitizer_args: --enable_asan --enable_ubsan
42+
setup_rust: true
43+
- sanitizer: tsan
44+
sanitizer_args: --enable_tsan
45+
setup_rust: false
3846
steps:
3947
- name: Checkout paimon-cpp
4048
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
@@ -43,16 +51,20 @@ jobs:
4351
- name: Setup ccache
4452
uses: ./.github/actions/setup-ccache
4553
with:
46-
cache-key-prefix: ccache-sanitizer
54+
cache-key-prefix: ccache-${{ matrix.sanitizer }}
4755
- name: Install Rust toolchain (tantivy-fts)
56+
if: matrix.setup_rust
4857
shell: bash
4958
run: ci/scripts/setup_rust.sh
5059
- name: Build Paimon
5160
shell: bash
5261
env:
5362
CC: clang
5463
CXX: clang++
55-
run: ci/scripts/build_paimon.sh $(pwd) true
64+
run: >-
65+
ci/scripts/build_paimon.sh
66+
--source_dir "$(pwd)"
67+
${{ matrix.sanitizer_args }}
5668
- name: Show ccache statistics
5769
if: always()
5870
run: ccache -s

build_support/tsan-suppressions.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
18+
# Prebuilt shared libraries are not TSAN-instrumented. Suppress reports from the whole library.
19+
race:liblance_lib_rc.so
20+
thread:liblance_lib_rc.so
21+
race:liblumina.so
22+
race:libjindosdk_c.so.6

ci/scripts/build_paimon.sh

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,77 @@
1616

1717
set -eux
1818

19-
source_dir=${1}
20-
enable_sanitizer=${2:-false}
21-
check_clang_tidy=${3:-false}
22-
build_type=${4:-Debug}
19+
usage() {
20+
echo "Usage: $0 --source_dir <path> [--enable_asan] [--enable_ubsan] [--enable_tsan] [--check_clang_tidy] [--build_type <type>]"
21+
}
22+
23+
source_dir=""
24+
enable_asan="false"
25+
enable_ubsan="false"
26+
enable_tsan="false"
27+
check_clang_tidy="false"
28+
build_type="Debug"
29+
30+
while [[ $# -gt 0 ]]; do
31+
case "$1" in
32+
--source_dir)
33+
if [[ $# -lt 2 ]]; then
34+
echo "Missing value for --source_dir" >&2
35+
usage >&2
36+
exit 1
37+
fi
38+
source_dir=$2
39+
shift 2
40+
;;
41+
--enable_asan)
42+
enable_asan="true"
43+
shift
44+
;;
45+
--enable_ubsan)
46+
enable_ubsan="true"
47+
shift
48+
;;
49+
--enable_tsan)
50+
enable_tsan="true"
51+
shift
52+
;;
53+
--check_clang_tidy)
54+
check_clang_tidy="true"
55+
shift
56+
;;
57+
--build_type)
58+
if [[ $# -lt 2 ]]; then
59+
echo "Missing value for --build_type" >&2
60+
usage >&2
61+
exit 1
62+
fi
63+
build_type=$2
64+
shift 2
65+
;;
66+
-h | --help)
67+
usage
68+
exit 0
69+
;;
70+
*)
71+
echo "Unknown argument: $1" >&2
72+
usage >&2
73+
exit 1
74+
;;
75+
esac
76+
done
77+
78+
if [[ -z "${source_dir}" ]]; then
79+
echo "--source_dir is required" >&2
80+
usage >&2
81+
exit 1
82+
fi
83+
84+
if [[ "${enable_asan}" == "true" && "${enable_tsan}" == "true" ]]; then
85+
echo "ASAN and TSAN cannot be enabled together" >&2
86+
usage >&2
87+
exit 1
88+
fi
89+
2390
build_dir="${source_dir}/build"
2491

2592
# Display ccache status if available
@@ -46,6 +113,9 @@ if [[ "${CC:-}" == *"gcc-8"* ]] || [[ "${CXX:-}" == *"g++-8"* ]]; then
46113
# Consider supporting Lance from source compilation in the future
47114
ENABLE_TANTIVY="OFF" # tantivy-fts (Rust FFI) is not built on the gcc-8 image.
48115
fi
116+
if [[ "${enable_tsan}" == "true" ]]; then
117+
ENABLE_TANTIVY="OFF" # Tantivy's Rust library is not TSAN-instrumented.
118+
fi
49119

50120
CMAKE_ARGS=(
51121
"-G Ninja"
@@ -58,11 +128,14 @@ CMAKE_ARGS=(
58128
"-DPAIMON_ENABLE_TANTIVY=${ENABLE_TANTIVY}"
59129
)
60130

61-
if [[ "${enable_sanitizer}" == "true" ]]; then
62-
CMAKE_ARGS+=(
63-
"-DPAIMON_USE_ASAN=ON"
64-
"-DPAIMON_USE_UBSAN=ON"
65-
)
131+
if [[ "${enable_asan}" == "true" ]]; then
132+
CMAKE_ARGS+=("-DPAIMON_USE_ASAN=ON")
133+
fi
134+
if [[ "${enable_ubsan}" == "true" ]]; then
135+
CMAKE_ARGS+=("-DPAIMON_USE_UBSAN=ON")
136+
fi
137+
if [[ "${enable_tsan}" == "true" ]]; then
138+
CMAKE_ARGS+=("-DPAIMON_USE_TSAN=ON")
66139
fi
67140

68141
cmake "${CMAKE_ARGS[@]}" "${source_dir}"

cmake_modules/BuildUtils.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,13 @@ function(add_paimon_lib LIB_NAME)
183183
if(NOT APPLE)
184184
set(SHARED_LINK_OPTIONS -Wl,--exclude-libs,ALL -Wl,-Bsymbolic
185185
-Wl,--gc-sections)
186-
# -z defs (--no-undefined) rejects the __asan_*/__ubsan_* symbols that
186+
# -z defs (--no-undefined) rejects the __asan_*/__tsan_*/__ubsan_* symbols that
187187
# sanitizer-instrumented shared libraries legitimately leave undefined
188188
# (they are resolved at load time from the executable's sanitizer
189189
# runtime). Only enforce it for non-sanitizer builds.
190-
if(NOT PAIMON_USE_ASAN AND NOT PAIMON_USE_UBSAN)
190+
if(NOT PAIMON_USE_ASAN
191+
AND NOT PAIMON_USE_TSAN
192+
AND NOT PAIMON_USE_UBSAN)
191193
list(APPEND SHARED_LINK_OPTIONS -Wl,-z,defs)
192194
endif()
193195
target_link_options(${LIB_NAME}_shared PRIVATE ${SHARED_LINK_OPTIONS})

0 commit comments

Comments
 (0)