aboutsummaryrefslogtreecommitdiff
path: root/weed/replication/source/filer_source.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-10-07 22:49:04 -0700
committerChris Lu <chris.lu@gmail.com>2020-10-07 22:49:04 -0700
commita8624c2e4f94dce96448f6f3b33fb0f71e1f07df (patch)
tree27083da070f50b49d6b5f4ae96db88159d7d573d /weed/replication/source/filer_source.go
parentda4edf3651d0dd17570057388e5e012eeda4ff80 (diff)
downloadseaweedfs-a8624c2e4f94dce96448f6f3b33fb0f71e1f07df.tar.xz
seaweedfs-a8624c2e4f94dce96448f6f3b33fb0f71e1f07df.zip
read from alternative replica
related to https://github.com/chrislusf/seaweedfs/issues/1512
Diffstat (limited to 'weed/replication/source/filer_source.go')
-rw-r--r--weed/replication/source/filer_source.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/weed/replication/source/filer_source.go b/weed/replication/source/filer_source.go
index 9106ee98b..c3ef8835c 100644
--- a/weed/replication/source/filer_source.go
+++ b/weed/replication/source/filer_source.go
@@ -41,7 +41,7 @@ func (fs *FilerSource) DoInitialize(grpcAddress string, dir string) (err error)
return nil
}
-func (fs *FilerSource) LookupFileId(part string) (fileUrl string, err error) {
+func (fs *FilerSource) LookupFileId(part string) (fileUrls []string, err error) {
vid2Locations := make(map[string]*filer_pb.Locations)
@@ -64,29 +64,38 @@ func (fs *FilerSource) LookupFileId(part string) (fileUrl string, err error) {
if err != nil {
glog.V(1).Infof("LookupFileId volume id %s: %v", vid, err)
- return "", fmt.Errorf("LookupFileId volume id %s: %v", vid, err)
+ return nil, fmt.Errorf("LookupFileId volume id %s: %v", vid, err)
}
locations := vid2Locations[vid]
if locations == nil || len(locations.Locations) == 0 {
glog.V(1).Infof("LookupFileId locate volume id %s: %v", vid, err)
- return "", fmt.Errorf("LookupFileId locate volume id %s: %v", vid, err)
+ return nil, fmt.Errorf("LookupFileId locate volume id %s: %v", vid, err)
}
- fileUrl = fmt.Sprintf("http://%s/%s", locations.Locations[0].Url, part)
+ for _, loc := range locations.Locations {
+ fileUrls = append(fileUrls, fmt.Sprintf("http://%s/%s", loc.Url, part))
+ }
return
}
func (fs *FilerSource) ReadPart(part string) (filename string, header http.Header, resp *http.Response, err error) {
- fileUrl, err := fs.LookupFileId(part)
+ fileUrls, err := fs.LookupFileId(part)
if err != nil {
return "", nil, nil, err
}
- filename, header, resp, err = util.DownloadFile(fileUrl)
+ for _, fileUrl := range fileUrls {
+ filename, header, resp, err = util.DownloadFile(fileUrl)
+ if err != nil {
+ glog.V(1).Infof("fail to read from %s: %v", fileUrl, err)
+ } else {
+ break
+ }
+ }
return filename, header, resp, err
}