filer read write all via locations from MasterClient

This commit is contained in:
Chris Lu
2018-07-28 14:51:36 -07:00
parent 1d779389cb
commit 888eb2abb5
6 changed files with 59 additions and 11 deletions

View File

@@ -2,6 +2,12 @@ package wdclient
import (
"sync"
"strings"
"math/rand"
"errors"
"strconv"
"github.com/chrislusf/seaweedfs/weed/glog"
"fmt"
)
type Location struct {
@@ -14,6 +20,33 @@ type VidMap struct {
vid2Locations map[uint32][]Location
}
func (vc *VidMap) LookupVolumeServerUrl(vid string) (serverUrl string, err error) {
id, err := strconv.Atoi(vid)
if err != nil {
glog.V(1).Infof("Unknown volume id %s", vid)
return "", err
}
locations := vc.GetLocations(uint32(id))
if len(locations) == 0 {
return "", fmt.Errorf("volume %d not found", id)
}
return locations[rand.Intn(len(locations))].Url, nil
}
func (vc *VidMap) LookupFileId(fileId string) (fullUrl string, err error) {
parts := strings.Split(fileId, ",")
if len(parts) != 2 {
return "", errors.New("Invalid fileId " + fileId)
}
serverUrl, lookupError := LookupVolumeServerUrl(parts[0])
if lookupError != nil {
return "", lookupError
}
return "http://" + serverUrl + "/" + fileId, nil
}
func (vc *VidMap) GetLocations(vid uint32) (locations []Location) {
vc.RLock()
defer vc.RUnlock()