mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-23 04:03:35 +08:00
erasure coding: tracking encoded/decoded volumes
If an EC shard is created but not spread to other servers, the masterclient would think this shard is not located here.
This commit is contained in:
@@ -159,6 +159,14 @@ func (mc *MasterClient) tryConnectToMaster(master pb.ServerAddress) (nextHintedL
|
||||
glog.V(1).Infof("%s: %s masterClient removes volume %d", mc.clientType, loc.Url, deletedVid)
|
||||
mc.deleteLocation(deletedVid, loc)
|
||||
}
|
||||
for _, newEcVid := range resp.VolumeLocation.NewEcVids {
|
||||
glog.V(1).Infof("%s: %s masterClient adds ec volume %d", mc.clientType, loc.Url, newEcVid)
|
||||
mc.addEcLocation(newEcVid, loc)
|
||||
}
|
||||
for _, deletedEcVid := range resp.VolumeLocation.DeletedEcVids {
|
||||
glog.V(1).Infof("%s: %s masterClient removes ec volume %d", mc.clientType, loc.Url, deletedEcVid)
|
||||
mc.deleteEcLocation(deletedEcVid, loc)
|
||||
}
|
||||
}
|
||||
|
||||
if resp.ClusterNodeUpdate != nil {
|
||||
|
@@ -36,16 +36,18 @@ func (l Location) ServerAddress() pb.ServerAddress {
|
||||
|
||||
type vidMap struct {
|
||||
sync.RWMutex
|
||||
vid2Locations map[uint32][]Location
|
||||
DataCenter string
|
||||
cursor int32
|
||||
vid2Locations map[uint32][]Location
|
||||
ecVid2Locations map[uint32][]Location
|
||||
DataCenter string
|
||||
cursor int32
|
||||
}
|
||||
|
||||
func newVidMap(dataCenter string) vidMap {
|
||||
return vidMap{
|
||||
vid2Locations: make(map[uint32][]Location),
|
||||
DataCenter: dataCenter,
|
||||
cursor: -1,
|
||||
vid2Locations: make(map[uint32][]Location),
|
||||
ecVid2Locations: make(map[uint32][]Location),
|
||||
DataCenter: dataCenter,
|
||||
cursor: -1,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +126,13 @@ func (vc *vidMap) GetLocations(vid uint32) (locations []Location, found bool) {
|
||||
vc.RLock()
|
||||
defer vc.RUnlock()
|
||||
|
||||
glog.V(4).Infof("~ lookup volume id %d: %+v ec:%+v", vid, vc.vid2Locations, vc.ecVid2Locations)
|
||||
|
||||
locations, found = vc.vid2Locations[vid]
|
||||
if found && len(locations) > 0 {
|
||||
return
|
||||
}
|
||||
locations, found = vc.ecVid2Locations[vid]
|
||||
return
|
||||
}
|
||||
|
||||
@@ -132,6 +140,8 @@ func (vc *vidMap) addLocation(vid uint32, location Location) {
|
||||
vc.Lock()
|
||||
defer vc.Unlock()
|
||||
|
||||
glog.V(4).Infof("+ volume id %d: %+v", vid, location)
|
||||
|
||||
locations, found := vc.vid2Locations[vid]
|
||||
if !found {
|
||||
vc.vid2Locations[vid] = []Location{location}
|
||||
@@ -148,10 +158,34 @@ func (vc *vidMap) addLocation(vid uint32, location Location) {
|
||||
|
||||
}
|
||||
|
||||
func (vc *vidMap) addEcLocation(vid uint32, location Location) {
|
||||
vc.Lock()
|
||||
defer vc.Unlock()
|
||||
|
||||
glog.V(4).Infof("+ ec volume id %d: %+v", vid, location)
|
||||
|
||||
locations, found := vc.ecVid2Locations[vid]
|
||||
if !found {
|
||||
vc.ecVid2Locations[vid] = []Location{location}
|
||||
return
|
||||
}
|
||||
|
||||
for _, loc := range locations {
|
||||
if loc.Url == location.Url {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
vc.ecVid2Locations[vid] = append(locations, location)
|
||||
|
||||
}
|
||||
|
||||
func (vc *vidMap) deleteLocation(vid uint32, location Location) {
|
||||
vc.Lock()
|
||||
defer vc.Unlock()
|
||||
|
||||
glog.V(4).Infof("- volume id %d: %+v", vid, location)
|
||||
|
||||
locations, found := vc.vid2Locations[vid]
|
||||
if !found {
|
||||
return
|
||||
@@ -165,3 +199,23 @@ func (vc *vidMap) deleteLocation(vid uint32, location Location) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (vc *vidMap) deleteEcLocation(vid uint32, location Location) {
|
||||
vc.Lock()
|
||||
defer vc.Unlock()
|
||||
|
||||
glog.V(4).Infof("- ec volume id %d: %+v", vid, location)
|
||||
|
||||
locations, found := vc.ecVid2Locations[vid]
|
||||
if !found {
|
||||
return
|
||||
}
|
||||
|
||||
for i, loc := range locations {
|
||||
if loc.Url == location.Url {
|
||||
vc.ecVid2Locations[vid] = append(locations[0:i], locations[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user