Prevent MySQLCluster controller startup slowdown in large clusters#924
Merged
Conversation
Signed-off-by: sho-iizuka <sho-iizuka@cybozu.co.jp>
Signed-off-by: sho-iizuka <sho-iizuka@cybozu.co.jp>
Signed-off-by: sho-iizuka <sho-iizuka@cybozu.co.jp>
Signed-off-by: sho-iizuka <sho-iizuka@cybozu.co.jp>
26b0b64 to
414cfca
Compare
Closed
5 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses MOCO controller startup slowdowns in namespaces with many MySQLCluster objects and secondary resources (e.g., ConfigMap, BackupPolicy) by replacing expensive “list all clusters then scan” watch handlers with field-index-based lookups. It also adds an envtest regression test to ensure the controller can start promptly even with large numbers of pre-existing objects, and improves Ginkgo goroutine failure reporting.
Changes:
- Index
MySQLClusterbyspec.mysqlConfigMapNameandspec.backupPolicyName, and useclient.MatchingFieldsin secondary-resource event handlers. - Add a large-scale startup regression test that creates 1000
MySQLCluster+ 1000ConfigMapobjects before starting the manager. - Update test goroutines to use
defer GinkgoRecover()and add focused-test execution instructions.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| controllers/mysqlcluster_controller.go | Replaces secondary watch list-and-scan handlers with field-index lookups for ConfigMap/BackupPolicy references. |
| cmd/moco-controller/cmd/run.go | Passes a context into MySQLClusterReconciler.SetupWithManager and reuses the signal context consistently. |
| controllers/mysqlcluster_controller_slowdown_test.go | Adds an envtest regression test covering large-scale controller startup behavior. |
| controllers/mysqlcluster_controller_test.go | Updates controller setup call signature and improves goroutine failure reporting with GinkgoRecover. |
| controllers/pod_watcher_test.go | Improves goroutine failure reporting with GinkgoRecover and Gomega assertions. |
| controllers/partition_controller_test.go | Improves goroutine failure reporting with GinkgoRecover and Gomega assertions. |
| clustering/manager_test.go | Improves goroutine failure reporting with GinkgoRecover and Gomega assertions. |
| .github/instructions/focused-tests.instructions.md | Documents preferred Makefile-based focused test execution paths for MOCO. |
Contributor
|
@arosh |
…owdown-test Signed-off-by: sho-iizuka <sho-iizuka@cybozu.co.jp>
Member
Author
yoheinbb
approved these changes
Jul 1, 2026
yamatcha
approved these changes
Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the main cause of issue #922.
It reduces the startup cost of
moco-controllerwhen manyMySQLClusterand secondary resources exist in the same namespace.The current implementation scanned all
MySQLClusterobjects for eachConfigMapandBackupPolicyevent. This became expensive after the controller-runtime upgrade and could make cache sync fail during controller startup. In that case, MOCO failover and switchover could be unavailable because all controller replicas might fail to become ready.Context
After upgrading to controller-runtime 0.23.x, controller startup became more sensitive to slow event handlers during initial cache sync.
In MOCO, the
MySQLClusterReconcilerwatches secondary resources such asConfigMapandBackupPolicy. The old handlers used a list-and-scan pattern, so startup work increased too much in large-scale environments. This was the root cause behind the cache sync timeout described in issue #922.Implementation
This PR replaces the list-and-scan logic with field index lookups.
MySQLClusterobjects are now indexed by:spec.mysqlConfigMapNamespec.backupPolicyNameDuring
ConfigMapandBackupPolicyevents, the reconciler now lists only matchingMySQLClusterobjects by usingclient.MatchingFields, instead of scanning every cluster in the namespace.This PR also adds a startup regression test for the
MySQLClustercontroller. The test creates 1000MySQLClusterobjects and 1000ConfigMapobjects before the manager starts, then checks that the controller can still start and process initial events in time.Note
In addition, test startup goroutines were updated to use
GinkgoRecoverso failures are reported correctly, and focused test instructions were added to make the new test easier to run.