Skip to content

Make 04330_rocksdb_truncate_drop_null_ptr stress-restart safe - #107858

Merged
hanfei1991 merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-04330-rocksdb-test-stress-restart-safe
Jun 22, 2026
Merged

hanfei1991 merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-04330-rocksdb-test-stress-restart-safe

Conversation

@groeneai

@groeneai groeneai commented Jun 18, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

Test-only follow-up to #106940 (the EmbeddedRocksDB truncate()/drop() null-pointer fix), which is already merged.

The regression test 04330_rocksdb_truncate_drop_null_ptr.sh created a read_only EmbeddedRocksDB table over a relative user_files directory on the running server and emptied it with TRUNCATE. That left a persisted read_only table whose data directory was wiped. When the Stress test restarted the server mid-run, attaching that table called OpenForReadOnly() on the missing directory, which threw ROCKSDB_ERROR and aborted metadata loading, so the server refused to start.

Master regression:

Fix: run the whole scenario in a single clickhouse-local process. The poisoned read_only table lives only for that one-shot process and is never written to server metadata, so a stress restart can no longer reattach it. --ignore-error lets the batch continue past the first TRUNCATE's expected reopen failure so the second TRUNCATE and the DROP still execute against the now-null handle, which is exactly the path the merged fix guards. The data directory is placed under CLICKHOUSE_TMP with a unique per-test name, so the test is parallel-safe and no longer needs no-parallel.

The merged C++ fix is unchanged. Verified locally (debug build) both directions: without the guards the clickhouse-local process segfaults (no ok, output mismatches the reference); with the guards it prints ok. The test runs in the parallel pool (clickhouse-test reports it as a parallel test) and passes repeatedly.

Version info

  • Merged into: 26.6.1.1119

@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. clickhouse local --ignore-error --multiquery "CREATE ... rdb_rw EmbeddedRocksDB(0, '<dir>'); INSERT; DROP rdb_rw SYNC; CREATE ... rdb_ro EmbeddedRocksDB(0, '<dir>', 1); TRUNCATE rdb_ro; TRUNCATE rdb_ro; DROP rdb_ro SYNC; SELECT 'ok'" segfaults every time on a no-guard binary (exit 139, no ok). The original master regression is also deterministic: Stress test (amd_debug), commit 81a39f72bed, Cannot start clickhouse-server.
b Root cause explained? Two distinct things. (1) The crash the test targets: the first TRUNCATE on a read_only table wipes the dir, initDB()'s OpenForReadOnly() throws, leaving rocksdb_ptr == nullptr; the second TRUNCATE/DROP then dereferenced it (fixed in #106940, merged). (2) The Stress regression this PR fixes: the old test created that poisoned read_only table on the persistent server, so when the Stress test restarted the server, attaching the table called OpenForReadOnly() on the wiped dir, threw ROCKSDB_ERROR, aborted metadata loading, and the server refused to start.
c Fix matches root cause? Yes. Running the scenario in a one-shot clickhouse-local process means the poisoned read_only table never enters server metadata, so no stress restart can reattach it. This removes the regression mechanism directly, not a symptom.
d Test intent preserved / new tests added? Yes. The test still exercises the exact guarded path (double TRUNCATE + DROP on a null handle). --ignore-error is required so the batch continues past the first TRUNCATE's expected reopen failure to reach the second TRUNCATE/DROP. Final SELECT 'ok' (matching .reference) proves the process survived. The C++ fix is unchanged.
e Both directions demonstrated? Yes. No-guard debug binary: segfault, empty stdout (mismatches reference ok) → FAIL. Guarded (current master) debug binary: prints ok → PASS. Also ran through clickhouse-test (10/10 OK), which classifies it as a parallel test.
f Fix is general, not a narrow patch? N/A for the C++ fix (already merged in #106940 and unchanged here). This PR is test-only: it makes the regression test stress-restart safe and parallel-safe (drops no-parallel, unique dir under CLICKHOUSE_TMP).

Session id: cron:clickhouse-worker-slot-0:20260618-124400

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @rschu1ze — could you review this? Test-only follow-up to #106940: it rewrites the EmbeddedRocksDB null-ptr regression test to run in a one-shot clickhouse-local process so the poisoned read_only table never persists into server metadata. The old test left a read_only table over a wiped relative user_files dir on the running server, which bricked startup when the Stress test restarted the server (Cannot start clickhouse-server, master Stress test (amd_debug)). Also drops no-parallel and uses a unique dir under CLICKHOUSE_TMP.

@rschu1ze

Copy link
Copy Markdown
Member

I am not affiliated with EmbeddedRockDB, sorry.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @hanfei1991 — you reviewed and approved the parent fix #106940; could you take this test-only follow-up? It rewrites that EmbeddedRocksDB null-ptr regression test to run in a one-shot clickhouse-local process so the poisoned read_only table never persists into server metadata (the old test bricked Stress-test server restart on amd_debug). C++ fix unchanged.

@hanfei1991 hanfei1991 added the can be tested Allows running workflows for external contributors label Jun 18, 2026
@hanfei1991 hanfei1991 self-assigned this Jun 18, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9d052a4]

Summary: ❌

job_name test_name status info comment
Stress test (amd_msan) FAIL
Hung check failed, possible deadlock found FAIL cidb, issue
Stress test (arm_msan) FAIL
Hung check failed, possible deadlock found FAIL cidb, issue

AI Review

Summary

This PR rewrites 04330_rocksdb_truncate_drop_null_ptr to run the EmbeddedRocksDB null-handle regression scenario entirely under clickhouse-local, keeping the poisoned read_only table out of persistent server metadata while still requiring observable output from the RocksDB setup before the expected TRUNCATE failure. The current code fixes the prior test-observability concern, and I do not see remaining review findings.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 18, 2026
The regression test for the EmbeddedRocksDB truncate()/drop() null-handle fix
(merged in ClickHouse#106940) created a persistent read_only table over a relative
user_files directory and TRUNCATEd it. A stress-test server restart then
re-attached that poisoned read_only table whose data dir had been wiped, so
the server refused to start (ROCKSDB_ERROR, "Cannot start clickhouse-server").

Run the whole scenario inside a single one-shot clickhouse-local process so the
poisoned read_only table never persists into server metadata, and place the
data dir under CLICKHOUSE_TMP with a unique name so parallel runs never collide
(drops the no-parallel tag).

A SELECT count() over the read_only table runs before the first TRUNCATE and
must print 1: it proves the table actually opened over the data the rw table
persisted (the EmbeddedRocksDB read_only path was reached) rather than
--ignore-error silently swallowing a broken setup, so the trailing 'ok' only
appears when the null-handle path was genuinely exercised.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai
groeneai force-pushed the groeneai/fix-04330-rocksdb-test-stress-restart-safe branch from 28c8f91 to d7f3d44 Compare June 18, 2026 14:49
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. clickhouse-local --ignore-error --multiquery running the test scenario (create rw table, insert, drop, create read_only over the same dir, two TRUNCATEs, drop) SIGSEGVs every time on a binary without the #106940 null guards (exit 139).
b Root cause explained? This is a test-observability fix, not a code bug. The test relied on a single --ignore-error batch, which swallows errors from ALL statements: if a setup statement (CREATE rdb_rw / INSERT / CREATE rdb_ro) silently broke, the batch would still reach the final SELECT 'ok' and the reference would still match, so the test could pass without ever exercising the EmbeddedRocksDB null-handle path that #106940 guards.
c Fix matches root cause? Yes. Added SELECT count() FROM rdb_ro before the first TRUNCATE, expecting 1, and added 1 to the reference. The read_only table opens over the data the rw table persisted (the data dir survives DROP, which only closes the handle), so count() = 1 proves the read_only path was reached. A broken setup yields 0/empty, breaking the reference match.
d Test intent preserved / new tests added? Preserved and strengthened. The test still asserts the server survives the two TRUNCATEs + DROP against the poisoned null handle (final ok), and now additionally proves the setup genuinely reached that path. No no-parallel tag (per parallel-safe-test guidance): unique CLICKHOUSE_TMP data dir.
e Both directions demonstrated? Yes, on distinct Build IDs. Without the guards: stdout 1 then SIGSEGV at the first TRUNCATE, never reaching ok -> reference mismatch -> FAIL. With the guards (master): stdout 1 then ok -> PASS. clickhouse-test 5/5 OK.
f Fix is general, not a narrow patch? N/A for the C++ (the #106940 fix is unchanged and already guards both truncate() and drop()). This PR is test-only; the change makes the existing regression test observably exercise the guarded path.

Session id: cron:clickhouse-worker-slot-2:20260618-142900

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finished on d7f3d44. This PR only edits the unrelated 04330_rocksdb_truncate_drop_null_ptr stateless test, and the two non-skipped failures are pre-existing trunk issues that also occur on master, not caused by this change:

The rocksdb test itself passes (debug, asan, msan, tsan flaky-check all green). Ready for review.

@hanfei1991

Copy link
Copy Markdown
Member

@groeneai can you fix 00653_verification_monotonic_data_load?

@groeneai

Copy link
Copy Markdown
Collaborator Author

@hanfei1991 The 00653 crash is a trunk heap-corruption bug, not caused by this PR (it only edits the unrelated 04330 rocksdb test). It is a 3-frame jump-to-NULL SIGSEGV during DROP TABLE in a background thread, where the crashing object is a victim of external heap corruption rather than the corruptor (the only fully-symbolized sibling thread, the statistics-merge task, is internally clean), which is why the stack stops at 3 frames with no stable ClickHouse frame.

I believe it is already fixed on master by #107457 (COW-safe assumeMutable -> IColumn::mutate on the read/build paths), merged 2026-06-18 19:49Z. That sweep stops in-place mutation of a shared ColumnPtr from freeing data still referenced elsewhere, which is exactly the corruptor mechanism here. The config-specificity also matches: the crash only ever appeared on amd_debug, distributed plan, s3 storage, and plan serialize/deserialize plus S3 async reads are what push use_count > 1 at the mutation point.

The crash was only ever 2 hits, both on 2026-06-18 and both before #107457 merged (master 6390f1a0 and this PR's run, CI report). Since the merge there has been 0 recurrence across 26 master builds of that check. I am watching the post-merge window; if it reappears on a build that contains #107457 I will reopen and dig further, ideally from a core dump.

@clickhouse-gh

clickhouse-gh Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.20% +0.00%
Functions 92.50% 92.60% +0.10%
Branches 77.50% 77.50% +0.00%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 214 line(s), 37 function(s) across 90 file(s) · Details

Top files
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesChanges.h: 14 line(s), 32 function(s)
  • src/Storages/MergeTree/ReplicatedMergeTreePartCheckThread.cpp: 12 line(s)
  • src/Functions/array/FunctionArrayMapped.h: 8 line(s)
  • src/Storages/MergeTree/ReplicatedMergeTreeRestartingThread.cpp: 8 line(s)
  • src/Functions/FunctionGenerateRandomStructure.cpp: 5 line(s)

Full report

@hanfei1991
hanfei1991 added this pull request to the merge queue Jun 22, 2026
Merged via the queue into ClickHouse:master with commit 1508215 Jun 22, 2026
163 of 166 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants