diff options
| author | hilimd <68371223+hilimd@users.noreply.github.com> | 2020-11-05 12:02:47 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-05 12:02:47 +0800 |
| commit | 546f1bcb903dd26ba447cdbedb972736fdb31b42 (patch) | |
| tree | 09b8119faa7162acaa7240de5af6fd0bebe96c2f /weed/filer/reader_at.go | |
| parent | 843865f2ca534bb6286b7a3d79c436384d875608 (diff) | |
| parent | 75887ba2a20b9f3f7ff9c4b8998cf3af0c0f48c2 (diff) | |
| download | seaweedfs-546f1bcb903dd26ba447cdbedb972736fdb31b42.tar.xz seaweedfs-546f1bcb903dd26ba447cdbedb972736fdb31b42.zip | |
Merge pull request #34 from chrislusf/master
sync
Diffstat (limited to 'weed/filer/reader_at.go')
| -rw-r--r-- | weed/filer/reader_at.go | 60 |
1 files changed, 26 insertions, 34 deletions
diff --git a/weed/filer/reader_at.go b/weed/filer/reader_at.go index 04c64d449..ccc746b90 100644 --- a/weed/filer/reader_at.go +++ b/weed/filer/reader_at.go @@ -3,19 +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 { @@ -45,34 +42,29 @@ func LookupFn(filerClient filer_pb.FilerClient) LookupFileIdFunctionType { locations, found := vidCache[vid] vicCacheLock.RUnlock() - waitTime := time.Second - for !found && waitTime < ReadWaitTime { - // println("looking up volume", vid) - err = filerClient.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { - resp, err := client.LookupVolume(context.Background(), &filer_pb.LookupVolumeRequest{ - VolumeIds: []string{vid}, + if !found { + 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}, + }) + if err != nil { + return err + } + + locations = resp.LocationsMap[vid] + if locations == nil || len(locations.Locations) == 0 { + glog.V(0).Infof("failed to locate %s", fileId) + return fmt.Errorf("failed to locate %s", fileId) + } + vicCacheLock.Lock() + vidCache[vid] = locations + vicCacheLock.Unlock() + + return nil }) - if err != nil { - return err - } - - locations = resp.LocationsMap[vid] - if locations == nil || len(locations.Locations) == 0 { - glog.V(0).Infof("failed to locate %s", fileId) - return fmt.Errorf("failed to locate %s", fileId) - } - vicCacheLock.Lock() - vidCache[vid] = locations - vicCacheLock.Unlock() - - return nil + return err }) - if err == nil { - break - } - glog.V(1).Infof("wait for volume %s", vid) - time.Sleep(waitTime) - waitTime += waitTime / 2 } if err != nil { |
