mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-02-09 09:17:28 +08:00
MasterClient replicates all vid locations
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
59
weed/wdclient/vid_map.go
Normal file
59
weed/wdclient/vid_map.go
Normal file
@@ -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:]...)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user