Repository navigation
feat: persist CDC configuration in database config table [backport #971] - #972
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]> (cherry picked from commit 3ba9750)
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 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
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
|
There was a problem hiding this comment.
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:
- 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.
| 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 | ||
| } |
There was a problem hiding this comment.
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.
|
Related Documentation 1 document(s) may need updating based on files changed in this PR: kalbasit's Space Cache and Storage Configuration FlagsView 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.Note: You must be authenticated to accept/decline updates. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Bot-based backport to
release-0.9, triggered by a label in #971.Implement boot-time CDC configuration validation and persistence:
Boot behavior:
Implementation:
All tests pass, code passes linting, no migrations needed (uses existing config table).