Skip to content

Commit a307b4c

Browse files
authored
Merge pull request #180 from acekingke/fix_bug
api,cluster: fix the bug for status reset leader #178
2 parents 0ba14ad + ed30007 commit a307b4c

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

cluster/syncer/statefulset.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ func (s *StatefulSetSyncer) preUpdate(ctx context.Context, leader, follower stri
258258
return nil
259259
}
260260

261+
// Touch a new preUpdate file ,indicate that preUpdate is going on
262+
// remove it when it is finished.
263+
// See https://github.com/radondb/radondb-mysql-kubernetes/issues/178
264+
utils.TouchUpdateFile()
265+
defer utils.RemoveUpdateFile()
261266
sctName := s.GetNameForResource(utils.Secret)
262267
svcName := s.GetNameForResource(utils.HeadlessSVC)
263268
port := utils.MysqlPort

cluster/syncer/status.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ func (s *StatusSyncer) updateNodeStatus(ctx context.Context, cli client.Client,
204204
node.Message = err.Error()
205205
}
206206

207-
if isLeader == corev1.ConditionTrue && isReadOnly != corev1.ConditionFalse {
207+
if !utils.ExistUpdateFile() &&
208+
isLeader == corev1.ConditionTrue &&
209+
isReadOnly != corev1.ConditionFalse {
208210
log.V(1).Info("try to correct the leader writeable", "node", node.Name)
209211
runner.RunQuery("SET GLOBAL read_only=off")
210212
runner.RunQuery("SET GLOBAL super_read_only=off")

utils/common.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package utils
1818

1919
import (
2020
"fmt"
21+
"os"
2122
"sort"
2223
"strconv"
2324
"strings"
@@ -58,3 +59,34 @@ func GetOrdinal(name string) (int, error) {
5859
}
5960
return ordinal, nil
6061
}
62+
63+
// Create the Update file.
64+
func TouchUpdateFile() error {
65+
var err error
66+
var file *os.File
67+
68+
if file, err = os.Create(FileIndicateUpdate); err != nil {
69+
return err
70+
}
71+
72+
file.Close()
73+
return nil
74+
}
75+
76+
// Remove the Update file.
77+
func RemoveUpdateFile() error {
78+
return os.Remove(FileIndicateUpdate)
79+
}
80+
81+
// Check update file exist.
82+
func ExistUpdateFile() bool {
83+
f, err := os.Open(FileIndicateUpdate)
84+
if os.IsNotExist(err) {
85+
return false
86+
} else if err != nil {
87+
return true
88+
}
89+
90+
err = f.Close()
91+
return true
92+
}

utils/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ const (
8686
// The path to the client MySQL client configuration.
8787
// The file used to liveness and readiness check.
8888
ConfClientPath = "/etc/mysql/client.conf"
89+
90+
// preUpdate file
91+
FileIndicateUpdate = "PreUpdating"
8992
)
9093

9194
// ResourceName is the type for aliasing resources that will be created.

0 commit comments

Comments
 (0)