aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-11-01 01:11:08 -0700
committerChris Lu <chris.lu@gmail.com>2020-11-01 01:11:08 -0700
commitf7b21973acb5a405e6a0333b6f630d2a88088a52 (patch)
treec33a78b5436d4af327ab13b38028e7b3d94171eb
parentde86945aeb49e469cc644921beb4f1dbe476e054 (diff)
downloadseaweedfs-f7b21973acb5a405e6a0333b6f630d2a88088a52.tar.xz
seaweedfs-f7b21973acb5a405e6a0333b6f630d2a88088a52.zip
mount: add retry for all operations with filer
fix https://github.com/chrislusf/seaweedfs/issues/1589
-rw-r--r--weed/filesys/wfs_filer_client.go12
-rw-r--r--weed/util/retry.go21
2 files changed, 29 insertions, 4 deletions
diff --git a/weed/filesys/wfs_filer_client.go b/weed/filesys/wfs_filer_client.go
index 096ee555f..5eb3587dd 100644
--- a/weed/filesys/wfs_filer_client.go
+++ b/weed/filesys/wfs_filer_client.go
@@ -1,6 +1,8 @@
package filesys
import (
+ "github.com/chrislusf/seaweedfs/weed/filer"
+ "github.com/chrislusf/seaweedfs/weed/util"
"google.golang.org/grpc"
"github.com/chrislusf/seaweedfs/weed/pb"
@@ -11,10 +13,12 @@ var _ = filer_pb.FilerClient(&WFS{})
func (wfs *WFS) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
- err := pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
- client := filer_pb.NewSeaweedFilerClient(grpcConnection)
- return fn(client)
- }, wfs.option.FilerGrpcAddress, wfs.option.GrpcDialOption)
+ err := util.Retry("filer grpc", filer.ReadWaitTime, func() error {
+ return pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
+ client := filer_pb.NewSeaweedFilerClient(grpcConnection)
+ return fn(client)
+ }, wfs.option.FilerGrpcAddress, wfs.option.GrpcDialOption)
+ })
if err == nil {
return nil
diff --git a/weed/util/retry.go b/weed/util/retry.go
new file mode 100644
index 000000000..7d6d8da23
--- /dev/null
+++ b/weed/util/retry.go
@@ -0,0 +1,21 @@
+package util
+
+import (
+ "time"
+
+ "github.com/chrislusf/seaweedfs/weed/glog"
+)
+
+func Retry(name string, waitTimeLimit time.Duration, job func() error) (err error) {
+ waitTime := time.Second
+ for waitTime < waitTimeLimit {
+ err = job()
+ if err == nil {
+ break
+ }
+ glog.V(1).Infof("retry %s", name)
+ time.Sleep(waitTime)
+ waitTime += waitTime / 2
+ }
+ return err
+} \ No newline at end of file