Repository navigation
feat: implement lazy CDC chunking with delayed compressed NAR deletion - #1082
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
Summary of ChangesHello, 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 lazy CDC (Content-Defined Chunking) functionality by addressing a critical bug that led to premature normalization of narinfo compression. The core improvement involves delaying the deletion of original compressed NAR files until a configurable period after they have been chunked. This ensures data integrity and provides a grace period for clients to transition to chunked references, preventing potential data unavailability. A new background cleanup job automates the removal of these old files, streamlining cache management and optimizing storage utilization. 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
|
|
Documentation Updates 2 document(s) were updated by changes in this PR: Cache and Storage Configuration FlagsView Changes@@ -202,6 +202,11 @@
- Environment variable: `CACHE_CDC_BACKGROUND_WORKERS`
- YAML key: `cache.cdc.background-workers`
+- `--cache-cdc-delete-delay` (duration): Delay before deleting compressed NAR files after chunking completes. Default: `24h`
+ - Environment variable: `CACHE_CDC_DELETE_DELAY`
+ - YAML key: `cache.cdc.delete-delay`
+ - Purpose: Controls how long to wait before deleting original compressed NAR files after CDC chunking completes. When lazy chunking is enabled, this delay ensures that compressed NAR files remain available during the transition period, allowing graceful fallback while chunks are being generated in the background. A background cleanup job runs hourly to delete compressed files that have been replaced by chunks and exceed this delay.
+
**Behavior:**
When lazy chunking is enabled (the default), NAR files are:
@@ -231,6 +236,13 @@
--cache-cdc-background-workers 4
```
+**CLI Example (custom delete delay):**
+```bash
+ncps serve \
+ --cache-cdc-enabled \
+ --cache-cdc-delete-delay 48h
+```
+
**YAML Example (using defaults):**
```yaml
cache:
@@ -238,6 +250,7 @@
enabled: true
# lazy-chunking-enabled defaults to true
# background-workers defaults to CPU count
+ # delete-delay defaults to 24h
```
**YAML Example (disabling lazy chunking):**
@@ -255,6 +268,7 @@
enabled: true
lazy-chunking-enabled: true
background-workers: 4
+ delete-delay: 48h
```
**Note:** The existing `migrate-nar-to-chunks` CLI command can still be used for manual chunking of stored NAR files.NAR File Download and StreamingView Changes@@ -252,6 +252,7 @@
**Configuration:**
- `--cache-cdc-lazy-chunking-enabled` (default: `true`): Enable lazy chunking for optimal TTFB
- `--cache-cdc-background-workers` (default: CPU count): Number of background workers for asynchronous chunking
+- `--cache-cdc-delete-delay` (default: `24h`): Delay before deleting compressed NAR files after chunking completes
**Serving Logic:**
@@ -259,7 +260,25 @@
- If `total_chunks > 0`: Serve from CDC chunks for optimal performance and deduplication
- If `total_chunks = 0`: Serve the raw compressed NAR from storage while background workers perform chunking
-This dual-path serving ensures clients receive data immediately while chunking happens asynchronously, maintaining the deduplication benefits of CDC without impacting TTFB.
+**Compression Preservation:**
+
+When lazy chunking is enabled and a NAR file has not yet been chunked (`total_chunks = 0`), the system preserves the original compression format (e.g., xz) and FileSize from the upstream cache in the narinfo response. This ensures clients receive accurate metadata during the chunking transition period. The `pullNarInfo` function skips the compression normalization step that would otherwise convert all CDC-enabled narinfos to `compression=none` immediately, allowing the original compressed NAR to be served until chunking completes.
+
+**Delayed Deletion:**
+
+When lazy chunking is enabled, the system implements delayed deletion of compressed NAR files after chunking completes. Rather than immediately deleting the original compressed NAR when the chunked version becomes available, the system preserves it for a configurable grace period (controlled by `--cache-cdc-delete-delay`, default: 24 hours). This provides:
+
+- A grace period for clients to update their cached narinfo records
+- Graceful degradation if the chunked version encounters issues
+- Reduced risk of cache misses during the transition
+
+A background cleanup job runs hourly (via `AddCDCDeletedCleanupCronJob`) to identify and delete old compressed NAR files that meet all these criteria:
+
+- The compressed NAR has been replaced by a chunked version (`compression != 'none'` and matching hash has `compression = 'none'` with `total_chunks > 0`)
+- The deletion delay has passed since the compressed NAR was created
+- The database record is deleted first, followed by the storage file
+
+This dual-path serving and lifecycle management ensures clients receive data immediately while chunking happens asynchronously, maintaining the deduplication benefits of CDC without impacting TTFB.
To restore the previous behavior where chunking happens synchronously during download, set `--cache-cdc-lazy-chunking-enabled=false`.
|
There was a problem hiding this comment.
Code Review
This pull request introduces lazy CDC chunking with delayed deletion of compressed NARs, which correctly fixes a bug related to premature narinfo normalization. The implementation includes a new configuration flag for the deletion delay and a background cron job for cleanup, which is a solid approach. The changes are well-supported by a new test case. I've provided two suggestions: one to improve the robustness of the cleanup logic and another to address the manual modification of generated files, which should be handled by the generator script as per repository rules.
8cefa7f to
28d9595
Compare
This fixes a bug in lazy CDC chunking where narinfo compression was incorrectly normalized to 'none' even when lazy chunking was enabled and the NAR hadn't been chunked yet. The original compression (e.g., xz) and FileSize are now preserved until chunking completes. Changes: - Fix pullNarInfo to skip normalization when lazy chunking is enabled - Add --cache-cdc-delete-delay flag (default: 24h) to control delayed deletion - Modify migrateNarToChunksCleanup to skip immediate deletion in lazy mode - Add background cleanup job that runs hourly to delete old compressed NARs after delay - Add GetOldCompressedNarFiles and DeleteNarFileByID database queries
28d9595 to
91037f0
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1082 +/- ##
=====================================
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)
feat: implement lazy CDC chunking with delayed compressed NAR deletion
This fixes a bug in lazy CDC chunking where narinfo compression was
incorrectly normalized to 'none' even when lazy chunking was enabled and
the NAR hadn't been chunked yet. The original compression (e.g., xz) and
FileSize are now preserved until chunking completes.
Changes:
deletion
mode
NARs after delay
add some logs