Repository navigation
Fix exception when querying system.rocksdb during concurrent table drop - #101108
Conversation
…drop `StorageSystemRocksDB::fillData` collects RocksDB tables in a first pass, but by the time it calls `getRocksDBStatistics`, the table may have been dropped. Skip the table instead of throwing a `LOGICAL_ERROR` exception. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100290&sha=672c551dd5b6b553a8c76d3fc13e823303b2a822&name_0=PR&name_1=Stress%20test%20%28amd_debug%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [938d2aa] Summary: ✅ AI ReviewSummaryThis PR fixes a real race around ClickHouse Rules
Final Verdict
|
Algunenano
left a comment
There was a problem hiding this comment.
I see multiple 3 other problematic spots related to this problem with rocksdb:
- StorageEmbeddedRocksDB.cpp::336: rocksdb_ptr->Write(...) in the mutation path: no lock on rocksdb_ptr_mx at all. If DROP runs concurrently with a mutation, this dereferences a null pointer.
- StorageEmbeddedRocksDB.cpp::401: rocksdb_ptr->CompactRange(...) in optimize: acquires the shared lock but doesn't check for null before dereferencing, unlike the other guarded sites (lines 833-835, 842-844, 961-964, 972-975 all do the null check).
- StorageEmbeddedRocksDB::684 — storage.rocksdb_ptr->NewIterator(...) in ReadFromEmbeddedRocksDB::initializePipeline: no lock at all, direct access to rocksdb_ptr.
I think we should use TSA anotations for rocksdb_ptr and make sure we check for null before dereferencing it
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
|
The test |
|
The flaky test failures in this PR ( |
…uarded accesses Add `TSA_GUARDED_BY(rocksdb_ptr_mx)` annotation to `rocksdb_ptr` and `TSA_NO_THREAD_SAFETY_ANALYSIS` to `initDB` (called from constructor and from `truncate` which already holds the lock). Fix three race conditions identified in review: - `mutate` DELETE path: `rocksdb_ptr->Write` had no lock — add `SharedLockGuard` + null check. - `optimize`: `rocksdb_ptr->CompactRange` had shared lock but no null check — add null check. - `ReadFromEmbeddedRocksDB::initializePipeline`: `rocksdb_ptr->NewIterator` had no lock — add `SharedLockGuard` + null check. Also protect `rocksdb_ptr` accesses in `EmbeddedRocksDBSink` and `EmbeddedRocksDBBulkSink` for consistency, and switch all shared locks from `std::shared_lock` to TSA-aware `SharedLockGuard`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Four concurrent loops for 10 seconds: - CREATE/INSERT/DROP cycle - SELECT from `system.rocksdb` - SELECT from the RocksDB table - OPTIMIZE on the RocksDB table Exercises the code paths fixed in this PR: `getRocksDBStatistics`, `initializePipeline`, and `optimize` racing with `drop`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Split flaky check and targeted check into separate roles: Flaky check — runs only new/modified tests from the PR with thread fuzzer enabled. Tests run in parallel with themselves (shared queue) to ensure new tests are parallel-safe under randomized thread ordering. Targeted check — runs previously failed and coverage-relevant tests with per-worker partitioning (--no-self-parallel) so the same test never runs concurrently on multiple workers, avoiding conflicts on shared resources (hardcoded users, roles, settings profiles, etc.). Both use --test-runs 50. Changes: - Add --no-self-parallel flag to clickhouse-test: partitions tests by name hash so all copies go to the same worker - Flaky check: only changed tests, thread fuzzer, shared queue - Targeted check: relevant tests, no thread fuzzer, per-worker queues, 50 runs, single clickhouse-test invocation - Restore original thread fuzzer parameters (reverts reductions from 06c945a and 9790435) - Add amd_binary to flaky check, use AMD_LARGE for targeted debug - Targeted check uses --flaky-check --no-self-parallel PRs affected by tests running in parallel with themselves: #102015 #101093 #99653 #101503 #101108 #101884 #100746 #101447 #100941 #101099 #100203 #96130 #102038
Split flaky check and targeted check into separate roles: Flaky check — runs only new/modified tests from the PR with thread fuzzer enabled. Tests can run in parallel with themselves (shared queue) to ensure new tests are parallel-safe. Targeted check — runs previously failed and coverage-relevant tests with per-worker partitioning (--no-self-parallel) so the same test never runs concurrently on multiple workers, avoiding conflicts on shared resources (hardcoded users, roles, settings profiles, etc.). Both use --test-runs 50. Changes: - Add --no-self-parallel flag to clickhouse-test: partitions tests by name hash so all copies go to the same worker - Flaky check: only changed tests, thread fuzzer, shared queue - Targeted check: relevant tests, no thread fuzzer, per-worker partitioning, 50 runs, single clickhouse-test invocation - Restore original thread fuzzer parameters - Change targeted check to arm_asan_ubsan on ARM_LARGE PRs affected by tests running in parallel with themselves: #102015 #101093 #99653 #101503 #101108 #101884 #100746 #101447 #100941 #101099 #100203 #96130
The raw pointer obtained via `GetSystemClock().get()` was taken from a temporary `shared_ptr` that was destroyed at the end of the full expression. After `lock.unlock()`, a concurrent `DROP TABLE` could destroy the `rocksdb_ptr` and its `Env`, so `GetCurrentTime` could be called through a dangling pointer. Keep the `shared_ptr` returned by `GetSystemClock` to extend ownership across the call. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Add the `use-rocksdb` tag back to `04094_rocksdb_system_table_race.sh` so the test is only scheduled on builds with `EmbeddedRocksDB` support. Tolerate expected `Table ... does not exist` errors in the `SELECT`, `OPTIMIZE`, and `system.rocksdb` workers with `|| true`, so they keep running for the full timeout instead of exiting on the first race under `set -o errexit`.
In `04094_rocksdb_system_table_race.sh`, the `wait` loop overwrote `status` on each failed `wait`, so the exit code reflected the **last** failing background job rather than the first one (contradicting the inline comment). Capture each `wait` result into `ec` and only update `status` while it is still zero, so the first non-zero exit code is preserved. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
@groeneai, fix the fuzzer finding, |
|
@alexey-milovidov — already addressed by PR #103928 ("Fix LOGICAL_ERROR Primary key type mismatch in DirectKeyValueJoin (STID 3436-4175)"). It's currently waiting on @vdimir's response to my 2026-05-04 question about whether we should keep the legacy-planner fix as a stopgap (no open removal PR for the legacy path; STID 3436-4175 still recurring chronically — 29 hits in last 30 days, latest 2026-05-04 12:22 UTC) or close the PR pending the new-analyzer-only direction. |
When a direct join between an `EmbeddedRocksDB` table and a subquery whose join key has a different type reaches `StorageEmbeddedRocksDB::getByKeys`, the existing defensive check threw `LOGICAL_ERROR` with the message "Primary key type mismatch, expected ..., got ...". This was inappropriate because the condition is reachable from a regular user query (the planner does not always insert a type conversion before a direct join, e.g. with `USING`), so it should surface as a user-facing `TYPE_MISMATCH` instead of a server-side logical error that aborts in debug builds. Found by AST fuzzer (amd_debug, targeted, old_compatibility) on ClickHouse#101108 Report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/101108/dbafc9d33a11336412d0f9ffdd53fbfbb560aa70/ast_fuzzer_amd_debug_targeted_old_compatibility/ Triggered by: SELECT * FROM (SELECT k AS key FROM t2__fuzz_22) AS t2 INNER JOIN rdb USING (key) ORDER BY key ASC NULLS LAST
…ics-race # Conflicts: # src/Storages/RocksDB/StorageEmbeddedRocksDB.cpp
LLVM Coverage Report
Changed lines: 75.00% (57/76) | lost baseline coverage: 2 line(s) · Uncovered code |
|
Hi @alexey-milovidov @Algunenano — while reviewing this PR I found the following:
Could you review the test PR and add the |
Split flaky check and targeted check into separate roles: Flaky check — runs only new/modified tests from the PR with thread fuzzer enabled. Tests run in parallel with themselves (shared queue) to ensure new tests are parallel-safe under randomized thread ordering. Targeted check — runs previously failed and coverage-relevant tests with per-worker partitioning (--no-self-parallel) so the same test never runs concurrently on multiple workers, avoiding conflicts on shared resources (hardcoded users, roles, settings profiles, etc.). Both use --test-runs 50. Changes: - Add --no-self-parallel flag to clickhouse-test: partitions tests by name hash so all copies go to the same worker - Flaky check: only changed tests, thread fuzzer, shared queue - Targeted check: relevant tests, no thread fuzzer, per-worker queues, 50 runs, single clickhouse-test invocation - Restore original thread fuzzer parameters (reverts reductions from 06c945a and 9790435) - Add amd_binary to flaky check, use AMD_LARGE for targeted debug - Targeted check uses --flaky-check --no-self-parallel PRs affected by tests running in parallel with themselves: ClickHouse#102015 ClickHouse#101093 ClickHouse#99653 ClickHouse#101503 ClickHouse#101108 ClickHouse#101884 ClickHouse#100746 ClickHouse#101447 ClickHouse#100941 ClickHouse#101099 ClickHouse#100203 ClickHouse#96130 ClickHouse#102038
StorageSystemRocksDB::fillDatacollects RocksDB tables in a first pass, but by the time it callsgetRocksDBStatisticsin the second pass, the table may have been concurrently dropped.getRocksDBStatisticsreturns null whenrocksdb_ptris null (table shut down), and the code threw aLOGICAL_ERRORexception instead of gracefully skipping the table.Found in Stress test (amd_debug): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100290&sha=672c551dd5b6b553a8c76d3fc13e823303b2a822&name_0=PR&name_1=Stress%20test%20%28amd_debug%29
#100290
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
LOGICAL_ERRORexception "RocksDB statistics are not available" when queryingsystem.rocksdbwhile a RocksDB table is being concurrently dropped.Documentation entry for user-facing changes
Version info
26.5.1.322