-
Notifications
You must be signed in to change notification settings - Fork 35
Long wait for SetReadOnly to complete #830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+214
−6
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f69bfac
issue-708: add switchover test
shunki-fujita 36df88e
issue-708: Set lock_wait_timeout to SetReadOnly
shunki-fujita f6f8150
issue-708: use buffered channel
shunki-fujita 3c648ed
issue-708: Change the time to wait for SetReadOnly
shunki-fujita 279db25
issue-708: convert type
shunki-fujita b58bb2d
issue-708: fix error handling
shunki-fujita 9c0a9e7
add switchOverTimeoutSeconds
lrf141 0846b6a
execute test in ordered
lrf141 954b01a
specified the k8s version
lrf141 b64c5b5
fix sql and add test comment
lrf141 3364022
add variable
lrf141 742a083
refactor duplicate process in case of successful switchover
lrf141 70ac6d0
add test for when the timeout is exceeded
lrf141 55b1e87
fix expected test result
lrf141 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| _ "embed" | ||
| "errors" | ||
| "fmt" | ||
| mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| //go:embed testdata/switchover.yaml | ||
| var switchoverYAML string | ||
|
|
||
| var _ = Context("switchover", Ordered, func() { | ||
| if doUpgrade { | ||
| return | ||
| } | ||
|
|
||
| It("should construct a 3-instance cluster", func() { | ||
| kubectlSafe(fillTemplate(switchoverYAML), "apply", "-f", "-") | ||
| Eventually(func() error { | ||
| cluster, err := getCluster("switchover", "test") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| for _, cond := range cluster.Status.Conditions { | ||
| if cond.Type != mocov1beta2.ConditionHealthy { | ||
| continue | ||
| } | ||
| if cond.Status == metav1.ConditionTrue { | ||
| return nil | ||
| } | ||
| return fmt.Errorf("cluster is not healthy: %s", cond.Status) | ||
| } | ||
| return errors.New("no health condition") | ||
| }).Should(Succeed()) | ||
|
|
||
| kubectlSafe(nil, "moco", "mysql", "test", | ||
| "-n", "switchover", | ||
| "-u", "moco-writable", | ||
| "--", "-e", "CREATE DATABASE test;") | ||
| kubectlSafe(nil, "moco", "mysql", "test", | ||
| "-n", "switchover", | ||
| "-u", "moco-admin", | ||
| "--", "-e", "CREATE USER 'user'@'%' IDENTIFIED BY 'abc';") | ||
| kubectlSafe(nil, "moco", "mysql", "test", | ||
| "-n", "switchover", | ||
| "-u", "moco-admin", | ||
| "--", "-e", "GRANT ALL PRIVILEGES ON test.* TO 'user'@'%';") | ||
| kubectlSafe(nil, "moco", "mysql", "test", | ||
| "-n", "switchover", | ||
| "-u", "moco-writable", | ||
| "--", "-e", "CREATE TABLE test.t1 (foo int);") | ||
| kubectlSafe(nil, "moco", "mysql", "test", | ||
| "-n", "switchover", | ||
| "-u", "moco-writable", | ||
| "--", "-e", "INSERT INTO test.t1 (foo) VALUES (1); COMMIT;") | ||
| }) | ||
|
|
||
| It("should switch the primary if requested, even when a long global read lock is acquired", func() { | ||
| cluster, err := getCluster("switchover", "test") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| beforePrimaryIndex := cluster.Status.CurrentPrimaryIndex | ||
|
|
||
| go func() { | ||
| // Calling SLEEP within an UPDATE statement creates a situation where a global read lock is intentionally acquired. | ||
| // The value specified for SLEEP must be less than half the value of `PreStopSeconds`. | ||
| runInPod("mysql", "-u", "user", "-pabc", | ||
| "-h", "moco-test-primary.switchover.svc.cluster.local", "test", | ||
| "-e", "UPDATE test.t1 SET foo = SLEEP(5)") | ||
| }() | ||
| kubectlSafe(nil, "moco", "-n", "switchover", "switchover", "test") | ||
| Eventually(func() int { | ||
| cluster, err := getCluster("switchover", "test") | ||
| if err != nil { | ||
| return 0 | ||
| } | ||
| return cluster.Status.CurrentPrimaryIndex | ||
| }).ShouldNot(Equal(beforePrimaryIndex)) | ||
|
|
||
| Eventually(func() error { | ||
| cluster, err := getCluster("switchover", "test") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| for _, cond := range cluster.Status.Conditions { | ||
| if cond.Type != mocov1beta2.ConditionHealthy { | ||
| continue | ||
| } | ||
| if cond.Status == metav1.ConditionTrue { | ||
| return nil | ||
| } | ||
| return fmt.Errorf("cluster is not healthy: %s", cond.Status) | ||
| } | ||
| return errors.New("no health condition") | ||
| }).Should(Succeed()) | ||
| }) | ||
|
|
||
| It("should switch the primary if requested, even when a holding global read lock exceeds timeout", func() { | ||
| cluster, err := getCluster("switchover", "test") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| beforePrimaryIndex := cluster.Status.CurrentPrimaryIndex | ||
|
|
||
| go func() { | ||
| // Calling SLEEP within an UPDATE statement creates a situation where a global read lock is intentionally acquired. | ||
| // The value specified for SLEEP must be more than half the value of `PreStopSeconds`. | ||
| runInPod("mysql", "-u", "user", "-pabc", | ||
| "-h", "moco-test-primary.switchover.svc.cluster.local", "test", | ||
| "-e", "UPDATE test.t1 SET foo = SLEEP(15)") | ||
| }() | ||
|
|
||
| kubectlSafe(nil, "moco", "-n", "switchover", "switchover", "test") | ||
| Eventually(func() int { | ||
| cluster, err := getCluster("switchover", "test") | ||
| if err != nil { | ||
| return 0 | ||
| } | ||
| return cluster.Status.CurrentPrimaryIndex | ||
| }).ShouldNot(Equal(beforePrimaryIndex)) | ||
|
|
||
| Eventually(func() error { | ||
| cluster, err := getCluster("switchover", "test") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| for _, cond := range cluster.Status.Conditions { | ||
| if cond.Type != mocov1beta2.ConditionHealthy { | ||
| continue | ||
| } | ||
| if cond.Status == metav1.ConditionTrue { | ||
| return nil | ||
| } | ||
| return fmt.Errorf("cluster is not healthy: %s", cond.Status) | ||
| } | ||
| return errors.New("no health condition") | ||
| }).Should(Succeed()) | ||
| }) | ||
|
|
||
| It("should delete clusters", func() { | ||
| kubectlSafe(nil, "delete", "-n", "switchover", "mysqlclusters", "--all") | ||
| verifyAllPodsDeleted("switchover") | ||
| }) | ||
| }) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| apiVersion: v1 | ||
| kind: Namespace | ||
| metadata: | ||
| name: switchover | ||
| --- | ||
| apiVersion: moco.cybozu.com/v1beta2 | ||
| kind: MySQLCluster | ||
| metadata: | ||
| namespace: switchover | ||
| name: test | ||
| spec: | ||
| replicas: 3 | ||
| podTemplate: | ||
| spec: | ||
| containers: | ||
| - name: mysqld | ||
| image: ghcr.io/cybozu-go/moco/mysql:{{ . }} | ||
| volumeClaimTemplates: | ||
| - metadata: | ||
| name: mysql-data | ||
| spec: | ||
| accessModes: [ "ReadWriteOnce" ] | ||
| resources: | ||
| requests: | ||
| storage: 1Gi |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to use 1.33.1, but since
setup-envtestcannot find the 1.33.1 archive.