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/wdclient/vid_map.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/wdclient/vid_map.go')
| -rw-r--r-- | weed/wdclient/vid_map.go | 51 |
1 files changed, 16 insertions, 35 deletions
diff --git a/weed/wdclient/vid_map.go b/weed/wdclient/vid_map.go index 97df49cb6..cee2da6e1 100644 --- a/weed/wdclient/vid_map.go +++ b/weed/wdclient/vid_map.go @@ -44,38 +44,36 @@ func (vc *vidMap) getLocationIndex(length int) (int, error) { return int(atomic.AddInt32(&vc.cursor, 1)) % length, nil } -func (vc *vidMap) LookupVolumeServerUrl(vid string) (serverUrl string, err error) { +func (vc *vidMap) LookupVolumeServerUrl(vid string) (serverUrls []string, err error) { id, err := strconv.Atoi(vid) if err != nil { glog.V(1).Infof("Unknown volume id %s", vid) - return "", err + return nil, err } - return vc.GetRandomLocation(uint32(id)) -} - -func (vc *vidMap) LookupFileId(fileId string) (fullUrl string, err error) { - parts := strings.Split(fileId, ",") - if len(parts) != 2 { - return "", errors.New("Invalid fileId " + fileId) + locations, found := vc.GetLocations(uint32(id)) + if !found { + return nil, fmt.Errorf("volume %d not found", id) } - serverUrl, lookupError := vc.LookupVolumeServerUrl(parts[0]) - if lookupError != nil { - return "", lookupError + for _, loc := range locations { + serverUrls = append(serverUrls, loc.Url) } - return "http://" + serverUrl + "/" + fileId, nil + return } -func (vc *vidMap) LookupVolumeServer(fileId string) (volumeServer string, err error) { +func (vc *vidMap) LookupFileId(fileId string) (fullUrls []string, err error) { parts := strings.Split(fileId, ",") if len(parts) != 2 { - return "", errors.New("Invalid fileId " + fileId) + return nil, errors.New("Invalid fileId " + fileId) } - serverUrl, lookupError := vc.LookupVolumeServerUrl(parts[0]) + serverUrls, lookupError := vc.LookupVolumeServerUrl(parts[0]) if lookupError != nil { - return "", lookupError + return nil, lookupError } - return serverUrl, nil + for _, serverUrl := range serverUrls { + fullUrls = append(fullUrls, "http://"+serverUrl+"/"+fileId) + } + return } func (vc *vidMap) GetVidLocations(vid string) (locations []Location, err error) { @@ -99,23 +97,6 @@ func (vc *vidMap) GetLocations(vid uint32) (locations []Location, found bool) { return } -func (vc *vidMap) GetRandomLocation(vid uint32) (serverUrl string, err error) { - vc.RLock() - defer vc.RUnlock() - - locations := vc.vid2Locations[vid] - if len(locations) == 0 { - return "", fmt.Errorf("volume %d not found", vid) - } - - index, err := vc.getLocationIndex(len(locations)) - if err != nil { - return "", fmt.Errorf("volume %d: %v", vid, err) - } - - return locations[index].Url, nil -} - func (vc *vidMap) addLocation(vid uint32, location Location) { vc.Lock() defer vc.Unlock() |
