Skip to content

Commit

Permalink
Merge pull request radondb#180 from acekingke/fix_bug
Browse files Browse the repository at this point in the history
api,cluster: fix the bug for status reset leader radondb#178
  • Loading branch information
andyli029 authored Aug 19, 2021
2 parents 0ba14ad + ed30007 commit a307b4c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cluster/syncer/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,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
Expand Down
4 changes: 3 additions & 1 deletion cluster/syncer/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
32 changes: 32 additions & 0 deletions utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package utils

import (
"fmt"
"os"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a307b4c

Please sign in to comment.