mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
Merge pull request #3318 from kmlebedev/issues/3310
Use fallback if urls are not found
This commit is contained in:
commit
9667588af0
|
@ -18,6 +18,12 @@ import (
|
|||
"github.com/chrislusf/seaweedfs/weed/wdclient"
|
||||
)
|
||||
|
||||
var getLookupFileIdBackoffSchedule = []time.Duration{
|
||||
150 * time.Millisecond,
|
||||
600 * time.Millisecond,
|
||||
1800 * time.Millisecond,
|
||||
}
|
||||
|
||||
func HasData(entry *filer_pb.Entry) bool {
|
||||
|
||||
if len(entry.Content) > 0 {
|
||||
|
@ -69,14 +75,22 @@ func StreamContent(masterClient wdclient.HasLookupFileIdFunction, writer io.Writ
|
|||
fileId2Url := make(map[string][]string)
|
||||
|
||||
for _, chunkView := range chunkViews {
|
||||
|
||||
urlStrings, err := masterClient.GetLookupFileIdFunction()(chunkView.FileId)
|
||||
var urlStrings []string
|
||||
var err error
|
||||
for _, backoff := range getLookupFileIdBackoffSchedule {
|
||||
urlStrings, err = masterClient.GetLookupFileIdFunction()(chunkView.FileId)
|
||||
if err == nil && len(urlStrings) > 0 {
|
||||
time.Sleep(backoff)
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
glog.V(1).Infof("operation LookupFileId %s failed, err: %v", chunkView.FileId, err)
|
||||
return err
|
||||
} else if len(urlStrings) == 0 {
|
||||
glog.Errorf("operation LookupFileId %s failed, err: urls not found", chunkView.FileId)
|
||||
return fmt.Errorf("operation LookupFileId %s failed, err: urls not found", chunkView.FileId)
|
||||
errUrlNotFound := fmt.Errorf("operation LookupFileId %s failed, err: urls not found", chunkView.FileId)
|
||||
glog.Error(errUrlNotFound)
|
||||
return errUrlNotFound
|
||||
}
|
||||
fileId2Url[chunkView.FileId] = urlStrings
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package wdclient
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/chrislusf/seaweedfs/weed/stats"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
@ -44,7 +45,7 @@ func (mc *MasterClient) GetLookupFileIdFunction() LookupFileIdFunctionType {
|
|||
|
||||
func (mc *MasterClient) LookupFileIdWithFallback(fileId string) (fullUrls []string, err error) {
|
||||
fullUrls, err = mc.vidMap.LookupFileId(fileId)
|
||||
if err == nil {
|
||||
if err == nil && len(fullUrls) > 0 {
|
||||
return
|
||||
}
|
||||
err = pb.WithMasterClient(false, mc.currentMaster, mc.grpcDialOption, func(client master_pb.SeaweedClient) error {
|
||||
|
@ -52,7 +53,7 @@ func (mc *MasterClient) LookupFileIdWithFallback(fileId string) (fullUrls []stri
|
|||
VolumeOrFileIds: []string{fileId},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("LookupVolume failed: %v", err)
|
||||
}
|
||||
for vid, vidLocation := range resp.VolumeIdLocations {
|
||||
for _, vidLoc := range vidLocation.Locations {
|
||||
|
@ -65,7 +66,6 @@ func (mc *MasterClient) LookupFileIdWithFallback(fileId string) (fullUrls []stri
|
|||
fullUrls = append(fullUrls, "http://"+loc.Url+"/"+fileId)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue