Skip to content

Fix access entities lost or left dangling after a restart that follows SYSTEM RELOAD USERS - #125058

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:groeneai/disk-access-storage-mark-before-every-list-change
Oct 12, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:groeneai/disk-access-storage-mark-before-every-list-change

Conversation

@groeneai

@groeneai groeneai commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #111493
Related: #120943
Related: #111346

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed access entities (users, roles, row policies, etc.) of the local_directory access storage being lost after a restart, or a dropped row policy making every query fail with FILE_DOESNT_EXIST. This happened to entities created or dropped within a minute after SYSTEM RELOAD USERS if the server was then killed, or at any time after SYSTEM RELOAD USERS failed to write the storage's .list files.

Description

On 26.9.14.10, after CREATE USER alice; SYSTEM RELOAD USERS; CREATE USER bob and a kill -9 within a minute, the restarted server has no bob, although its access/<id>.sql is still on disk. With CREATE ROW POLICY p ON default.t USING 1 TO ALL; SYSTEM RELOAD USERS; DROP ROW POLICY p ON default.t instead, every query after the restart fails with Code: 107 ... Cannot open file .../access/<id>.sql (FILE_DOESNT_EXIST). This is why the server never became ready in Stress test (arm_release) on #111493: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=111493&sha=00ba4e00e36ef6f686be7a845e86d93ee4de33e3&name_0=PR&name_1=Stress%20test%20%28arm_release%29

DiskAccessStorage changes <id>.sql at once and rewrites the .list index files a minute later from a background thread; need_rebuild_lists.mark tells the next start not to trust the index. scheduleWriteLists created the mark only when it started a new writer thread, and its two early returns assumed it already existed. But SYSTEM RELOAD USERS removes the mark while the writer is still waiting, and when that reload's own list write fails (ENOSPC, or an injected OOM in the stress job) no mark exists and nothing writes the lists again until the next reload, so later DDLs are lost even on a clean restart.

The mark is now created at the top of scheduleWriteLists, before both early returns, with WriteBufferFromFile, so a DDL fails before changing any file when the mark cannot be created (std::ofstream failed silently). SYSTEM RELOAD USERS now also creates it first, best effort, so a read-only directory stays reloadable.

Four new gtests (one per early return, a failed reload that picked up a new <id>.sql, an uncreatable mark) fail on master and pass 50/50 with the fix; with the mark moved only before the waiting-writer return (the #111346 shape) the failed-write test still fails. test_disk_access_storage passes.

#120943 is the startup-side defence; it cannot restore an entity missing from the index.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.2234-master (included in 26.10 and later)

groeneai and others added 3 commits October 10, 2026 09:31
…iles

`DiskAccessStorage` changes `<id>.sql` immediately and rewrites the `.list`
index files a minute later from a background thread. `need_rebuild_lists.mark`
is what tells the next start not to trust a stale index. `scheduleWriteLists`
created it only when it started a new writer thread, and assumed in its two
early returns that it already existed. Neither assumption held:

- `SYSTEM RELOAD USERS` (`reloadAllAndRebuildLists`) writes the lists and
  removes the mark while the writer thread keeps waiting, so a DDL in the rest
  of that minute changed `<id>.sql` with no mark on disk;
- after a failed list write (`failed_to_write_lists`) nothing writes the lists
  again until restart, and when that write came from `reloadAllAndRebuildLists`
  no mark existed either.

A restart from either state trusted the stale index: an entity created in the
window was lost, and a dropped one stayed listed without its `.sql`. For a row
policy every new session then fails with `FILE_DOESNT_EXIST`, which is how
`Stress test (arm_release)` on PR ClickHouse#111493 ended with a server that never became
ready.

Create the mark at the top of `scheduleWriteLists`, before both early returns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`std::ofstream` failed silently, so a DDL could change `<id>.sql` with no mark
on disk. `WriteBufferFromFile` throws before any file is changed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the reason for creating need_rebuild_lists.mark on every call to one line; the failed-write case is already stated at the early return below.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding; 1 full pass + 1 fix round + 1 delta recheck with 0 new findings) plus my own cold review.

# Sev Finding Verdict Evidence / action
1 ❌ Creating need_rebuild_lists.mark with std::ofstream fails silently, so a DROP could still unlink <id>.sql with no mark on disk (DiskAccessStorage.cpp, scheduleWriteLists) AGREE, fixed @ d56b6d9 The mark is created with WriteBufferFromFile, which throws, so the DDL fails before any file changes; new gtest with a directory in place of the mark
2 💡 KeepsUserCreatedAfterReloadOnCrash waits out the writer's one-minute timer at shutdown AGREE, not changed Lost notify_one on master, fixed by #118099; the verdict does not depend on it

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-8:20261010-104500

@clickhouse-gh

clickhouse-gh Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5adb8bb]

Summary: ✅


AI Review

Summary

This PR closes the recovery gap around need_rebuild_lists.mark in DiskAccessStorage: DDLs now recreate the marker before both early returns in scheduleWriteLists, and SYSTEM RELOAD USERS creates it before reloadAllAndRebuildLists so a failed rebuild no longer leaves later restarts trusting stale .list files. I do not see any remaining contract violations in the current code, and the added regression tests together with the all-green bugfix-validation / stress coverage make the fix convincing.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 10, 2026
Comment thread src/Access/DiskAccessStorage.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. label Oct 10, 2026
…e lists

`SYSTEM RELOAD USERS` replaces the in-memory entities with the `<id>.sql`
files on disk and then rewrites the `.list` files. If that rewrite fails
and no access DDL follows, nothing created the mark, so a clean restart
trusted the old `.list` files: a user added to the directory before the
reload was lost, and a row policy removed from it left every query failing
with `FILE_DOESNT_EXIST`.

`reloadAllAndRebuildLists` already removes the mark only after the lists
are written and the stale files are gone, so `reload` creates it first.
This is best effort: a directory that refuses new files (for example a
read-only mount) rewrites the existing `.list` files in place and must stay
reloadable, so a failure to create the mark is logged instead of failing
the reload.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5adb8bbc9 with master 18b5a991f (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 9 s compile time in total, 7 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov self-assigned this Oct 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 12, 2026
Merged via the queue into ClickHouse:master with commit 8935851 Oct 12, 2026
163 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 12, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 13, 2026
…diskaccessstorage-fsync

Resolve the conflict with ClickHouse#125058, which moved the creation of
`need_rebuild_lists.mark` to the start of `scheduleWriteLists` and added
one more in `reload`. Both now go through `createNeedRebuildListsMark`,
which syncs the mark and its directory when `fsync_metadata` is set.

`reload` now creates the mark itself before `reloadAllAndRebuildLists`, so
the check "a mark already exists, so its lists are owed durably" moves out
of `reloadAllAndRebuildLists` to before that creation in `reload`, and to
the constructor. Otherwise every `SYSTEM RELOAD USERS` would sync the lists
even with `fsync_metadata = 0`. `scheduleWriteLists` now accumulates
`pending_lists_fsync` before the `failed_to_write_lists` early return, like
the mark creation, so a change made after a failed list write keeps its
requirement too.

Also trim the comments added by this PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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-rbac Authorization: roles, grants, quotas, row-level security, access checks. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-bugfix Pull request with bugfix, not backported by default 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.

3 participants