From 7192a378ccd6c3c0db8fe567e95a44210202f0f7 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 1 Nov 2020 01:40:16 -0700 Subject: [PATCH] add retry to master clients also --- weed/util/retry.go | 9 +++++++-- weed/wdclient/masterclient.go | 14 +++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/weed/util/retry.go b/weed/util/retry.go index 65cf07b41..6dccadddb 100644 --- a/weed/util/retry.go +++ b/weed/util/retry.go @@ -9,13 +9,18 @@ import ( func Retry(name string, waitTimeLimit time.Duration, job func() error) (err error) { waitTime := time.Second + hasErr := false for waitTime < waitTimeLimit { err = job() if err == nil { + if hasErr { + glog.V(0).Infof("retry %s successfully", name) + } break } - if strings.Contains(err.Error(), "transport: ") { - glog.V(1).Infof("retry %s", name) + if strings.Contains(err.Error(), "transport") { + hasErr = true + glog.V(0).Infof("retry %s", name) time.Sleep(waitTime) waitTime += waitTime / 2 } diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go index 60753e582..01df6a38a 100644 --- a/weed/wdclient/masterclient.go +++ b/weed/wdclient/masterclient.go @@ -5,6 +5,8 @@ import ( "math/rand" "time" + "github.com/chrislusf/seaweedfs/weed/filer" + "github.com/chrislusf/seaweedfs/weed/util" "google.golang.org/grpc" "github.com/chrislusf/seaweedfs/weed/glog" @@ -150,10 +152,12 @@ func (mc *MasterClient) tryConnectToMaster(master string) (nextHintedLeader stri } func (mc *MasterClient) WithClient(fn func(client master_pb.SeaweedClient) error) error { - for mc.currentMaster == "" { - time.Sleep(3 * time.Second) - } - return pb.WithMasterClient(mc.currentMaster, mc.grpcDialOption, func(client master_pb.SeaweedClient) error { - return fn(client) + return util.Retry("master grpc", filer.ReadWaitTime, func() error { + for mc.currentMaster == "" { + time.Sleep(3 * time.Second) + } + return pb.WithMasterClient(mc.currentMaster, mc.grpcDialOption, func(client master_pb.SeaweedClient) error { + return fn(client) + }) }) }