Scheduler: max one instance of a job at a time - #104
Conversation
Scheduled jobs (repset-diff, table-diff, schema-diff) had no overlap protection. If a job took longer than its run_frequency interval, gocron would start a new instance concurrently, stacking connection pools — e.g. 4 overlapping runs × 2 nodes × 10 max_connections = 80 database connections despite a max_connections cap of 10. Add WithSingletonMode(LimitModeReschedule) so gocron skips a tick when the previous run is still in progress. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The discovery and metadata pools in repset-diff and schema-diff were created with empty ConnectionOptions, bypassing the max_connections setting. Also add YAML config fallback in Validate() for both commands so the CLI path is consistent with the scheduled-job and HTTP paths. In practice these pools only open 1-2 short-lived connections, so this aligns them with the table-diff pool code rather than fixing a user-facing issue. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughConnection pooling parameters in diff commands are now derived from configuration when not explicitly set, and passed to connection options. Job scheduler was enhanced to enforce singleton mode with reschedule limiting for both cron and duration-based scheduled jobs. Changes
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Duplication | 2 |
TIP This summary will be updated as you push new changes. Give us feedback
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/consistency/diff/schema_diff.go (1)
228-228: Optional: centralize schema-diff connection options to avoid drift.Both call sites are correct, but using a small helper (like repset) keeps this consistent if options expand later.
♻️ Suggested refactor
@@ func NewSchemaDiffTask() *SchemaDiffCmd { @@ } + +func (c *SchemaDiffCmd) connOpts() auth.ConnectionOptions { + return auth.ConnectionOptions{PoolSize: c.MaxConnections} +} @@ - pool, err := auth.GetClusterNodeConnection(c.Ctx, nodeWithDBInfo, auth.ConnectionOptions{PoolSize: c.MaxConnections}) + pool, err := auth.GetClusterNodeConnection(c.Ctx, nodeWithDBInfo, c.connOpts()) @@ - pool, err := auth.GetClusterNodeConnection(task.Ctx, nodeWithDBInfo, auth.ConnectionOptions{PoolSize: task.MaxConnections}) + pool, err := auth.GetClusterNodeConnection(task.Ctx, nodeWithDBInfo, task.connOpts())Also applies to: 308-308
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/consistency/diff/schema_diff.go` at line 228, Centralize the connection options used when calling auth.GetClusterNodeConnection by extracting the auth.ConnectionOptions{PoolSize: c.MaxConnections} literal into a single helper (e.g., a small function or a shared variable like buildConnectionOptions or repSetConnectionOptions) and replace both call sites in schema_diff.go (calls to GetClusterNodeConnection) to use that helper; ensure the helper accepts context/cluster/node if needed or simply returns the ConnectionOptions so future option additions are made in one place.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/consistency/diff/schema_diff.go`:
- Line 228: Centralize the connection options used when calling
auth.GetClusterNodeConnection by extracting the auth.ConnectionOptions{PoolSize:
c.MaxConnections} literal into a single helper (e.g., a small function or a
shared variable like buildConnectionOptions or repSetConnectionOptions) and
replace both call sites in schema_diff.go (calls to GetClusterNodeConnection) to
use that helper; ensure the helper accepts context/cluster/node if needed or
simply returns the ConnectionOptions so future option additions are made in one
place.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e7ca0a21-99e5-4d90-a426-366430771d9a
📒 Files selected for processing (3)
internal/consistency/diff/repset_diff.gointernal/consistency/diff/schema_diff.gointernal/jobs/scheduler.go
Currently the scheduler will spawn a new job even if the previous one of the same type has not finished. That can happen for small values of
run_frequency.Instead, skip starting the new job if the previous one is still running.
Also, use
max_connectionsfor repset-diff and schema-diff discovery to align with the table-diff pools, even though in practice they only open a connection or two and then close them.ACE-182