This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks-controller.git


The following commit(s) were added to refs/heads/unstable by this push:
     new f4f3be0  Fix the error check after Kvrocks removing the ERR prefix 
(#188)
f4f3be0 is described below

commit f4f3be08bcda9aa2d9b7ea6e4cc5169edc1942f8
Author: hulk <[email protected]>
AuthorDate: Sat Jun 22 17:37:15 2024 +0800

    Fix the error check after Kvrocks removing the ERR prefix (#188)
    
    Kvrocks fixes the cluster down error prefix after PR
    https://github.com/apache/kvrocks/pull/236, and we need to compatible
    with this change by checking the error with the string contains.
---
 controller/cluster.go | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/controller/cluster.go b/controller/cluster.go
index 87a28c6..340dd3b 100644
--- a/controller/cluster.go
+++ b/controller/cluster.go
@@ -22,6 +22,7 @@ package controller
 import (
        "context"
        "errors"
+       "strings"
        "sync"
        "time"
 
@@ -32,8 +33,8 @@ import (
 )
 
 var (
-       ErrClusterNotInitialized = errors.New("ERR CLUSTERDOWN The cluster is 
not initialized")
-       ErrRestoringBackUp       = errors.New("ERR LOADING kvrocks is restoring 
the db from backup")
+       ErrClusterNotInitialized = errors.New("CLUSTERDOWN The cluster is not 
initialized")
+       ErrRestoringBackUp       = errors.New("LOADING kvrocks is restoring the 
db from backup")
 )
 
 type ClusterCheckOptions struct {
@@ -106,13 +107,15 @@ func (c *ClusterChecker) WithMaxFailureCount(count int64) 
*ClusterChecker {
 func (c *ClusterChecker) probeNode(ctx context.Context, node store.Node) 
(int64, error) {
        clusterInfo, err := node.GetClusterInfo(ctx)
        if err != nil {
-               switch err.Error() {
-               case ErrRestoringBackUp.Error():
-                       // The node is restoring from backup, just skip it
+               // We need to use the string contains to check the error message
+               // since Kvrocks wrongly returns the error message with `ERR` 
prefix.
+               // And it's fixed in PR: 
https://github.com/apache/kvrocks/pull/2362,
+               // but we need to be compatible with the old version here.
+               if strings.Contains(err.Error(), ErrRestoringBackUp.Error()) {
                        return -1, nil
-               case ErrClusterNotInitialized.Error():
+               } else if strings.Contains(err.Error(), 
ErrClusterNotInitialized.Error()) {
                        return -1, ErrClusterNotInitialized
-               default:
+               } else {
                        return -1, err
                }
        }

Reply via email to