diff --git a/cluster/syncer/statefulset.go b/cluster/syncer/statefulset.go index 512a8561..3f34e95e 100644 --- a/cluster/syncer/statefulset.go +++ b/cluster/syncer/statefulset.go @@ -255,6 +255,11 @@ func (s *StatefulSetSyncer) preUpdate(ctx context.Context, leader, follower stri return nil } + // Touch a new preUpdate file ,indicate that preUpdate is going on + // remove it when it is finished. + // See https://github.com/radondb/radondb-mysql-kubernetes/issues/178 + utils.TouchUpdateFile() + defer utils.RemoveUpdateFile() sctName := s.GetNameForResource(utils.Secret) svcName := s.GetNameForResource(utils.HeadlessSVC) port := utils.MysqlPort diff --git a/cluster/syncer/status.go b/cluster/syncer/status.go index 02df3904..ee20a317 100644 --- a/cluster/syncer/status.go +++ b/cluster/syncer/status.go @@ -204,7 +204,9 @@ func (s *StatusSyncer) updateNodeStatus(ctx context.Context, cli client.Client, node.Message = err.Error() } - if isLeader == corev1.ConditionTrue && isReadOnly != corev1.ConditionFalse { + if !utils.ExistUpdateFile() && + isLeader == corev1.ConditionTrue && + isReadOnly != corev1.ConditionFalse { log.V(1).Info("try to correct the leader writeable", "node", node.Name) runner.RunQuery("SET GLOBAL read_only=off") runner.RunQuery("SET GLOBAL super_read_only=off") diff --git a/utils/common.go b/utils/common.go index 2fb23a39..894a5ee7 100644 --- a/utils/common.go +++ b/utils/common.go @@ -18,6 +18,7 @@ package utils import ( "fmt" + "os" "sort" "strconv" "strings" @@ -58,3 +59,34 @@ func GetOrdinal(name string) (int, error) { } return ordinal, nil } + +// Create the Update file. +func TouchUpdateFile() error { + var err error + var file *os.File + + if file, err = os.Create(FileIndicateUpdate); err != nil { + return err + } + + file.Close() + return nil +} + +// Remove the Update file. +func RemoveUpdateFile() error { + return os.Remove(FileIndicateUpdate) +} + +// Check update file exist. +func ExistUpdateFile() bool { + f, err := os.Open(FileIndicateUpdate) + if os.IsNotExist(err) { + return false + } else if err != nil { + return true + } + + err = f.Close() + return true +} diff --git a/utils/constants.go b/utils/constants.go index 30c5e51f..731ee8e7 100644 --- a/utils/constants.go +++ b/utils/constants.go @@ -86,6 +86,9 @@ const ( // The path to the client MySQL client configuration. // The file used to liveness and readiness check. ConfClientPath = "/etc/mysql/client.conf" + + // preUpdate file + FileIndicateUpdate = "PreUpdating" ) // ResourceName is the type for aliasing resources that will be created.