aboutsummaryrefslogtreecommitdiff
path: root/weed/wdclient
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2018-07-28 14:22:46 -0700
committerChris Lu <chris.lu@gmail.com>2018-07-28 14:22:46 -0700
commit1d779389cbf9e5cf19de5ceba136d862c49b9d8f (patch)
tree29de8937565aad998b1737ce5a6ea53b1d5ca505 /weed/wdclient
parent01bcc89803b5caefe6d1809d4a85bc8a1d19918e (diff)
downloadseaweedfs-1d779389cbf9e5cf19de5ceba136d862c49b9d8f.tar.xz
seaweedfs-1d779389cbf9e5cf19de5ceba136d862c49b9d8f.zip
MasterClient replicates all vid locations
Diffstat (limited to 'weed/wdclient')
-rw-r--r--weed/wdclient/masterclient.go12
-rw-r--r--weed/wdclient/vid_map.go59
2 files changed, 71 insertions, 0 deletions
diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go
index fb634d0f0..13383c9f1 100644
--- a/weed/wdclient/masterclient.go
+++ b/weed/wdclient/masterclient.go
@@ -15,6 +15,8 @@ type MasterClient struct {
name string
currentMaster string
masters []string
+
+ VidMap
}
func NewMasterClient(ctx context.Context, clientName string, masters []string) *MasterClient {
@@ -61,6 +63,16 @@ func (mc *MasterClient) tryAllMasters() {
return err
} else {
glog.V(0).Infof("volume location: %+v", volumeLocation)
+ loc := Location{
+ Url: volumeLocation.Url,
+ PublicUrl: volumeLocation.PublicUrl,
+ }
+ for _, newVid := range volumeLocation.NewVids {
+ mc.AddLocation(newVid, loc)
+ }
+ for _, deletedVid := range volumeLocation.DeletedVids {
+ mc.DeleteLocation(deletedVid, loc)
+ }
}
}
})
diff --git a/weed/wdclient/vid_map.go b/weed/wdclient/vid_map.go
new file mode 100644
index 000000000..0eb5ee5d0
--- /dev/null
+++ b/weed/wdclient/vid_map.go
@@ -0,0 +1,59 @@
+package wdclient
+
+import (
+ "sync"
+)
+
+type Location struct {
+ Url string `json:"url,omitempty"`
+ PublicUrl string `json:"publicUrl,omitempty"`
+}
+
+type VidMap struct {
+ sync.RWMutex
+ vid2Locations map[uint32][]Location
+}
+
+func (vc *VidMap) GetLocations(vid uint32) (locations []Location) {
+ vc.RLock()
+ defer vc.RUnlock()
+
+ return vc.vid2Locations[vid]
+}
+
+func (vc *VidMap) AddLocation(vid uint32, location Location) {
+ vc.Lock()
+ defer vc.Unlock()
+
+ locations, found := vc.vid2Locations[vid]
+ if !found {
+ vc.vid2Locations[vid] = []Location{location}
+ return
+ }
+
+ for _, loc := range locations {
+ if loc.Url == location.Url {
+ return
+ }
+ }
+
+ vc.vid2Locations[vid] = append(locations, location)
+
+}
+
+func (vc *VidMap) DeleteLocation(vid uint32, location Location) {
+ vc.Lock()
+ defer vc.Unlock()
+
+ locations, found := vc.vid2Locations[vid]
+ if !found {
+ return
+ }
+
+ for i, loc := range locations {
+ if loc.Url == location.Url {
+ vc.vid2Locations[vid] = append(locations[0:i], locations[i+1:]...)
+ }
+ }
+
+}