Repository navigation
feat: add --verify-content flag to fsck - #1176
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
There was a problem hiding this comment.
Code Review
This pull request adds an opt-in --verify-content flag to ncps fsck, enabling deep integrity checks for CDC-mode caches by verifying individual chunk hashes and the assembled NAR's NarHash. The implementation includes updates to the CLI, database queries, Helm chart, and documentation. Feedback was provided to switch from io.ReadAll to streaming with io.Copy during chunk verification to prevent potential memory issues and adhere to the design specification.
b2f37a1 to
8fc0b60
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1176 +/- ##
========================================
- Coverage 6.38% 5.04% -1.34%
========================================
Files 6 6
Lines 329 436 +107
========================================
+ Hits 21 22 +1
- Misses 304 410 +106
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Nix build errors like 'bad archive: input doesn't look like a Nix archive' can be caused by bit-rot in CDC chunks that are served without any content verification. The existing fsck only stat-checks that chunk files exist — it never reads or hashes their content. Add an opt-in --verify-content flag that: - Reads and decompresses every chunk via GetChunk, hashes the output with SHA-256, and compares it against the stored BLAKE3 key (narFilesWithCorruptChunks). - For NARs that pass per-chunk checks, assembles the full stream and compares the SHA-256 against the narinfo NarHash field (narFilesWithHashMismatch). - Repairs both categories with the same cascade as broken CDC NARs (nar_file + orphaned narinfo + orphaned chunks). - Shows the two new rows in the fsck summary only when --verify-content is active. The flag is opt-in because reading all chunk bytes is O(total NAR bytes) of I/O and zstd decompression. Combine with --verified-since to limit scope on large caches. Helm chart: adds fsck.verifyContent value (default false) and the corresponding --verify-content arg in the CronJob template. Docs: new usage section, flags reference row, and repair table entries.
Using io.ReadAll to load the full chunk into memory before hashing with blake3.Sum256 risks OOM on large chunks and contradicts the design intent of streaming chunk verification. Replace with blake3.New() + io.Copy so the hasher consumes the reader incrementally without allocating a per-chunk buffer.
8fc0b60 to
b80b574
Compare
## 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)
Nix build errors like 'bad archive: input doesn't look like a
Nix archive' can be caused by bit-rot in CDC chunks that are
served without any content verification. The existing fsck only
stat-checks that chunk files exist — it never reads or hashes
their content.
Add an opt-in --verify-content flag that:
output with SHA-256, and compares it against the stored BLAKE3
key (narFilesWithCorruptChunks).
and compares the SHA-256 against the narinfo NarHash field
(narFilesWithHashMismatch).
NARs (nar_file + orphaned narinfo + orphaned chunks).
--verify-content is active.
The flag is opt-in because reading all chunk bytes is O(total
NAR bytes) of I/O and zstd decompression. Combine with
--verified-since to limit scope on large caches.
Helm chart: adds fsck.verifyContent value (default false) and
the corresponding --verify-content arg in the CronJob template.
Docs: new usage section, flags reference row, and repair table
entries.