Skip to content

Make 05054_embedded_rocksdb_explicit_dir_file_grant stress-restart safe - #118220

Merged
PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-05054-rocksdb-stress-restart-safe
Sep 5, 2026
Merged

PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-05054-rocksdb-stress-restart-safe

Conversation

@groeneai

@groeneai groeneai commented Sep 5, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #117665

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

Stress test (*) loses the whole job: the post-stress restart cannot attach <db>_poc_<pid>.leak (Code: 555 ... /CURRENT: No such file or directory). 8 rows in 3 days: 2 unrelated PRs, 6 release-branch runs, all after the reland.

Dropping an EmbeddedRocksDB table with an explicit rocksdb_dir closes the handle but leaves the directory, so this test removes its own. stress.py SIGTERMs a random clickhouse-client whose pattern misses the test script, so the script outlives its dead client and still runs the rm -rf; prepare_for_hung_check then only detaches databases, so leak.sql reaches the final restart, where FORCE_ATTACH skips fs::create_directories and OpenForReadOnly fails on the missing directory.

The rm -rf runs only if both teardown drops reported success and a probe confirms the victim is gone: nothing is removed while a stored definition still names it. Two things make a zero status mean the drop happened: the top-level DROP TABLEs pin ignore_drop_queries_probability = 0, because Stress test injects 0.2 and InterpreterDropQuery then skips a disk-backed table's drop, reporting success; and neither teardown drop says IF EXISTS, which reports success for a merely detached object. Their stderr is discarded: any stderr fails a test. DROP DATABASE needs no pin, the skip being disabled inside one. The RESTORE pin also removes a latent per-run failure.

Teardown extracted verbatim: unfixed, the directories go and the restart fails; fixed, they stay and it starts, leak readable. Measured with the client killed and with the databases detached. Removing either pin reds a mutant, as does dropping the redirect. 41 randomized runs, 20 under the injected client option: green, nothing left behind.

Not fixed here: at FORCE_ATTACH a read_only table whose directory has vanished still cannot attach, and with async_load_databases = false that aborts startup, though the level's contract is to ignore errors. Pre-existing, reachable via truncate() alone.

CIDB breadth query and result
SELECT check_name, if(pull_request_number = 0, head_ref, 'unrelated PR') AS ref,
       count() AS n, max(check_start_time) AS last
FROM default.checks
WHERE check_start_time > now() - INTERVAL 3 DAY
  AND test_context_raw LIKE '%05054_embedded_rocksdb_explicit_dir_file_grant%'
  AND test_context_raw LIKE '%Failed to open rocksdb path%'
GROUP BY check_name, ref ORDER BY last
┌─check_name─────────────────┬─ref──────────┬─n─┬────────────────last─┐
│ Stress test (amd_msan)     │ unrelated PR │ 1 │ 2026-09-04 17:35:33 │
│ Stress test (amd_tsan)     │ unrelated PR │ 1 │ 2026-09-04 20:40:33 │
│ Stress test (arm_asan, s3) │ 26.3         │ 2 │ 2026-09-04 21:26:50 │
│ Stress test (arm_asan)     │ 26.3         │ 1 │ 2026-09-04 21:26:50 │
│ Stress test (amd_debug)    │ 26.3         │ 1 │ 2026-09-04 21:33:53 │
│ Stress test (amd_msan)     │ 26.3         │ 2 │ 2026-09-04 21:33:56 │
└────────────────────────────┴──────────────┴───┴─────────────────────┘

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=26.3&sha=0d1d84363d80aab0cb154b6d670bd50f7ec5a528&name_0=ReleaseBranchCI&name_1=Stress%20test%20%28amd_debug%29

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=26.3&sha=3e4f263a8de732250e07b36e12a90d5607d17110&name_0=ReleaseBranchCI&name_1=Stress%20test%20%28arm_asan%2C%20s3%29


Workflow [PR]
Sync PR [sync-upstream/pr/118220]

Version info

  • Merged into: 26.9.1.802 (included in 26.9 and later)
  • Backported to: 26.8.3.62, 26.7.7.52, 26.6.5.79, 26.3.33.18

groeneai and others added 3 commits September 5, 2026 03:14
`Stress test (*)` loses the whole job on this test: the post-stress restart
cannot attach `<db>_poc_<pid>.leak` (`Code: 555. Failed to open rocksdb path
... /CURRENT: No such file or directory`) and gives up after 11 attempts.

`StorageEmbeddedRocksDB::drop` closes the handle but never removes an explicit
`rocksdb_dir`, so this test removes its own. It removed them unconditionally,
discarding the teardown drops' exit codes, and `stress.py` SIGTERMs a random
`clickhouse-client` whose pgrep pattern does not match the test script itself,
so the script outlives its dead client and still runs the `rm -rf`.
`prepare_for_hung_check` only detaches databases, so `leak.sql` reaches the
final restart, where `FORCE_ATTACH` skips `fs::create_directories` and
`OpenForReadOnly` cannot open a directory that is gone. Whether that aborts
startup or is instead deferred to the first query that waits on the table
depends on `async_load_databases`, which the stress runner randomizes.

Order the removal after proof that no stored definition still names those
directories: capture both teardown drops' exit codes and gate the `rm -rf` on
both. A zero status then has to mean the drop happened, so the two top-level
`DROP TABLE`s carry `ignore_drop_queries_probability = 0`. `Stress test`
injects `0.2`, and `InterpreterDropQuery` then silently skips such a drop for a
table whose `storesDataOnDisk` is true, while returning success.

The `DROP DATABASE` is deliberately not pinned. `InterpreterDropQuery` computes
`is_drop_or_detach_database` from the top-level query and requires it to be
false before skipping, so a table drop performed as part of a `DROP DATABASE`
is never skipped. That carve-out is deliberate: `f1c0f886d5b60fb` added it
because a partial skip left "orphaned tables that prevent server restart". A
pin there would be a no-op, so the source comment states the rule scoped to
what the setting actually does.

Pinning the `RESTORE` arm's drop also removes a latent per-stress-run failure
of the test itself: a skipped drop leaves the name taken, so the denial arm
that follows prints `CREATED ANYWAY (unexpected)`. Measured at the injected
`0.2` it reds 1 run in 20, and at `1.0` it reds every run.

Only a `read_only` table is a restart carrier. A writable one reaches
`rocksdb::DB::Open`, which is configured with `create_if_missing`, so it
re-creates an empty directory instead of failing to attach.
`victim_rc == 0` means the drop happened only while
`ignore_drop_queries_probability = 0` is in force on that statement.
`InterpreterDropQuery` skips a top-level `DROP TABLE` of a table whose
`storesDataOnDisk` is true and returns success, so if that pin ever stopped
applying, the teardown would delete `SECRET_DIR` while a live table still named
it and nothing would say so: the victim is writable, so the next start
re-creates an empty RocksDB instead of failing to attach, and the reference ends
before the teardown.

Probe `EXISTS TABLE` after the drop, print on the contradiction, and require the
probe in the gate as well. A probe that fails is not read as absence, so a
teardown whose client died still removes nothing and prints nothing. Measured
through `tests/clickhouse-test` at probability 1.0: with the pin removed the
test now fails on one added line and keeps all three directories, where the same
mutation was green with the directories removed.

Also drop the claim that a table failing to attach aborts metadata loading.
`async_load_databases` defaults to true, and there the failed load job is
rethrown to the query that waits on the table; only the stress runner's
randomized false arm refuses to start. The removal ordering that comment is
attached to holds either way.

Co-Authored-By: Claude Opus 5 <[email protected]>
`prepare_for_hung_check` fires `DETACH DATABASE` for every database without
waiting for it, and the stress harness then says outright that shell scripts
outlive `clickhouse-test` and keep issuing queries. A teardown reaching that
window gets success from two drops that deleted nothing: with `IF EXISTS`,
`tryGetDatabase` and `tryGetDatabaseAndTable` return null for an object missing
from the catalog and the interpreter returns an empty result, while the metadata
directory survives untouched. `EXISTS TABLE` reads `isTableExist`, false for a
detached object as well, so no probe can tell the two apart. The absence of
`IF EXISTS` is the only discriminator: the drop then throws `UNKNOWN_DATABASE`,
which is exactly what the gate needs to mean "not verifiably deleted".

Measured on this test, server alive throughout and no client killed: before,
all four gate conditions passed, `SECRET_DIR` was removed and the next start
refused to boot with `Code: 555 Failed to open rocksdb path ... /CURRENT: No
such file or directory: Cannot attach table poc.leak`; after, the drop reports
81, the directories stay and the restart brings `leak` back reading `marker
secret`. The same holds one level down for the victim's own database.

Discard both drops' output: `clickhouse-test` fails a shell test on any
non-empty stderr regardless of exit code, so a teardown landing in that window
would turn this test red instead of leaking. Verified in both directions
through the runner - green with the redirects, `having stderror:` without them.

Name both arms in the teardown comment. A definition whose `rocksdb_dir` is
gone cannot be attached only when it is `read_only`; a writable one comes back
silently empty, which is measurable here as the victim losing its row across a
restart, and two of the gate's four conditions exist for exactly that table.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 5, 2026
@groeneai

groeneai commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

Three rounds. Six findings agreed and fixed before publishing, none dismissed; the last round's
independent pass returned none.

❌ The gate could still delete the directories while detached metadata named them. The stress
harness detaches every database without waiting, then notes that shell scripts outlive
clickhouse-test and keep running queries. In that window DROP ... IF EXISTS reports success having
deleted nothing, and EXISTS TABLE cannot see a detached object either, so the exit-code gate passed
and the restart reloaded leak from preserved metadata onto a removed directory. The teardown drops
no longer use IF EXISTS, which is the only thing that distinguishes deleted from detached; their
output is discarded because any stderr fails a test outright. Reproduced against a healthy server with
no client killed, then inverted.

❌ Nothing detected the victim pin declining. With the pin gone the injector skips the drop,
reports success, the exit-code checks pass and the directory is deleted under a live table; because
that table is writable the restart re-creates an empty RocksDB, so nothing reddened. The teardown now
also probes EXISTS TABLE and reports "the drop succeeded and the table is still here", while a
failed probe keeps the directories rather than being read as absence.

❌ Two comment over-claims. A failed attach was said to always abort startup: async_load_databases
defaults to true, where the error is rethrown at the first query that waits on the table. And a
missing rocksdb_dir was said to always prevent attaching: only a read_only definition fails, a
writable one silently comes back empty. Both corrected; the mechanisms stay in the commit messages.

💡 Two nits raised in the last round and refuted at source rather than changed. The EXISTS TABLE
probe leaves its stderr unredirected while its two neighbouring drops do not, but the unchanged
DROP USER IF EXISTS ahead of it is unredirected too, so no failing window can red on the probe
without redding on that line first, and the probe cannot throw for a detached database because
EXISTS resolves through isTableExist. And "remove the three this test made" above a four-path
rm -rf is pre-existing wording whose fourth path is asserted never created.

⚠️ Not fixed, deliberately: the startup hole described in the body, and the DROP DATABASE stays
unpinned because the skip is disabled inside one.

@groeneai

groeneai commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, at probability 1. Kill the server, run the teardown block extracted verbatim from the file, restart: Code: 555. Failed to open rocksdb path ... Cannot attach table <db>_poc_<pid>.leak, and with async_load_databases = false (which the stress runner draws on half its runs) the server refuses to boot. Not a rate.
b Root cause explained? Yes. StorageEmbeddedRocksDB::drop closes the handle but never removes an explicit rocksdb_dir, so the test removes its own, unconditionally, discarding the teardown drops' exit codes. The stress runner SIGTERMs a random clickhouse-client and its pattern does not match the test script, so the script outlives its dead client and still runs the rm -rf; prepare_for_hung_check only detaches databases, so leak.sql reaches the final restart, where FORCE_ATTACH skips fs::create_directories and OpenForReadOnly cannot open a directory that is gone.
c Fix matches root cause? Yes. The removal is ordered after proof that no stored definition still names the directories, and every status that proof rests on is made unable to report success without having deleted: non-skippable, probed, and not silenced by IF EXISTS. No widened bound, no no-random-* tag, no size reduction, and nothing guards the failure site.
d Test intent preserved / new tests added? Preserved exactly: every assertion and the whole .reference are byte-identical, only the teardown and one drop changed. No new case, because the change is teardown robustness rather than a behaviour fix.
e Both directions demonstrated? Yes, in two independent windows, same driver, one variable. Dead client: unfixed the directories go and the restart fails; fixed they stay (poc_rc=210 victim_rc=210 probe_rc=210) and the restart succeeds with leak still readable. Detached catalog, server alive and no client killed: unfixed all four gate conditions pass, the directories go and the restart fails with the same Code: 555; fixed the drop reports 81 (UNKNOWN_DATABASE), the directories stay and leak reads its row after the restart, and one level down the victim keeps its row instead of coming back empty. With the server alive and the catalog intact both trees clean up fully, so "it boots" is not satisfied by simply never removing anything. Each pin also reds a one-line mutant on demand and greens when reverted; the mutant removing the victim pin is caught by the test itself at ignore_drop_queries_probability = 1.0 (one added output line, three directories kept, where the same mutation without the probe was green with them removed); and deleting the two 2>/dev/null redirects turns the detach scenario from green into a having stderror: failure, which is why they are there.
f Fix is general across code paths? Every table this test can leave behind is covered: the victim by its pinned drop, victim_rc and a post-drop existence probe, the five tables in the other database by poc_rc (a DROP DATABASE is immune to the skip), and the argument-less form is not a carrier at all, its directory living under the table's own data path. Every DROP and DETACH in the file was checked for exposure to the setting; the two exposed ones are the two pinned, and DETACH is out of the setting's reach entirely. The three distinct ways a drop can report success without having deleted anything are each closed at their own site and each measured separately: the silent skip by the pin, a table surviving a reported success by the probe, and a merely detached object by the absence of IF EXISTS (no probe can see that one, since EXISTS TABLE reads isTableExist, false for a detached database too). None of the three subsumes another and the gate rests on no single one of them. Sibling tests: 03602_embeddedrock_path creates nothing, 04330_rocksdb_truncate_drop_null_ptr already runs in clickhouse-local under CLICKHOUSE_TMP.
g Fix generalizes across inputs? Both read_only values and both ttl == 0 open branches are enumerated; only read_only = 1 is a boot-failure carrier, since a writable table takes rocksdb::DB::Open with create_if_missing. Both async_load_databases values and both ends of ignore_drop_queries_probability (0.2 as injected, 1.0 deterministic) plus the default were measured.
h Backward compatible? N/A. Test-only: no setting default, no serialization format, no SettingsChangesHistory.cpp entry, no user-visible behaviour.
i Invariants and contracts preserved? The gate is evaluated before the destructive step, so no half-removed state is reachable. On the failing path the test leaves exactly what the engine already leaves for any explicit-directory table, and every surviving definition stays attachable, which is the invariant the change exists to hold.

Session id: cron:clickhouse-impl-slot-5:20260905-055300

@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [967cf2e]

Summary: ✅


AI Review

Summary

The PR hardens 05054_embedded_rocksdb_explicit_dir_file_grant.sh against the stress runner's client kills and prepare_for_hung_check database detaches by pinning the affected top-level DROP TABLE queries away from ignore_drop_queries_probability and by deleting the explicit rocksdb_dir trees only after the stored metadata is provably gone. I checked the surrounding invariants in InterpreterDropQuery, InterpreterExistsQuery, DatabaseCatalog, and StorageEmbeddedRocksDB; the new teardown gate matches the failure mode described in the PR and I did not find a remaining contract violation in the current diff.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 5, 2026
@groeneai

groeneai commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

cc @hanfei1991, could you review this? It is the same class as #107858 which you merged: a stress restart cannot attach an EmbeddedRocksDB table whose explicit rocksdb_dir the test itself already removed, so the rm -rf is now ordered after proof that no stored definition still names the directory, and #107858's clickhouse-local remedy is unavailable here because this test asserts server-side FILE grants as another user.

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 5, 2026
@PedroTadim PedroTadim self-assigned this Sep 5, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Sep 5, 2026
Merged via the queue into ClickHouse:master with commit 51ec619 Sep 5, 2026
174 of 175 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 5, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 8, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 8, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 8, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 8, 2026
Backport #118220 to 26.8: Make 05054_embedded_rocksdb_explicit_dir_file_grant stress-restart safe
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 8, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 8, 2026
Backport #118220 to 26.6: Make 05054_embedded_rocksdb_explicit_dir_file_grant stress-restart safe
PedroTadim added a commit that referenced this pull request Sep 8, 2026
Backport #118220 to 26.3: Make 05054_embedded_rocksdb_explicit_dir_file_grant stress-restart safe
clickhouse-gh Bot added a commit that referenced this pull request Sep 8, 2026
Backport #118220 to 26.7: Make 05054_embedded_rocksdb_explicit_dir_file_grant stress-restart safe
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
@clickhouse-gh clickhouse-gh Bot added comp-foreign-db Connectivity to external databases (ODBC/JDBC, MySQL, PostgreSQL, etc.). and removed comp-testing Test content only (no production code). labels Nov 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 comp-foreign-db Connectivity to external databases (ODBC/JDBC, MySQL, PostgreSQL, etc.). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.3-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants