Repository navigation
Fix DiskAccessStorage crash on restart when .sql file is missing - #99487
alexey-milovidov wants to merge 52 commits into
Conversation
Make `insertNoLock` exception-safe: if `writeAccessEntityToDisk` fails (e.g. due to memory fault injection in stress tests), roll back the `memory_storage` insert so the orphaned entity never makes it into the list files. Also add a defense-in-depth check in `readLists`: validate that each listed entity has a corresponding .sql file on disk, and trigger `reloadAllAndRebuildLists` recovery if any are missing. https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=ba724855a1ff39014f1e254183c387b5cf9625eb&name_0=MasterCI&name_1=Stress%20test%20%28amd_msan%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [f774faee] Summary: ✅ AI ReviewSummaryThis PR hardens Findings❌ Blockers
ClickHouse Rules
Final VerdictStatus: Minimum required action:
|
…safe Move deletion of the old name-collision `.sql` file to after the new file is successfully written. This way, if `writeAccessEntityToDisk` throws, the old file remains on disk and can be recovered on restart. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Add cleanup (TRUNCATE TABLE, DROP COLUMN IF EXISTS, DROP DATABASE IF EXISTS) at the start of each test function so that repeated runs in targeted CI (which uses --count N --repeat-scope=function) don't fail due to accumulated data or pre-existing objects from previous iterations. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Under TSan, the metric collection thread may only fire once during a 2.5s sleep with 1000ms interval, giving 2 rows (1 interval + 1 final) instead of 3+. Change `count() > 2` to `count() >= 2` to tolerate this. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=99487&sha=3ca6c8c21ce1edfe740d99001743e6b0d4447eee&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%2C%201%2F2%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…rage-missing-sql-file # Conflicts: # tests/integration/test_polymorphic_parts/test.py
…on safety - Save old entity before `memory_storage.insert` so it can be restored if `writeAccessEntityToDisk` fails in the `replace_if_exists` path. - Move `scheduleWriteLists` after successful disk write so list updates are not scheduled when the .sql file was never written. - Tolerate missing old collision files instead of throwing `FILE_DOESNT_EXIST`, making the cleanup step non-throwing. - Revert unrelated test relaxation in `03203_system_query_metric_log.sh` (count() > 2 back from >= 2). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…rage-missing-sql-file
If `scheduleWriteLists` throws (e.g. during thread creation), the entity would be in memory and on disk but the caller would see failure. Move it inside the try block and clean up the .sql file in the catch block if the disk write already succeeded. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
…rage-missing-sql-file
…rage-missing-sql-file
…rage-missing-sql-file
…rage-missing-sql-file
…rage-missing-sql-file
…rage-missing-sql-file
…rage-missing-sql-file
…rage-missing-sql-file
…rage-missing-sql-file
…nsertNoLock` If `replace_if_exists` succeeds in writing the new `<id>.sql` but then fails to remove the displaced (different UUID, same name) `<old_id>.sql`, leaving both files on disk would let a later `reloadAllAndRebuildLists` see two same-name entities, which `clearConflictsInEntitiesList` resolves by dropping *all* same-name entries — silently losing the user/role. Move the old-file removal into the same try/catch as the new file write and list-update scheduling, and throw on failure so the existing rollback path restores a single consistent on-disk state. Also adds a `disk_access_storage_remove_old_file_fails` failpoint and an integration test exercising this rollback. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…rage-missing-sql-file # Conflicts: # src/Common/FailPoint.cpp
…rage-missing-sql-file
The gh CLI token used here lacks `workflow` scope, so pushes touching `.github/workflows/*` are rejected. Restore those files byte-identical to the previous PR tip content so the master merge can be pushed.
…rage-missing-sql-file
The previous "restore" commit reverted these files to the PR's old tip to work around a `workflow` scope token limitation, but that made the praktika `Check Workflows` job fail because the generated YAML for `vectorsearchstress.yml` no longer matched what `python3 -m praktika yaml` produces from the current configuration (master switched the runner from `arm-large` to `arm-large-storage`). Bringing all three workflow files to the current master state. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
| /// No pre-existing entity at this UUID: the new file (if any) is orphaned. | ||
| /// Best-effort delete; don't mask the original exception on failure. | ||
| std::error_code ec; | ||
| std::filesystem::remove(new_file_path, ec); |
There was a problem hiding this comment.
<old_id>.sql and <id>.sql on disk while memory/list were rolled back to the old UUID.
That recreates the duplicate-file state this patch is trying to eliminate, and a later reloadAllAndRebuildLists can drop both entries via clearConflictsInEntitiesList.
Please make this path fail-close instead of best-effort: ensure rollback ends with exactly one on-disk file for the name (either fully restore old state or fully commit new state), and surface failure if that invariant cannot be maintained.
There was a problem hiding this comment.
I re-checked the current insertNoLock rollback and this concern is still live.
In the old_entity_at_id == nullptr branch (src/Access/DiskAccessStorage.cpp, around std::filesystem::remove(new_file_path, ec)), cleanup failure is only logged. If that cleanup fails after memory/list rollback, both <old_id>.sql and <id>.sql can remain on disk for the same name, and later reloadAllAndRebuildLists can drop both via conflict cleanup.
Please make this path fail-close so rollback finishes with exactly one on-disk file for the name (or surfaces a hard failure if that invariant cannot be restored).
| throwReadonlyCannotInsert(new_entity->getType(), new_entity->getName()); | ||
|
|
||
| /// In case of name collision old file should be removed. | ||
| /// Capture pre-existing state before any mutation, so the rollback path can restore it. |
There was a problem hiding this comment.
I think we should try to implement a different approach here - first update files, then memory_storage, in order to make them always consistent. I'll try to implement this.
| 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; |
…rage-missing-sql-file
LLVM Coverage Report
Changed lines: 79.41% (54/68) · Uncovered code |
|
Closing in favor of #104411 |
…ertNoLock` cleanup paths The cleanup branches in `insertNoLock` called `std::filesystem::remove` in its throwing form, which can throw `std::filesystem::filesystem_error`: - In the `catch (...)` rollback path, a throw from the cleanup would mask the original exception (e.g. `MEMORY_LIMIT_EXCEEDED` from fault injection) and replace it with a less informative filesystem error. - In the post-commit path that removes a replaced collision file, a cleanup error would turn a successful replacement into a reported failure, even though the new file is already durably on disk and the memory state is consistent. Switch to the `std::error_code` overload and log a warning on failure. The behavior is now "best-effort cleanup", consistent with the preexisting comment that missing files are tolerated. Addresses AI review feedback on ClickHouse#99487
ClickHouse uses `CREATE USER OR REPLACE name`, not the standard SQL `CREATE OR REPLACE USER name`. The latter triggers a `SYNTAX_ERROR` and prevents the failpoint from being exercised. CI failures (all show the same `SYNTAX_ERROR` instead of `FAULT_INJECTED`): ClickHouse#99487
Summary
DiskAccessStorage::insertNoLockexception-safe: ifwriteAccessEntityToDiskfails (e.g. due to memory fault injection in stress tests), roll back thememory_storageinsert so the orphaned entity never appears in the list files.readLists: validate that each listed entity has a corresponding.sqlfile on disk, and triggerreloadAllAndRebuildListsrecovery if any are missing.The root cause:
insertNoLockfirst inserts the entity intomemory_storage, then writes the.sqlfile to disk. If the disk write throws (e.g.MEMORY_LIMIT_EXCEEDEDfrom fault injection), the entity remains in memory and gets persisted to the list files. On restart,DiskAccessStoragefinds the UUID in the list, tries to read the missing.sqlfile, and throws a fatalFILE_DOESNT_EXISTexception that prevents the server from starting.https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=ba724855a1ff39014f1e254183c387b5cf9625eb&name_0=MasterCI&name_1=Stress%20test%20%28amd_msan%29
Test plan
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix server failing to start after an access entity creation was interrupted, leaving an entry in the list file without a corresponding
.sqlfile on disk.🤖 Generated with Claude Code