Repository navigation
feat: persist CDC configuration in database config table - #971
Conversation
Implement boot-time CDC configuration validation and persistence: - Add CDC config keys (cdc_enabled, cdc_min, cdc_avg, cdc_max) to database - Enforce immutable CDC configuration: once enabled, cannot be disabled or changed - Store CDC settings on first boot with CDC enabled - Validate on subsequent boots to prevent accidental configuration changes - Provide detailed error messages when configuration mismatches occur Boot behavior: 1. CDC disabled, no config → no-op (nothing stored) 2. CDC enabled, no config → store all 4 values 3. CDC enabled, config exists, same values → proceed normally 4. CDC enabled, config exists, different values → fail boot with error 5. CDC disabled, config exists (was enabled) → fail boot with error Implementation: - Add sentinel errors: ErrCDCDisabledAfterEnabled, ErrCDCConfigMismatch - Implement ValidateOrStoreCDCConfig() with helper methods for clarity - Call validation in createCache() before SetCDCConfiguration() - Add 7 comprehensive test scenarios covering all boot rules - Support all database backends (SQLite, PostgreSQL, MySQL) All tests pass, code passes linting, no migrations needed (uses existing config table). Co-Authored-By: Claude Haiku 4.5 <[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 introduces a robust mechanism to manage Change Data Capture (CDC) configuration by persisting its settings in the database. This ensures that once CDC is enabled and configured, its parameters remain consistent across application restarts, safeguarding data integrity and preventing accidental misconfigurations that could lead to inaccessible data chunks. The system now validates these settings at boot time, providing clear error messages for any discrepancies, thereby enhancing the reliability and stability of CDC operations. Highlights
Changelog
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 1 document(s) were updated by changes in this PR: NAR File Download and StreamingView Changes@@ -57,24 +57,31 @@
The `migrate-nar-to-chunks` command requires CDC to be enabled via the `--cache-cdc-enabled` flag. If CDC is disabled, the command will return an error: "migrate-nar-to-chunks command requires CDC to be enabled". This ensures that the migration infrastructure is properly configured before attempting to migrate existing NAR files to the chunked storage format.
-> **⚠️ Warning: CDC Configuration is Immutable**
+> **⚠️ CDC Configuration Enforcement**
>
-> CDC configuration is a **one-way operation** that becomes permanent once enabled. Before enabling CDC for the first time, carefully plan your configuration:
+> CDC configuration is validated and enforced at server startup. Once CDC is enabled, the configuration becomes immutable to prevent data inconsistency. Before enabling CDC for the first time, carefully plan your configuration:
>
-> - **Cannot Disable CDC**: Once CDC is enabled (`--cache-cdc-enabled=true`) and NAR data has been chunked, you cannot later disable it. Attempting to start the server with `--cache-cdc-enabled=false` after CDC has been enabled will cause a boot failure with the error: "CDC was previously enabled and cannot be disabled; existing chunks would become inaccessible".
+> **Boot-Time Validation:**
>
-> - **Cannot Change Chunk Sizes**: The CDC chunk size parameters (`--cache-cdc-min`, `--cache-cdc-avg`, `--cache-cdc-max`) are permanently stored in the database on first boot with CDC enabled. Changing any of these values on subsequent boots will cause a boot failure with the error: "CDC configuration mismatch; existing chunks would be inaccessible if values change".
+> The server validates CDC configuration using `ValidateOrStoreCDCConfig()` during startup. CDC settings are persisted to the database `config` table with keys: `cdc_enabled`, `cdc_min`, `cdc_avg`, and `cdc_max`. If validation fails, the server will refuse to start.
>
-> - **Boot-Time Validation**: On every boot, the server validates that the current CDC configuration matches the stored configuration. If any values differ (enabled flag or chunk sizes), the server will fail to start with a detailed error message indicating which values differ (e.g., "cdc_min: stored=65536, current=32768").
+> **Configuration Errors That Prevent Startup:**
>
-> - **Planning Guidance**: Choose your CDC configuration carefully before enabling it for the first time, as it becomes permanent for that deployment. If different CDC parameters are needed later, a new deployment with fresh storage would be required.
+> - **Disabling CDC After Enabled**: Attempting to disable CDC after it was previously enabled will fail with: `"CDC cannot be disabled after being enabled; existing chunked NARs would not be reconstructed"`. This prevents the server from running in a state where existing chunked NAR files cannot be properly reconstructed.
>
-> **Configuration Persistence Behavior:**
-> 1. **CDC disabled, no stored config**: No configuration is stored (no-op).
-> 2. **CDC enabled, no stored config**: All 4 values (enabled flag, min, avg, max) are stored in the database.
-> 3. **CDC enabled, config exists, same values**: Server boots normally.
-> 4. **CDC enabled, config exists, different values**: Server fails to boot with detailed mismatch error.
-> 5. **CDC disabled, config exists (was previously enabled)**: Server fails to boot with error.
+> - **Changing CDC Parameters**: Modifying any CDC chunk size parameter (`--cache-cdc-min`, `--cache-cdc-avg`, `--cache-cdc-max`) after initial configuration will fail with: `"CDC config changed; different chunk sizes create new chunks without reusing old ones, causing storage duplication"`. The error includes specific parameter mismatches (e.g., `"cdc_min: stored=65536, current=32768"`). Changing chunk sizes would create new chunks without reusing existing ones, leading to storage duplication and preventing proper NAR reconstruction.
+>
+> **Boot Scenarios:**
+>
+> 1. **CDC disabled, no stored config**: No configuration is stored (no-op). Server starts normally.
+> 2. **CDC enabled, no stored config**: All 4 configuration values are persisted to the database. Server starts normally.
+> 3. **CDC enabled, config exists, same values**: Configuration validation passes. Server starts normally.
+> 4. **CDC enabled, config exists, different values**: Configuration validation fails with detailed mismatch errors. Server refuses to start.
+> 5. **CDC disabled, config exists (was previously enabled)**: Configuration validation fails. Server refuses to start.
+>
+> **Planning Guidance:**
+>
+> Choose your CDC configuration carefully before enabling it for the first time, as it becomes permanent for that deployment. If different CDC parameters are needed later, a new deployment with fresh storage would be required.
### Error Propagation
Errors encountered during download (e.g., upstream failures, disk write errors) are stored in the `downloadError` field of `downloadState`. Waiting goroutines are signaled via the condition variable, and clients receive the error immediately if it occurs. This ensures that failures are communicated promptly and that resources are cleaned up appropriately [source](https://github.com/kalbasit/ncps/blob/b7653d4303670bb88fd34b8bf82ed3aade09885d/pkg/cache/cache.go#L94-L677). |
There was a problem hiding this comment.
Code Review
This pull request introduces a robust mechanism for persisting and validating CDC configuration in the database, ensuring that once CDC is enabled, its parameters are immutable. The implementation is well-structured, with clear separation of concerns between storing and validating the configuration. The addition of comprehensive, multi-backend tests is excellent and covers all the defined boot-time behaviors.
My review includes a couple of suggestions to simplify the code by removing an unused function parameter and a redundant validation check. Overall, this is a solid feature addition that improves the reliability of the CDC configuration.
Update error messages to accurately describe the issues: - CDC config mismatch: chunks won't be reused, causing storage duplication - CDC disabled after enabled: chunked NARs won't be reconstructed properly Update test assertions to match new error messages. Co-Authored-By: Claude Haiku 4.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #971 +/- ##
=====================================
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:
|
Implement boot-time CDC configuration validation and persistence: - Add CDC config keys (cdc_enabled, cdc_min, cdc_avg, cdc_max) to database - Enforce immutable CDC configuration: once enabled, cannot be disabled or changed - Store CDC settings on first boot with CDC enabled - Validate on subsequent boots to prevent accidental configuration changes - Provide detailed error messages when configuration mismatches occur Boot behavior: 1. CDC disabled, no config → no-op (nothing stored) 2. CDC enabled, no config → store all 4 values 3. CDC enabled, config exists, same values → proceed normally 4. CDC enabled, config exists, different values → fail boot with error 5. CDC disabled, config exists (was enabled) → fail boot with error Implementation: - Add sentinel errors: ErrCDCDisabledAfterEnabled, ErrCDCConfigMismatch - Implement ValidateOrStoreCDCConfig() with helper methods for clarity - Call validation in createCache() before SetCDCConfiguration() - Add 7 comprehensive test scenarios covering all boot rules - Support all database backends (SQLite, PostgreSQL, MySQL) All tests pass, code passes linting, no migrations needed (uses existing config table). --------- Co-authored-by: Claude Haiku 4.5 <[email protected]> (cherry picked from commit 3ba9750)
|
Successfully created backport PR for |
…] (#972) Bot-based backport to `release-0.9`, triggered by a label in #971. Implement boot-time CDC configuration validation and persistence: - Add CDC config keys (cdc_enabled, cdc_min, cdc_avg, cdc_max) to database - Enforce immutable CDC configuration: once enabled, cannot be disabled or changed - Store CDC settings on first boot with CDC enabled - Validate on subsequent boots to prevent accidental configuration changes - Provide detailed error messages when configuration mismatches occur Boot behavior: 1. CDC disabled, no config → no-op (nothing stored) 2. CDC enabled, no config → store all 4 values 3. CDC enabled, config exists, same values → proceed normally 4. CDC enabled, config exists, different values → fail boot with error 5. CDC disabled, config exists (was enabled) → fail boot with error Implementation: - Add sentinel errors: ErrCDCDisabledAfterEnabled, ErrCDCConfigMismatch - Implement ValidateOrStoreCDCConfig() with helper methods for clarity - Call validation in createCache() before SetCDCConfiguration() - Add 7 comprehensive test scenarios covering all boot rules - Support all database backends (SQLite, PostgreSQL, MySQL) All tests pass, code passes linting, no migrations needed (uses existing config table). Co-authored-by: Claude Haiku 4.5 <[email protected]>
## 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)

Implement boot-time CDC configuration validation and persistence:
Boot behavior:
Implementation:
All tests pass, code passes linting, no migrations needed (uses existing config table).