Repository navigation
feat: add fsck command to detect and repair DB/storage inconsistencies [backport #975] - #976
Conversation
#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)
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 significantly enhances the data integrity capabilities of the 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 the ncps fsck command, which provides essential integrity checks and repair capabilities for the database and storage backends. The implementation uses a robust double-check pattern to handle concurrent operations safely. My feedback focuses on improving the performance of these checks, particularly for large storage backends like S3, by optimizing storage iteration and database lookups. I also suggested using filepath.WalkDir for better efficiency in local storage walking and adding a terminal check for interactive repairs.
Bot-based backport to
release-0.9, triggered by a label in #975.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