aboutsummaryrefslogtreecommitdiff
path: root/weed/wdclient
diff options
context:
space:
mode:
Diffstat (limited to 'weed/wdclient')
-rw-r--r--weed/wdclient/masterclient.go11
-rw-r--r--weed/wdclient/vid_map.go18
-rw-r--r--weed/wdclient/vid_map_test.go2
3 files changed, 19 insertions, 12 deletions
diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go
index df8c186f2..e39b9dfdf 100644
--- a/weed/wdclient/masterclient.go
+++ b/weed/wdclient/masterclient.go
@@ -24,14 +24,14 @@ type MasterClient struct {
vidMap
}
-func NewMasterClient(grpcDialOption grpc.DialOption, clientType string, clientHost string, clientGrpcPort uint32, masters []string) *MasterClient {
+func NewMasterClient(grpcDialOption grpc.DialOption, clientType string, clientHost string, clientGrpcPort uint32, clientDataCenter string, masters []string) *MasterClient {
return &MasterClient{
clientType: clientType,
clientHost: clientHost,
grpcPort: clientGrpcPort,
masters: masters,
grpcDialOption: grpcDialOption,
- vidMap: newVidMap(),
+ vidMap: newVidMap(clientDataCenter),
}
}
@@ -89,7 +89,7 @@ func (mc *MasterClient) tryAllMasters() {
}
mc.currentMaster = ""
- mc.vidMap = newVidMap()
+ mc.vidMap = newVidMap("")
}
}
@@ -130,8 +130,9 @@ func (mc *MasterClient) tryConnectToMaster(master string) (nextHintedLeader stri
// process new volume location
loc := Location{
- Url: volumeLocation.Url,
- PublicUrl: volumeLocation.PublicUrl,
+ Url: volumeLocation.Url,
+ PublicUrl: volumeLocation.PublicUrl,
+ DataCenter: volumeLocation.DataCenter,
}
for _, newVid := range volumeLocation.NewVids {
glog.V(1).Infof("%s: %s masterClient adds volume %d", mc.clientType, loc.Url, newVid)
diff --git a/weed/wdclient/vid_map.go b/weed/wdclient/vid_map.go
index cee2da6e1..773da0191 100644
--- a/weed/wdclient/vid_map.go
+++ b/weed/wdclient/vid_map.go
@@ -16,20 +16,22 @@ const (
)
type Location struct {
- Url string `json:"url,omitempty"`
- PublicUrl string `json:"publicUrl,omitempty"`
+ Url string `json:"url,omitempty"`
+ PublicUrl string `json:"publicUrl,omitempty"`
+ DataCenter string `json:"dataCenter,omitempty"`
}
type vidMap struct {
sync.RWMutex
vid2Locations map[uint32][]Location
-
- cursor int32
+ DataCenter string
+ cursor int32
}
-func newVidMap() vidMap {
+func newVidMap(dataCenter string) vidMap {
return vidMap{
vid2Locations: make(map[uint32][]Location),
+ DataCenter: dataCenter,
cursor: -1,
}
}
@@ -56,7 +58,11 @@ func (vc *vidMap) LookupVolumeServerUrl(vid string) (serverUrls []string, err er
return nil, fmt.Errorf("volume %d not found", id)
}
for _, loc := range locations {
- serverUrls = append(serverUrls, loc.Url)
+ if vc.DataCenter == "" || loc.DataCenter == "" || vc.DataCenter != loc.DataCenter {
+ serverUrls = append(serverUrls, loc.Url)
+ } else {
+ serverUrls = append([]string{loc.Url}, serverUrls...)
+ }
}
return
}
diff --git a/weed/wdclient/vid_map_test.go b/weed/wdclient/vid_map_test.go
index 87be2fc25..0cea698ac 100644
--- a/weed/wdclient/vid_map_test.go
+++ b/weed/wdclient/vid_map_test.go
@@ -45,7 +45,7 @@ func TestLocationIndex(t *testing.T) {
mustOk(7, maxCursorIndex, 0)
// test with constructor
- vm = newVidMap()
+ vm = newVidMap("")
length := 7
for i := 0; i < 100; i++ {
got, err := vm.getLocationIndex(length)