From 5fbd1ce1710f20e79d455ea04be8ce637324c7f0 Mon Sep 17 00:00:00 2001 From: Evgeniy Date: Mon, 9 Oct 2023 18:52:51 +0300 Subject: [PATCH] A couple of methods transformed to functions --- internal/mysql/node.go | 30 +++++++++++++++--------------- internal/mysql/util.go | 6 ++++-- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/internal/mysql/node.go b/internal/mysql/node.go index 6a694364..bc59abd0 100644 --- a/internal/mysql/node.go +++ b/internal/mysql/node.go @@ -379,18 +379,6 @@ func (n *Node) GetDiskUsage() (used uint64, total uint64, err error) { return } -func (n *Node) isTestFileSystemReadonly(f string) (bool, error) { - data, err := os.ReadFile(f) - if err != nil { - return false, err - } - value, err := strconv.ParseBool(strings.TrimSpace(string(data))) - if err != nil { - return false, fmt.Errorf("error while parce test file: %s", err) - } - return value, nil -} - func getFlagsFromProcMounts(file, filesystem string) (string, error) { for _, line := range strings.Split(file, "\n") { components := strings.Split(line, " ") @@ -414,7 +402,7 @@ func getFlagsFromProcMounts(file, filesystem string) (string, error) { func (n *Node) IsFileSystemReadonly() (bool, error) { if n.config.TestFilesystemReadonlyFile != "" { - return n.isTestFileSystemReadonly(n.config.TestFilesystemReadonlyFile) + return isTestFileSystemReadonly(n.config.TestFilesystemReadonlyFile) } if !n.IsLocal() { return false, ErrNotLocalNode @@ -438,6 +426,18 @@ func (n *Node) IsFileSystemReadonly() (bool, error) { } } +func isTestFileSystemReadonly(f string) (bool, error) { + data, err := os.ReadFile(f) + if err != nil { + return false, err + } + value, err := strconv.ParseBool(strings.TrimSpace(string(data))) + if err != nil { + return false, fmt.Errorf("error while parce test file: %s", err) + } + return value, nil +} + func (n *Node) GetDaemonStartTime() (time.Time, error) { if !n.IsLocal() { return time.Time{}, ErrNotLocalNode @@ -907,7 +907,7 @@ func (n *Node) UpdateExternalCAFile() error { } if data != string(oldDataByte) { n.logger.Infof("saving new CA file to %s", fileName) - err := n.SaveCAFile(data, fileName) + err := SaveCAFile(data, fileName) if err != nil { return err } @@ -927,7 +927,7 @@ func (n *Node) UpdateExternalCAFile() error { return nil } -func (n *Node) SaveCAFile(data string, path string) error { +func SaveCAFile(data string, path string) error { rootCertPool := x509.NewCertPool() byteData := []byte(data) if ok := rootCertPool.AppendCertsFromPEM(byteData); !ok { diff --git a/internal/mysql/util.go b/internal/mysql/util.go index a2ea92cf..1ea18fa3 100644 --- a/internal/mysql/util.go +++ b/internal/mysql/util.go @@ -13,8 +13,10 @@ var dubiousErrorNumbers = []uint16{ 1698, // Symbol: ER_ACCESS_DENIED_NO_PASSWORD_ERROR; SQLSTATE: 28000 } -const channelDoesNotExists = 3074 // Symbol: ER_REPLICA_CHANNEL_DOES_NOT_EXIST; SQLSTATE: HY000 -const tableDoesNotExists = 1146 // Symbol: ER_NO_SUCH_TABLE; SQLSTATE: 42S02 +const ( + channelDoesNotExists = 3074 // Symbol: ER_REPLICA_CHANNEL_DOES_NOT_EXIST; SQLSTATE: HY000 + tableDoesNotExists = 1146 // Symbol: ER_NO_SUCH_TABLE; SQLSTATE: 42S02 +) // IsErrorDubious check that error may be caused by misconfiguration, mysync/scripts bugs // and not related to MySQL/network failure