mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-19 11:59:24 +08:00
filer read write all via locations from MasterClient
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user