Conversation
Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds lifecycle-driven partition synchronization to the database.partitioned module so partition creation can be fully configured via YAML (startup auto-sync + optional periodic re-sync), without requiring application-level Go code.
Changes:
- Introduces
autoSync(defaulting to enabled when asourceTableexists) andsyncIntervalfor periodic re-sync indatabase.partitioned. - Implements startup sync and a stoppable background goroutine for interval-based sync with module lifecycle (
Start/Stop) and logger capture. - Extends the storage plugin factory + schema to surface
autoSyncandsyncIntervalin configuration/UI.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
module/database_partitioned.go |
Adds startup auto-sync and periodic sync goroutine management in module lifecycle. |
plugins/storage/plugin.go |
Parses new config keys and exposes them in the module schema/defaults. |
module/database_partitioned_test.go |
Adds unit tests covering auto-sync defaults, opt-out behavior, interval parsing, and goroutine lifecycle. |
| if autoSync && hasSourceTable { | ||
| if err := p.SyncPartitionsFromSource(ctx); err != nil { | ||
| return fmt.Errorf("partitioned database %q: auto-sync on startup failed: %w", p.name, err) | ||
| } |
There was a problem hiding this comment.
If SyncPartitionsFromSource fails here, the underlying DB connection may already be opened by p.base.Start(). Returning without closing it can leak the connection when engine startup aborts. Consider cleaning up (e.g., p.base.Stop/Close) before returning this error, or use a deferred rollback that runs when Start exits with error.
| interval, err := time.ParseDuration(p.config.SyncInterval) | ||
| if err != nil { | ||
| return fmt.Errorf("partitioned database %q: invalid syncInterval %q: %w", p.name, p.config.SyncInterval, err) | ||
| } |
There was a problem hiding this comment.
If syncInterval parsing fails after p.base.Start() succeeds, Start returns an error but leaves the DB connection opened. Consider closing the base DB (and any started sync state) before returning to avoid leaking resources on startup failure.
| if interval > 0 { | ||
| p.syncStop = make(chan struct{}) | ||
| p.syncWg.Add(1) | ||
| go p.runPeriodicSync(ctx, interval) | ||
| } |
There was a problem hiding this comment.
Periodic sync can be started even when no DB was opened (e.g., DSN empty makes p.base.Start() a no-op). That leads to an always-failing ticker loop and repeated error logs. Consider validating that p.base.DB() is non-nil (or DSN is configured) before launching the goroutine, and return a clear Start error (or skip starting the loop) when it isn’t.
|
@copilot apply changes based on the comments in this thread Build failing, lint failing, test failing, config validation failing |
…ky test Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Applied all four review fixes in df4dd18:
Regarding the CI |
⏱ Benchmark Results✅ No significant performance regressions detected. benchstat comparison (baseline → PR)
|
database.partitionedexposesSyncPartitionsFromSource()but never calls it automatically — consumers must write custom Go code to iterate the service registry post-start. This makes partition sync invisible to YAML config and forces every consumer to rediscover the pattern independently.Changes
module/database_partitioned.goAutoSync *bool— new config field; defaults totruewhen anysourceTableis configured.Start()callsSyncPartitionsFromSource()after the DB connection is established. SetautoSync: falseto opt out.SyncInterval string— duration string (e.g."60s"); when set and asourceTableexists, a background goroutine periodically re-syncs partitions. Errors are logged;Stop()cleanly terminates the goroutine.modular.LoggerinInit()for periodic-sync error reporting.plugins/storage/plugin.goautoSync(bool) andsyncInterval(string) from config map.Example
No application-level Go code required to trigger partition sync.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.