Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

move to util.RetryWaitTime

Chris Lu8750cac09054
diff --git a/weed/command/mount_std.go b/weed/command/mount_std.go
index 649450e542..83cb352ffc 100644
--- a/weed/command/mount_std.go
+++ b/weed/command/mount_std.go
@@ -5,8 +5,6 @@ package command
import (
"context"
"fmt"
- "github.com/chrislusf/seaweedfs/weed/filer"
- "github.com/chrislusf/seaweedfs/weed/filesys/meta_cache"
"os"
"os/user"
"path"
@@ -15,6 +13,8 @@ import (
"strings"
"time"
+ "github.com/chrislusf/seaweedfs/weed/filesys/meta_cache"
+
"github.com/seaweedfs/fuse"
"github.com/seaweedfs/fuse/fs"
@@ -33,7 +33,7 @@ func runMount(cmd *Command, args []string) bool {
if *mountReadRetryTime < time.Second {
*mountReadRetryTime = time.Second
}
- filer.ReadWaitTime = *mountReadRetryTime
+ util.RetryWaitTime = *mountReadRetryTime
umask, umaskErr := strconv.ParseUint(*mountOptions.umaskString, 8, 64)
if umaskErr != nil {
diff --git a/weed/filer/filechunk_manifest.go b/weed/filer/filechunk_manifest.go
index 0d01a4a363..f5ab36d375 100644
--- a/weed/filer/filechunk_manifest.go
+++ b/weed/filer/filechunk_manifest.go
@@ -99,7 +99,7 @@ func retriedFetchChunkData(urlStrings []string, cipherKey []byte, isGzipped bool
var buffer bytes.Buffer
var shouldRetry bool
- for waitTime := time.Second; waitTime < ReadWaitTime; waitTime += waitTime / 2 {
+ for waitTime := time.Second; waitTime < util.RetryWaitTime; waitTime += waitTime / 2 {
for _, urlString := range urlStrings {
shouldRetry, err = util.ReadUrlAsStream(urlString+"?readDeleted=true", cipherKey, isGzipped, isFullChunk, offset, size, func(data []byte) {
buffer.Write(data)
diff --git a/weed/filer/reader_at.go b/weed/filer/reader_at.go
index 3890bfe54d..ccc746b906 100644
--- a/weed/filer/reader_at.go
+++ b/weed/filer/reader_at.go
@@ -3,20 +3,16 @@ package filer
import (
"context"
"fmt"
+ "io"
+ "math/rand"
+ "sync"
+
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/chrislusf/seaweedfs/weed/util"
"github.com/chrislusf/seaweedfs/weed/util/chunk_cache"
"github.com/chrislusf/seaweedfs/weed/wdclient"
"github.com/golang/groupcache/singleflight"
- "io"
- "math/rand"
- "sync"
- "time"
-)
-
-var (
- ReadWaitTime = 6 * time.Second
)
type ChunkReadAt struct {
@@ -47,7 +43,7 @@ func LookupFn(filerClient filer_pb.FilerClient) LookupFileIdFunctionType {
vicCacheLock.RUnlock()
if !found {
- util.Retry("lookup volume "+vid, ReadWaitTime, func() error {
+ util.Retry("lookup volume "+vid, func() error {
err = filerClient.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
resp, err := client.LookupVolume(context.Background(), &filer_pb.LookupVolumeRequest{
VolumeIds: []string{vid},
diff --git a/weed/filesys/meta_cache/meta_cache_init.go b/weed/filesys/meta_cache/meta_cache_init.go
index 3461babcbd..4089cea28b 100644
--- a/weed/filesys/meta_cache/meta_cache_init.go
+++ b/weed/filesys/meta_cache/meta_cache_init.go
@@ -16,7 +16,7 @@ func EnsureVisited(mc *MetaCache, client filer_pb.FilerClient, dirPath util.Full
glog.V(4).Infof("ReadDirAllEntries %s ...", path)
- util.Retry("ReadDirAllEntries", filer.ReadWaitTime, func() error {
+ util.Retry("ReadDirAllEntries", func() error {
err = filer_pb.ReadDirAllEntries(client, dirPath, "", func(pbEntry *filer_pb.Entry, isLast bool) error {
entry := filer.FromPbEntry(string(dirPath), pbEntry)
if err := mc.doInsertEntry(context.Background(), entry); err != nil {
diff --git a/weed/filesys/wfs_filer_client.go b/weed/filesys/wfs_filer_client.go
index 5eb3587dd1..dd76f5669a 100644
--- a/weed/filesys/wfs_filer_client.go
+++ b/weed/filesys/wfs_filer_client.go
@@ -1,7 +1,6 @@
package filesys
import (
- "github.com/chrislusf/seaweedfs/weed/filer"
"github.com/chrislusf/seaweedfs/weed/util"
"google.golang.org/grpc"
@@ -13,7 +12,7 @@ var _ = filer_pb.FilerClient(&WFS{})
func (wfs *WFS) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
- err := util.Retry("filer grpc", filer.ReadWaitTime, func() error {
+ err := util.Retry("filer grpc", func() error {
return pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
return fn(client)
diff --git a/weed/util/retry.go b/weed/util/retry.go
index 6dccadddb6..faaab0351a 100644
--- a/weed/util/retry.go
+++ b/weed/util/retry.go
@@ -7,10 +7,12 @@ import (
"github.com/chrislusf/seaweedfs/weed/glog"
)
-func Retry(name string, waitTimeLimit time.Duration, job func() error) (err error) {
+var RetryWaitTime = 6 * time.Second
+
+func Retry(name string, job func() error) (err error) {
waitTime := time.Second
hasErr := false
- for waitTime < waitTimeLimit {
+ for waitTime < RetryWaitTime {
err = job()
if err == nil {
if hasErr {
@@ -26,4 +28,4 @@ func Retry(name string, waitTimeLimit time.Duration, job func() error) (err erro
}
}
return err
-}
\ No newline at end of file
+}
diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go
index 7a367bfd98..df8c186f29 100644
--- a/weed/wdclient/masterclient.go
+++ b/weed/wdclient/masterclient.go
@@ -151,7 +151,7 @@ func (mc *MasterClient) tryConnectToMaster(master string) (nextHintedLeader stri
}
func (mc *MasterClient) WithClient(fn func(client master_pb.SeaweedClient) error) error {
- return util.Retry("master grpc", 6*time.Second, func() error {
+ return util.Retry("master grpc", func() error {
for mc.currentMaster == "" {
time.Sleep(3 * time.Second)
}