mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
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>
This commit is contained in:
parent
4131874fa8
commit
19245dde50
|
@ -5,11 +5,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/security"
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/stats"
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
||||||
"io"
|
"io"
|
||||||
"mime"
|
"mime"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
|
@ -19,6 +14,12 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/security"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/stats"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UploadOption struct {
|
type UploadOption struct {
|
||||||
|
@ -120,7 +121,8 @@ func UploadWithRetry(filerClient filer_pb.FilerClient, assignRequest *filer_pb.A
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
err = util.Retry("uploadWithRetry", doUploadFunc)
|
uploadErrList := []string{"transport", "is read only"}
|
||||||
|
err = util.MultiRetry("uploadWithRetry", uploadErrList, doUploadFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -32,6 +32,29 @@ func Retry(name string, job func() error) (err error) {
|
||||||
return err
|
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)) {
|
func RetryForever(name string, job func() error, onErrFn func(err error) (shouldContinue bool)) {
|
||||||
waitTime := time.Second
|
waitTime := time.Second
|
||||||
for {
|
for {
|
||||||
|
@ -62,3 +85,12 @@ func Nvl(values ...string) string {
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func containErr(err string, errList []string) bool {
|
||||||
|
for _, e := range errList {
|
||||||
|
if strings.Contains(err, e) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue