Repository navigation
feat: add fsck command to detect and repair DB/storage inconsistencies - #975
Conversation
Adds a new `ncps fsck` command that performs integrity checks between the database and storage backends, detecting orphaned records and missing files. Uses a double-check pattern (collect → re-verify → report → repair) to safely handle in-flight operations without requiring exclusive locks. Checks performed: - Narinfos in DB with no linked nar_file entries - Nar_files in DB not linked to any narinfo - Nar_files in DB whose physical files are missing from storage - NAR files in storage with no corresponding DB record - (CDC mode) Orphaned chunks in DB, chunks missing from storage, orphaned chunk files Flags: --dry-run (preview only), --repair (fix without prompting) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Summary of ChangesHello @kalbasit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request delivers a critical new Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new fsck command, which is a valuable addition for ensuring data integrity. The implementation is comprehensive, covering various types of inconsistencies between the database and storage, and includes a safe multi-phase approach for verification and repair. The code is well-structured and includes extensive tests.
My review focuses on a few key areas:
- Adherence to repository rules: I've noted that some generated files were modified manually, which goes against the established contribution guidelines.
- Performance: I've identified a couple of areas in the verification and repair logic that could be optimized to reduce the number of database queries, especially on large datasets.
- Error Handling: I've pointed out a place where an error is ignored, which could mask underlying data integrity issues.
Overall, this is a solid contribution. Addressing these points will improve the maintainability and performance of the new command.
- Optimize reVerifyFsckSuspects: fetch orphaned chunks once, build a map, then iterate instead of calling GetOrphanedChunks per suspect - Optimize repairFsckIssues: same pattern for orphaned chunk deletion - Fix narFileRowToURL to return an error when url.ParseQuery fails and update all three callers to propagate the error Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new fsck command to detect and repair inconsistencies between the database and storage backends. The implementation is robust, using a double-check pattern to handle in-flight operations safely. The changes include new SQL queries, storage interface extensions, and comprehensive test cases for the new command.
My main feedback is regarding the direct modification of auto-generated database wrapper files, which goes against the repository's contribution guidelines. These files should be updated by modifying the generator script instead. I've also pointed out a minor area for improvement in error handling for better code consistency.
Overall, this is a great feature addition that enhances the tool's reliability.
…g from storage When fsck repairs a nar_file that is missing from storage, deleting the nar_file DB record cascades to remove the narinfo_nar_files join row but leaves the parent narinfo as an orphan. This forced users to run fsck twice to fully clean up a single missing storage file. Fix: after deleting nar_files missing from storage, snapshot the newly orphaned narinfos (by comparing GetNarInfosWithoutNarFiles before and after the deletions) and delete them in the same repair pass. Add TestFsckBackends/.../NarFileMissingInStorageCascadeRepair to verify that a single --repair invocation leaves the database fully clean. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
#975) ## Summary - Adds a new `ncps fsck` command that performs integrity checks between the database and storage backends - Uses a double-check pattern (collect suspects → re-verify → report → optionally repair) to safely handle in-flight operations without exclusive locks - Supports `--dry-run` (preview issues without changes) and `--repair` (fix without prompting) ## Checks performed - Narinfos in DB with no linked `nar_file` entries - `nar_files` in DB not linked to any narinfo (orphaned) - `nar_files` in DB whose physical files are missing from storage - NAR files in storage with no corresponding DB record - (CDC mode) Orphaned chunks in DB, chunks missing from storage, orphaned chunk files in storage ## Changes - New SQL queries (`GetAllNarFiles`, `GetNarInfosWithoutNarFiles`, `GetAllChunks`) added to all 3 DB backends and regenerated - `WalkNars` added to `storage.NarStore` interface with local + S3 implementations - `WalkChunks` added to `chunk.Store` interface with local + S3 implementations - New `pkg/ncps/fsck.go` command implementation - New `pkg/ncps/fsck_test.go` with 7 test cases (clean, narinfos-without-narfiles, orphaned-narfiles, missing-from-storage, orphaned-in-storage, repair, dry-run) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]> (cherry picked from commit 7ef3479)
|
Successfully created backport PR for |
|
Successfully created backport PR for |
…s [backport #975] (#976) Bot-based backport to `release-0.9`, triggered by a label in #975. ## Summary - Adds a new `ncps fsck` command that performs integrity checks between the database and storage backends - Uses a double-check pattern (collect suspects → re-verify → report → optionally repair) to safely handle in-flight operations without exclusive locks - Supports `--dry-run` (preview issues without changes) and `--repair` (fix without prompting) ## Checks performed - Narinfos in DB with no linked `nar_file` entries - `nar_files` in DB not linked to any narinfo (orphaned) - `nar_files` in DB whose physical files are missing from storage - NAR files in storage with no corresponding DB record - (CDC mode) Orphaned chunks in DB, chunks missing from storage, orphaned chunk files in storage ## Changes - New SQL queries (`GetAllNarFiles`, `GetNarInfosWithoutNarFiles`, `GetAllChunks`) added to all 3 DB backends and regenerated - `WalkNars` added to `storage.NarStore` interface with local + S3 implementations - `WalkChunks` added to `chunk.Store` interface with local + S3 implementations - New `pkg/ncps/fsck.go` command implementation - New `pkg/ncps/fsck_test.go` with 7 test cases (clean, narinfos-without-narfiles, orphaned-narfiles, missing-from-storage, orphaned-in-storage, repair, dry-run) ## Test plan - [ ] `go test -race ./pkg/ncps/... -run TestFsck -v` — all subtests pass - [ ] `ncps fsck --help` shows correct flags - [ ] `ncps fsck --dry-run ...` reports issues without modifying anything - [ ] `ncps fsck --repair ...` fixes issues; second run shows 0 issues 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #975 +/- ##
=====================================
Coverage 5.04% 5.04%
=====================================
Files 6 6
Lines 436 436
=====================================
Hits 22 22
Misses 410 410
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
## Summary The `[Unreleased]` section was populated in #1309 but skewed toward the recent CDC-drain, in-flight-staging, and Ent-migration work, omitting several user-facing features and fixes that also landed since v0.9.4. This backfills the missing notable changes, each cross-referenced by PR. **Added** - `ncps fsck` command + Helm fsck CronJob (#975, #996, #998, #999, #1000, #1004, #1006, #1176) - Closure pinning HTTP endpoints `POST`/`DELETE /pin/{hash}.narinfo`, `GET /pins` (#1108) - pprof server via `--pprof-addr` (#1063) - CDC lazy chunking as a feature + `--cache-cdc-lazy-cleanup-schedule` + recovery cron (#1082, #1083, #1089, #1096) - Helm: auto `GOMEMLIMIT` (#1061), configurable temp volume / `volumeClaimTemplate` (#1074, #1077), SQLite `Recreate` strategy (#1012) - Startup storage reporting + deprecated-narinfo warning (#959, #961) - `docker-dev` image (#1097) **Fixed** - `store/tmp` no longer wiped on startup (#1313) - `nix-hash` NAR verification (#1101) - Prometheus counters primed at startup (#1337, #1343) - 404 on un-reassemblable chunked NARs (#1319), purged narinfo no longer 500 (#1318), fail-fast tmp validation (#1086) - Further CDC/cache reliability fixes (#1317, #1346, #1341, #1342, #1331, #1347) **Changed** - CDC config now persisted in the DB config table (#971) Dependency bumps, CI/test-only changes, and the internal Ent-conversion PRs are intentionally excluded; the existing Ent-migration entry already covers that work. ## Test plan - [x] `nix fmt` reports no changes (docs-only edit) - [x] CHANGELOG section structure intact (Added/Fixed/Changed/Removed/Migration/CI)
Summary
ncps fsckcommand that performs integrity checks between the database and storage backends--dry-run(preview issues without changes) and--repair(fix without prompting)Checks performed
nar_fileentriesnar_filesin DB not linked to any narinfo (orphaned)nar_filesin DB whose physical files are missing from storageChanges
GetAllNarFiles,GetNarInfosWithoutNarFiles,GetAllChunks) added to all 3 DB backends and regeneratedWalkNarsadded tostorage.NarStoreinterface with local + S3 implementationsWalkChunksadded tochunk.Storeinterface with local + S3 implementationspkg/ncps/fsck.gocommand implementationpkg/ncps/fsck_test.gowith 7 test cases (clean, narinfos-without-narfiles, orphaned-narfiles, missing-from-storage, orphaned-in-storage, repair, dry-run)Test plan
go test -race ./pkg/ncps/... -run TestFsck -v— all subtests passncps fsck --helpshows correct flagsncps fsck --dry-run ...reports issues without modifying anythingncps fsck --repair ...fixes issues; second run shows 0 issues🤖 Generated with Claude Code