aboutsummaryrefslogtreecommitdiff
path: root/weed/wdclient/vid_map.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/wdclient/vid_map.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/wdclient/vid_map.go')
-rw-r--r--weed/wdclient/vid_map.go51
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()