Skip to content

feat: add --cache-cdc-lazy-cleanup-schedule flag - #1096

Merged
kalbasit merged 3 commits into
mainfrom
feat-add-cache-cdc-lazy-cleanup
Mar 17, 2026
Merged

kalbasit merged 3 commits into
mainfrom
feat-add-cache-cdc-lazy-cleanup

Conversation

@kalbasit

@kalbasit kalbasit commented Mar 16, 2026 •

Copy link
Copy Markdown
Owner

Extract the hardcoded @every 1h CDC cleanup cron schedule into a
configurable flag --cache-cdc-lazy-cleanup-schedule. This allows
operators to tune the cleanup frequency based on their workload without
rebuilding.

The flag is wired through the same sources pattern as other CDC flags
(CLI flag, config file key cache.cdc.lazy-cleanup-schedule, and env var
CACHE_CDC_LAZY_CLEANUP_SCHEDULE), includes cron validation, and defaults
to the previous hardcoded value of @every 1h.

Also adds the flag to the Helm chart (values.yaml + configmap template)
and documents it in the CDC Options table in Reference.md.

@kalbasit

kalbasit commented Mar 16, 2026 •

Copy link
Copy Markdown
Owner Author

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. documentation Improvements or additions to documentation enhancement New feature or request go Pull requests that update go code helm labels Mar 16, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 enhances the Content-Defined Chunking (CDC) feature by externalizing the previously hardcoded cleanup cron schedule into a configurable option. This provides operators with the flexibility to fine-tune the frequency of NAR file cleanup based on their specific workload requirements, thereby improving operational control and adaptability without requiring application recompilation.

Highlights

  • Configurable CDC Cleanup Schedule: Introduced a new configurable flag --cache-cdc-lazy-cleanup-schedule to control the Content-Defined Chunking (CDC) cleanup cron schedule, replacing a hardcoded value.
  • Configuration Integration: The new flag is integrated across CLI arguments, configuration file keys (cache.cdc.lazy-cleanup-schedule), and environment variables (CACHE_CDC_LAZY_CLEANUP_SCHEDULE), including cron expression validation.
  • Helm Chart Support: Updated the Helm chart (values.yaml and configmap.yaml) to expose and support the new lazyCleanupSchedule configuration.
  • Documentation Update: The --cache-cdc-lazy-cleanup-schedule flag has been added to the CDC Options table in the Reference.md user guide.
Changelog
  • charts/ncps/templates/configmap.yaml
    • Added lazy-cleanup-schedule to the CDC configuration within the Helm chart's configmap template.
  • charts/ncps/values.yaml
    • Introduced lazyCleanupSchedule with a default value of @every 1h and descriptive comments in the Helm chart's default values.
  • dev-scripts/run.py
    • Adjusted CDC-related flags, including enabling lazy chunking and modifying recovery/delete schedules for development environments.
  • docs/docs/User Guide/Configuration/Reference.md
    • Expanded the CDC Options table to include the new --cache-cdc-lazy-cleanup-schedule flag and other related lazy chunking flags.
  • pkg/ncps/serve.go
    • Implemented the --cache-cdc-lazy-cleanup-schedule CLI flag with validation.
    • Updated the createCache function to use this configurable schedule for the CDC cleanup cron job.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@dosubot

dosubot Bot commented Mar 16, 2026 •

Copy link
Copy Markdown

Documentation Updates

2 document(s) were updated by changes in this PR:

Cache and Storage Configuration Flags
View Changes
@@ -207,7 +207,7 @@
 - `--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.
+  - 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 (scheduled via `--cache-cdc-lazy-cleanup-schedule`) deletes compressed files that have been replaced by chunks and exceed this delay.
 
 - `--cache-cdc-lazy-recovery-schedule` (string): Cron schedule for recovering stuck NARs in lazy chunking mode. Default: `@every 5m`
   - Environment variable: `CACHE_CDC_LAZY_RECOVERY_SCHEDULE`
@@ -220,6 +220,12 @@
   - YAML key: `cache.cdc.lazy-recovery-batch-size`
   - Helm value: `config.cdc.lazyRecoveryBatchSize`
   - Purpose: Limits the number of stuck NARs that will be recovered in each run to avoid overloading the system. NARs are identified as stuck if they have `total_chunks = 0`, `chunking_started_at = NULL`, and are older than the recovery interval.
+
+- `--cache-cdc-lazy-cleanup-schedule` (string): Cron schedule for the background CDC cleanup job that removes deleted NAR chunks after the `--cache-cdc-delete-delay` period. Default: `@every 1h`
+  - Environment variable: `CACHE_CDC_LAZY_CLEANUP_SCHEDULE`
+  - YAML key: `cache.cdc.lazy-cleanup-schedule`
+  - Helm value: `config.cdc.lazyCleanupSchedule`
+  - Purpose: Controls the schedule for a background cleanup job that deletes compressed NAR files after they have been successfully chunked and the delete delay has expired. Accepts standard cron syntax or special descriptors like `@every 1h`, `@daily`, etc. Allows operators to tune cleanup frequency based on workload.
 
 **Behavior:**
 
@@ -261,6 +267,13 @@
 ncps serve \
   --cache-cdc-enabled \
   --cache-cdc-delete-delay 48h
+```
+
+**CLI Example (custom cleanup schedule):**
+```bash
+ncps serve \
+  --cache-cdc-enabled \
+  --cache-cdc-lazy-cleanup-schedule "@every 30m"
 ```
 
 **YAML Example (using defaults):**
@@ -291,6 +304,7 @@
     delete-delay: 48h
     lazy-recovery-schedule: "@every 10m"
     lazy-recovery-batch-size: 50
+    lazy-cleanup-schedule: "@every 30m"
 ```
 
 **Note:** The existing `migrate-nar-to-chunks` CLI command can still be used for manual chunking of stored NAR files.
@@ -454,6 +468,7 @@
 | LRU schedule timezone | `--cache-lru-schedule-timezone` | `cache.lru.schedule.timezone` | N/A | No       |
 | CDC lazy recovery schedule | `--cache-cdc-lazy-recovery-schedule` | `cache.cdc.lazy-recovery-schedule` | `config.cdc.lazyRecoverySchedule` | No (default: `@every 5m`) |
 | CDC lazy recovery batch size | `--cache-cdc-lazy-recovery-batch-size` | `cache.cdc.lazy-recovery-batch-size` | `config.cdc.lazyRecoveryBatchSize` | No (default: `100`) |
+| CDC lazy cleanup schedule | `--cache-cdc-lazy-cleanup-schedule` | `cache.cdc.lazy-cleanup-schedule` | `config.cdc.lazyCleanupSchedule` | No (default: `@every 1h`) |
 
 * Either local or S3 storage must be configured, not both.  
 ** Required for S3 storage.
NAR File Download and Streaming
View Changes
@@ -253,8 +253,9 @@
 - `--cache-cdc-lazy-chunking-enabled` (default: `true`): Enable lazy chunking for optimal TTFB
 - `--cache-cdc-background-workers` (default: number of CPUs): Number of background workers for asynchronous chunking
 - `--cache-cdc-delete-delay` (default: `24h`): Delay before deleting compressed NAR files after chunking completes
-
-These parameters are also configurable via the Helm chart under `config.cdc` in values.yaml (`lazyChunkingEnabled`, `backgroundWorkers`, `deleteDelay`).
+- `--cache-cdc-lazy-cleanup-schedule` (default: `@every 1h`): Cron schedule for running the cleanup job that removes old compressed NAR files
+
+These parameters are also configurable via the Helm chart under `config.cdc` in values.yaml (`lazyChunkingEnabled`, `backgroundWorkers`, `deleteDelay`, `lazyCleanupSchedule`).
 
 **Serving Logic:**
 
@@ -274,7 +275,7 @@
 - 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:
+A background cleanup job runs on a configurable schedule (via `AddCDCDeletedCleanupCronJob`, default: `@every 1h`) 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

How did I do? Any feedback?  Join Discord

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a configurable 'lazy cleanup schedule' for Content-Defined Chunking (CDC) by adding a new lazyCleanupSchedule option to the Helm chart, application CLI, and documentation. It also updates development scripts to enable lazy chunking and use more aggressive recovery/deletion schedules, and improves observability by adding an informational log for the recovery cron job setup.

@kalbasit
kalbasit force-pushed the fix-include-query-field-in-cdc branch from 1acc555 to 311efcb Compare March 16, 2026 06:06
@kalbasit
kalbasit force-pushed the feat-add-cache-cdc-lazy-cleanup branch from 4ad5f51 to f1d4953 Compare March 16, 2026 06:06
Base automatically changed from fix-include-query-field-in-cdc to main March 16, 2026 18:00
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Mar 16, 2026
@kalbasit
kalbasit force-pushed the feat-add-cache-cdc-lazy-cleanup branch 2 times, most recently from 147a3bf to 425ca74 Compare March 17, 2026 01:13
@github-actions

Copy link
Copy Markdown
Contributor

The serve command was checking !cmd.IsSet() for CDC lazy chunking flags
and manually setting defaults in code. This moves the defaults directly
into the CLI flag definitions using the Value field, making the code
cleaner and consistent with standard Go CLI patterns.

This also updates the Helm chart to default lazyChunkingEnabled to true
instead of null, ensuring the default is explicit in the values.yaml.
Extract the hardcoded '@every 1h' CDC cleanup cron schedule into a
configurable flag --cache-cdc-lazy-cleanup-schedule. This allows
operators to tune the cleanup frequency based on their workload without
rebuilding.

The flag is wired through the same sources pattern as other CDC flags
(CLI flag, config file key cache.cdc.lazy-cleanup-schedule, and env var
CACHE_CDC_LAZY_CLEANUP_SCHEDULE), includes cron validation, and defaults
to the previous hardcoded value of '@every 1h'.

Also adds the flag to the Helm chart (values.yaml + configmap template)
and documents it in the CDC Options table in Reference.md.
@kalbasit
kalbasit changed the base branch from main to fix-use-default-values-instead March 17, 2026 03:48
@kalbasit
kalbasit force-pushed the feat-add-cache-cdc-lazy-cleanup branch from 425ca74 to f29b07b Compare March 17, 2026 03:48
@github-actions

Copy link
Copy Markdown
Contributor

@codecov

codecov Bot commented Mar 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 5.04%. Comparing base (9f8df6b) to head (8077f94).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1096   +/-   ##
=====================================
  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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from fix-use-default-values-instead to main March 17, 2026 04:01
@kalbasit
kalbasit enabled auto-merge (squash) March 17, 2026 04:16
@github-actions

Copy link
Copy Markdown
Contributor

@kalbasit
kalbasit merged commit 7924c85 into main Mar 17, 2026
14 checks passed
@kalbasit
kalbasit deleted the feat-add-cache-cdc-lazy-cleanup branch March 17, 2026 04:27
kalbasit added a commit that referenced this pull request Jun 8, 2026
## 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request go Pull requests that update go code helm size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant