Skip to content

Commit

Permalink
A couple of methods transformed to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
noname0443 committed Oct 9, 2023
1 parent ff1b2f0 commit 5fbd1ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
30 changes: 15 additions & 15 deletions internal/mysql/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, " ")
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions internal/mysql/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5fbd1ce

Please sign in to comment.