Skip to content

feat: persist CDC configuration in database config table [backport #971] - #972

Merged
kalbasit merged 1 commit into
release-0.9from
backport-971-to-release-0.9
Feb 23, 2026
Merged

kalbasit merged 1 commit into
release-0.9from
backport-971-to-release-0.9

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

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).

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)
@kalbasit
kalbasit enabled auto-merge (squash) February 23, 2026 08:15
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request go Pull requests that update go code labels Feb 23, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 robust boot-time validation and persistence for Change Data Capture (CDC) configuration. It ensures that once CDC is enabled, its settings become immutable, preventing accidental changes or disabling that could lead to data inconsistencies. The system now stores CDC parameters in the database upon first enablement and rigorously validates them on subsequent boots, failing with informative errors if discrepancies are detected.

Highlights

  • CDC Configuration Persistence: Added new configuration keys (cdc_enabled, cdc_min, cdc_avg, cdc_max) to be stored in the database, ensuring CDC settings are persisted across restarts.
  • Immutable CDC Configuration: Implemented logic to enforce that once CDC is enabled, it cannot be disabled, nor can its chunking parameters be changed, preventing data consistency issues.
  • Boot-time Validation: Introduced a validation mechanism that checks current CDC configuration against stored values during application boot, failing if discrepancies are found.
  • Detailed Error Reporting: Provided specific error messages for scenarios where CDC is attempted to be disabled after being enabled, or when configuration values mismatch.
  • Comprehensive Testing: Added 7 new test scenarios covering all boot-time CDC configuration rules and ensuring compatibility with SQLite, PostgreSQL, and MySQL database backends.
Changelog
  • pkg/config/config.go
    • Added new constants for CDC configuration keys (KeyCDCEnabled, KeyCDCMin, KeyCDCAvg, KeyCDCMax).
    • Defined new error types: ErrCDCDisabledAfterEnabled and ErrCDCConfigMismatch.
    • Implemented getter and setter methods for CDC configuration values (GetCDCEnabled, SetCDCEnabled, GetCDCMin, SetCDCMin, GetCDCAvg, SetCDCAvg, GetCDCMax, SetCDCMax).
    • Introduced ValidateOrStoreCDCConfig function to handle persistence and validation logic for CDC settings.
    • Added helper functions storeCDCConfig and validateCDCConfig to encapsulate CDC configuration storage and comparison.
  • pkg/config/config_test.go
    • Added a new test suite TestValidateOrStoreCDCConfigBackends to test CDC configuration validation across different database backends (SQLite, PostgreSQL, MySQL).
    • Implemented several test cases for ValidateOrStoreCDCConfig, covering scenarios such as first boot with CDC disabled/enabled, subsequent boots with same/changed flags, and attempting to disable CDC after it was enabled.
  • pkg/ncps/serve.go
    • Integrated the ValidateOrStoreCDCConfig call into the createCache function to perform CDC configuration validation during application startup before setting the CDC configuration.
Activity
  • Bot-based backport to release-0.9 from feat: persist CDC configuration in database config table #971.
  • Implemented boot-time CDC configuration validation and persistence.
  • Added CDC config keys (cdc_enabled, cdc_min, cdc_avg, cdc_max) to the database.
  • Enforced immutable CDC configuration: once enabled, it cannot be disabled or changed.
  • Stored CDC settings on first boot with CDC enabled.
  • Validated on subsequent boots to prevent accidental configuration changes.
  • Provided detailed error messages when configuration mismatches occur.
  • Described boot behavior for various CDC states.
  • Added sentinel errors: ErrCDCDisabledAfterEnabled, ErrCDCConfigMismatch.
  • Implemented ValidateOrStoreCDCConfig() with helper methods for clarity.
  • Called validation in createCache() before SetCDCConfiguration().
  • Added 7 comprehensive test scenarios covering all boot rules.
  • Confirmed support for all database backends (SQLite, PostgreSQL, MySQL).
  • Confirmed all tests pass, code passes linting, and no migrations are needed.
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. ↩

@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 robust mechanism for persisting and validating CDC configuration at boot time. The changes ensure that once CDC is enabled, its configuration is immutable, preventing accidental changes that could lead to storage duplication or data reconstruction issues. The implementation is well-structured with clear separation of concerns for storing and validating the configuration. The test suite is comprehensive, covering all specified boot scenarios across different database backends.

I have one main suggestion for improvement:

  1. The function for storing the initial CDC configuration (storeCDCConfig) is not atomic. A failure midway could leave the database in an inconsistent state.

Overall, this is a great addition that enhances the stability and predictability of the CDC feature.

Comment thread pkg/config/config.go
Comment on lines +218 to +243
func (c *Config) storeCDCConfig(
ctx context.Context,
minSize, avgSize, maxSize uint32,
) error {
minStr := fmt.Sprintf("%d", minSize)
avgStr := fmt.Sprintf("%d", avgSize)
maxStr := fmt.Sprintf("%d", maxSize)

if err := c.SetCDCEnabled(ctx, "true"); err != nil {
return fmt.Errorf("failed to store CDC enabled flag: %w", err)
}

if err := c.SetCDCMin(ctx, minStr); err != nil {
return fmt.Errorf("failed to store CDC min: %w", err)
}

if err := c.SetCDCAvg(ctx, avgStr); err != nil {
return fmt.Errorf("failed to store CDC avg: %w", err)
}

if err := c.SetCDCMax(ctx, maxStr); err != nil {
return fmt.Errorf("failed to store CDC max: %w", err)
}

return nil
}

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.

high

The four Set... calls are executed as separate database operations. This is not atomic. If one of the later calls fails, the configuration will be left in an inconsistent state (e.g., cdc_enabled is true, but other values are missing), which will cause a startup failure on the next boot. To ensure atomicity, all four configuration values should be stored within a single database transaction.

@dosubot

dosubot Bot commented Feb 23, 2026

Copy link
Copy Markdown

Related Documentation

1 document(s) may need updating based on files changed in this PR:

kalbasit's Space

Cache and Storage Configuration Flags
View Suggested Changes
@@ -132,7 +132,7 @@
 
 ### Immutable CDC Settings
 
-Once CDC is enabled (`--cache-cdc-enabled=true`), the CDC configuration is persisted to the database and becomes immutable. The following settings cannot be changed after initial enablement:
+Once CDC is enabled (`--cache-cdc-enabled=true`), the CDC configuration is persisted to the database and becomes immutable. The configuration keys stored in the database are `cdc_enabled`, `cdc_min`, `cdc_avg`, and `cdc_max`. The following settings cannot be changed after initial enablement:
 
 - `--cache-cdc-enabled` (cannot be disabled once enabled)
 - `--cache-cdc-min` (minimum chunk size)
@@ -141,11 +141,11 @@
 
 ### Rationale
 
-CDC configuration immutability is enforced because changing CDC parameters after data has been chunked would make existing chunks inaccessible. Chunks are created using specific CDC parameters, and changing those parameters would prevent the system from correctly identifying and retrieving the stored chunks.
+CDC configuration immutability is enforced because changing CDC parameters after data has been chunked would create new chunks without reusing old ones, causing storage duplication. Disabling CDC after enabling it would prevent chunked NARs from being reconstructed.
 
 ### Boot-Time Validation
 
-On server startup, the system validates that the current CDC configuration matches the stored configuration in the database. The boot behavior depends on the current and stored states:
+On server startup, the `ValidateOrStoreCDCConfig()` function is called during cache creation in the `createCache()` function before `SetCDCConfiguration()` is invoked. This validates that the current CDC configuration matches the stored configuration in the database. The boot behavior depends on the current and stored states:
 
 | Scenario | Stored Config | Current Config | Behavior |
 |----------|--------------|----------------|----------|
@@ -161,12 +161,12 @@
 
 **Attempting to disable CDC after it was enabled:**
 ```
-CDC configuration validation failed: CDC was previously enabled and cannot be disabled; existing chunks would become inaccessible; stored cdc_enabled=true, current cdc_enabled=false
+CDC configuration validation failed: CDC cannot be disabled after being enabled; existing chunked NARs would not be reconstructed; stored cdc_enabled=true, current cdc_enabled=false
 ```
 
 **Attempting to change CDC parameters:**
 ```
-CDC configuration validation failed: CDC configuration mismatch; existing chunks would be inaccessible if values change: cdc_min: stored=8192, current=16384
+CDC configuration validation failed: CDC config changed; different chunk sizes create new chunks without reusing old ones, causing storage duplication: cdc_min: stored=65536, current=32768; cdc_avg: stored=262144, current=131072; cdc_max: stored=1048576, current=524288
 ```
 
 The error message will list all mismatched parameters (e.g., `cdc_enabled`, `cdc_min`, `cdc_avg`, `cdc_max`) along with their stored and current values.

[Accept] [Decline]

Note: You must be authenticated to accept/decline updates.

How did I do? Any feedback?  Join Discord

@codecov

codecov Bot commented Feb 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 5.04%. Comparing base (3e1d66c) to head (9a876b9).
⚠️ Report is 1 commits behind head on release-0.9.

Additional details and impacted files
@@             Coverage Diff             @@
##           release-0.9    #972   +/-   ##
===========================================
  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.

@kalbasit
kalbasit merged commit 87ff172 into release-0.9 Feb 23, 2026
13 checks passed
@kalbasit
kalbasit deleted the backport-971-to-release-0.9 branch February 23, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code 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