Repository navigation
Conversation
`DiskAccessStorage` persists each access entity as `access/<uuid>.sql` and indexes them in `access/<type>.list`. `readLists` trusted that index: every listed id became a lazy `EntityOnDisk` placeholder, and the first real read called `readEntityFile`, which throws `FILE_DOESNT_EXIST` once the file is gone. For a settings profile that first read happens during startup, in `Context::setDefaultProfiles` -> `SettingsProfilesCache::ensureAllProfilesRead`, so `Server::main` aborted and the server could not start at all, on every subsequent attempt, with no in-product recovery. The guard that looks like it should cover this, `tryRead`, only suppresses the storage's own `NOT_FOUND`, not a `FILE_DOESNT_EXIST` raised by `ReadBufferFromFile`. `DiskAccessStorage` already owns the recovery for this class of damage: `need_rebuild_lists.mark` leads to `reloadAllAndRebuildLists`, which rescans the directory, skips what it cannot parse and rewrites the `.list` files. It is already reached for a missing `.list`, an unparsable `.list`, an orphan `.tmp` and duplicate names. A listed entity whose `.sql` file is gone was not routed there. A file that is present but unparsable is still only detected at the read; `readLists` never opens entity files. `readLists` now checks each listed id and returns `false`, which routes into that same rebuild. The discarded entity is logged by name and id, and its definition was already gone from disk, so nothing recoverable is lost. A healthy directory pays one `stat` per listed entity, cheaper than the lazy read it guards, and the rescan happens only when damage is found. How the state arises: on 26.3 and 26.4 `insertNoLock` mutates memory before disk, so a `CANNOT_SCHEDULE_TASK` thrown out of `scheduleWriteLists` leaves the entity in `memory_storage` with no `<uuid>.sql` written, and a later access DDL bakes the phantom into the `.list` and removes the marker. That ordering defect is already fixed on master by ClickHouse#104411 (26.5 and later), but upgrading cannot repair a directory an earlier build already damaged, and the same state is reachable from a partial restore of `access/`. The check is taken from ClickHouse#99487, which proposed it at this exact site and was closed in favour of ClickHouse#104411; only the ordering half landed there. Its integration test is adapted here to damage a settings profile, so the test reproduces the failed startup rather than a later read. Found in 26.3 `Stress test (arm_asan)`, seven consecutive failed starts: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=26.3&sha=0af5e9c36f9f9cc12344e8dd96cb7a7bd801f468&name_0=ReleaseBranchCI&name_1=Stress%20test%20%28arm_asan%29 Related: ClickHouse#99487 Related: ClickHouse#104411 Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 8 findings; 1 full pass + 1 fix
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20260919-003100 |
|
Workflow [PR], commit [90daa43] Summary: ✅
AI ReviewSummaryThis PR teaches Findings
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit 90daa43.
Changed lines: Changed C/C++ lines covered: 7/7 (100.00%) · Uncovered code |
Build profile diff (arm_release)Commit See the job log for details. |
CI finish ledger - ac28a32Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Session id: cron:our-pr-ci-monitor:20260919-063230 |
| if (!std::filesystem::exists(getEntityFilePath(directory_path, id))) | ||
| { | ||
| LOG_WARNING(getLogger(), "Access entity {} ({}) is listed in {} but the corresponding .sql file doesn't exist", name, toString(id), file_path); | ||
| return false; |
There was a problem hiding this comment.
Routing this through reloadAllAndRebuildLists drops the missing entity itself, but that rebuild path never runs the dependency scrub that a normal remove uses via removeReferencesToRemovedIDs. If the missing .sql belonged to a role, user, or settings profile that is still referenced by some surviving access entity, the dead UUID stays serialized in those survivors' .sql files and is reloaded on every restart. For roles that is the same stale-reference class that test_drop_role_cascades_to_disk documents as leading to later ACCESS_ENTITY_NOT_FOUND failures. Please carry the set of discarded IDs into the rebuild path and scrub dependent entities before persisting the repaired directory.
There was a problem hiding this comment.
Reproduced the mechanism, and it is pre-existing rather than introduced here.
On a clean master build (015bf1203d344, none of this PR applied) I removed a role's .sql and ran SYSTEM RELOAD USERS, the user-facing entry into reloadAllAndRebuildLists: the role leaves system.roles and its UUID stays on disk in all three survivors (the user's DEFAULT ROLE ID(...) and ATTACH GRANT ID(...), the profile's TO ID(...), the row policy's TO ID(...)). With need_rebuild_lists.mark present, master boots on that same damaged directory, logs Recovering lists, and keeps the same three references. Control on the same server: DROP ROLE does scrub, so the cascade is only on the remove() path.
Neither entry goes through readLists, so this diff neither creates nor widens the class. It makes the marker-absent case behave like the marker-present one, which today is the difference between a server that boots and one that cannot.
I would rather not put the scrub inside recovery:
- A missing
.sqlis not a removal decision. Recovery runs when the on-disk state is damaged in an unknown way and the file may still be restorable (a half-restored backup, a volume not mounted yet), while grants scrubbed out of healthy entities are gone for good. The same function keeps an unparsable.sql"on disk for inspection" instead of treating it as a removal. - The rebuild reads the directory alone. At startup nothing is in memory yet and the marker declares the index suspect, so the discarded set is not computable there. Scrubbing only where it happens to be computable would re-introduce the divergence this PR removes.
Whether recovery should scrub dependencies is a component-owner call and it applies to master independently of this PR. If it is wanted, I will send it as a separate change covering every entry into the rebuild.
CI finish ledger - 7943960Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
No test-level failure on this head: the Session id: cron:our-pr-ci-monitor:20260920-063119 |
| for (auto & [id, name] : readListFile(file_path)) | ||
| { | ||
| /// The list files must not reference an entity without its `<id>.sql` file: such an entity throws when read. | ||
| if (!std::filesystem::exists(getEntityFilePath(directory_path, id))) |
There was a problem hiding this comment.
If the missing <id>.sql belongs to a settings profile that startup resolves by name from config, this still leaves the server unable to boot. readLists() now forces a rebuild, but reloadAllAndRebuildLists() just drops the profile; Context::setDefaultProfiles() / makeBackgroundContext() then look up default_profile, system_profile, buffer_profile, or an explicit background_profile by name and throw THERE_IS_NO_PROFILE when that profile was the one whose file disappeared. The new integration test misses this because sp_recover is never referenced from config, so it only proves the lazy-profile path. Please cover one of the configured-profile cases or narrow the fix to the non-configured-profile startup failure.
|
@groeneai is this still needed? I don't like this change. It allows to start the server without an important file |
|
No, it is not needed anymore, and I agree with the objection. The
Since #125058 merged on 2026-10-12, CI has not shown this |
Related: #99487
Related: #104411
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix the server failing to start when an access entity is listed in a
/var/lib/clickhouse/access/*.listfile but its<uuid>.sqlfile is missing on disk. The list files are now rebuilt from the directory contents in that case.Description
On 26.3
Stress test (arm_asan)the server could not start at all: seven consecutive attempts aborted withCode: 107 ... Cannot open file /var/lib/clickhouse/access/<uuid>.sql ... (FILE_DOESNT_EXIST). Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=26.3&sha=0af5e9c36f9f9cc12344e8dd96cb7a7bd801f468&name_0=ReleaseBranchCI&name_1=Stress%20test%20%28arm_asan%29ClickHouse created that state itself. In the same run the thread-pool fault injector made
CREATE SETTINGS PROFILEfail withCANNOT_SCHEDULE_TASKinsidescheduleWriteLists, which 26.3 calls after the in-memory insert, so the profile reached memory with no<uuid>.sql; a later access DDL wrote that phantom intosettings_profiles.listand removedneed_rebuild_lists.mark. #104411 fixed that ordering on master (26.5+), but 26.3 and 26.4 still create the state, and upgrading cannot repair a directory an earlier build already damaged.This fixes the half that is still on master.
readListstrusts the index, so a listed entity whose.sqlis gone becomes a lazy placeholder that throws on first read; for a settings profile that read happens inContext::setDefaultProfiles, soServer::mainaborts, permanently and with no in-product recovery.DiskAccessStoragealready owns the recovery,reloadAllAndRebuildLists, reached for a missing or unparsable.listbut not for a listed id with no.sql.readListsnow checks each listed id and returnsfalseinto that same rebuild. The discarded entity is logged by name and id; its definition was already gone from disk. A settings profile that a server setting such asdefault_profilenames is discarded too, so startup still stops withTHERE_IS_NO_PROFILE, as master's own rebuild already does. A healthy directory pays onestatper listed entity; the rescan runs only on damage. A present but unparsable.sqlstays out of scope:readListsnever opens entity files.The check is from #99487, closed in favour of #104411; its integration test is adapted here to damage a settings profile, so it reproduces the failed startup.
Validated both ways: the signature reproduced locally, and the new test fails on unpatched master.
Workflow [PR]
Sync PR [sync-upstream/pr/120943]