Repository navigation
Fix access entities lost or left dangling after a restart that follows SYSTEM RELOAD USERS - #125058
Conversation
…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]>
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.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261010-104500 |
|
Workflow [PR], commit [5adb8bb] Summary: ✅
AI ReviewSummaryThis PR closes the recovery gap around Final Verdict
|
…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]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 9 s compile time in total, 7 of them have a recent master baseline. |
…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]>
Related: #111493
Related: #120943
Related: #111346
Changelog category (leave one):
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_directoryaccess storage being lost after a restart, or a dropped row policy making every query fail withFILE_DOESNT_EXIST. This happened to entities created or dropped within a minute afterSYSTEM RELOAD USERSif the server was then killed, or at any time afterSYSTEM RELOAD USERSfailed to write the storage's.listfiles.Description
On 26.9.14.10, after
CREATE USER alice; SYSTEM RELOAD USERS; CREATE USER boband akill -9within a minute, the restarted server has nobob, although itsaccess/<id>.sqlis still on disk. WithCREATE ROW POLICY p ON default.t USING 1 TO ALL; SYSTEM RELOAD USERS; DROP ROW POLICY p ON default.tinstead, every query after the restart fails withCode: 107 ... Cannot open file .../access/<id>.sql (FILE_DOESNT_EXIST). This is why the server never became ready inStress 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%29DiskAccessStoragechanges<id>.sqlat once and rewrites the.listindex files a minute later from a background thread;need_rebuild_lists.marktells the next start not to trust the index.scheduleWriteListscreated the mark only when it started a new writer thread, and its two early returns assumed it already existed. ButSYSTEM RELOAD USERSremoves 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, withWriteBufferFromFile, so a DDL fails before changing any file when the mark cannot be created (std::ofstreamfailed silently).SYSTEM RELOAD USERSnow 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_storagepasses.#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
26.10.1.2234-master(included in26.10and later)