diff options
| author | hilimd <68371223+hilimd@users.noreply.github.com> | 2020-10-10 13:07:57 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-10 13:07:57 +0800 |
| commit | 411e49f96494629fa3da334e8dc7cc15bd4d19cd (patch) | |
| tree | 1756f0a2f86c871a6db67df7ecbd509c9df32233 /weed/replication/source/filer_source.go | |
| parent | ac162fc85769cb1b2a1f8694f9644eae7d0ce6c8 (diff) | |
| parent | 4a15e9c830de1b654515308e5be8380ffa34aefa (diff) | |
| download | seaweedfs-411e49f96494629fa3da334e8dc7cc15bd4d19cd.tar.xz seaweedfs-411e49f96494629fa3da334e8dc7cc15bd4d19cd.zip | |
Merge pull request #23 from chrislusf/master
sync
Diffstat (limited to 'weed/replication/source/filer_source.go')
| -rw-r--r-- | weed/replication/source/filer_source.go | 21 |
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 } |
