aboutsummaryrefslogtreecommitdiff
path: root/weed/util/retry.go
diff options
context:
space:
mode:
authorwusong <75450248+wusongANKANG@users.noreply.github.com>2023-04-21 15:09:31 +0800
committerGitHub <noreply@github.com>2023-04-21 00:09:31 -0700
commit19245dde505bdcd887fa7719d9f6e2bca92ced42 (patch)
treeb601aa1764cba124aa1bd70dcd557197f133e0ba /weed/util/retry.go
parent4131874fa8844d1ed6d71ae1cc839f2fc71a81d2 (diff)
downloadseaweedfs-19245dde505bdcd887fa7719d9f6e2bca92ced42.tar.xz
seaweedfs-19245dde505bdcd887fa7719d9f6e2bca92ced42.zip
mount: add retry for read only case (#4416)
* mount: add retry for read only case Signed-off-by: Wusong Wang <wangwusong@virtaitech.com> * add new util retry function for mount Signed-off-by: Wusong Wang <wangwusong@virtaitech.com> * change error list param Signed-off-by: Wusong Wang <wangwusong@virtaitech.com> --------- Signed-off-by: Wusong Wang <wangwusong@virtaitech.com> Co-authored-by: Wusong Wang <wangwusong@virtaitech.com>
Diffstat (limited to 'weed/util/retry.go')
-rw-r--r--weed/util/retry.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/weed/util/retry.go b/weed/util/retry.go
index fee6074b2..6be052f77 100644
--- a/weed/util/retry.go
+++ b/weed/util/retry.go
@@ -32,6 +32,29 @@ func Retry(name string, job func() error) (err error) {
return err
}
+func MultiRetry(name string, errList []string, job func() error) (err error) {
+ waitTime := time.Second
+ hasErr := false
+ for waitTime < RetryWaitTime {
+ err = job()
+ if err == nil {
+ if hasErr {
+ glog.V(0).Infof("retry %s successfully", name)
+ }
+ break
+ }
+ if containErr(err.Error(), errList) {
+ hasErr = true
+ glog.V(0).Infof("retry %s: err: %v", name, err)
+ } else {
+ break
+ }
+ time.Sleep(waitTime)
+ waitTime += waitTime / 2
+ }
+ return err
+}
+
func RetryForever(name string, job func() error, onErrFn func(err error) (shouldContinue bool)) {
waitTime := time.Second
for {
@@ -62,3 +85,12 @@ func Nvl(values ...string) string {
}
return ""
}
+
+func containErr(err string, errList []string) bool {
+ for _, e := range errList {
+ if strings.Contains(err, e) {
+ return true
+ }
+ }
+ return false
+}