mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-11-09 03:56:13 +08:00
fix: avoid timeout if datacenter does not exist in topology (#5772)
* fix: avoid timeout if datacenter does not exist in topology * fix: error msg * fix: rm dublicate check * fix: compare * revert minor change
This commit is contained in:
committed by
GitHub
parent
3a82f5ffad
commit
04f4b10884
@@ -69,6 +69,10 @@ func (ms *MasterServer) Assign(ctx context.Context, req *master_pb.AssignRequest
|
|||||||
MemoryMapMaxSizeMb: req.MemoryMapMaxSizeMb,
|
MemoryMapMaxSizeMb: req.MemoryMapMaxSizeMb,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !ms.Topo.DataCenterExists(option.DataCenter) {
|
||||||
|
return nil, fmt.Errorf("data center %v not found in topology", option.DataCenter)
|
||||||
|
}
|
||||||
|
|
||||||
vl := ms.Topo.GetVolumeLayout(option.Collection, option.ReplicaPlacement, option.Ttl, option.DiskType)
|
vl := ms.Topo.GetVolumeLayout(option.Collection, option.ReplicaPlacement, option.Ttl, option.DiskType)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ func (ms *MasterServer) ProcessGrowRequest() {
|
|||||||
for _, newVidLocation := range newVidLocations {
|
for _, newVidLocation := range newVidLocations {
|
||||||
ms.broadcastToClients(&master_pb.KeepConnectedResponse{VolumeLocation: newVidLocation})
|
ms.broadcastToClients(&master_pb.KeepConnectedResponse{VolumeLocation: newVidLocation})
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
glog.V(1).Infof("automatic volume grow failed: %+v", err)
|
||||||
}
|
}
|
||||||
vl.DoneGrowRequest()
|
vl.DoneGrowRequest()
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,13 @@ func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request)
|
|||||||
startTime = time.Now()
|
startTime = time.Now()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if !ms.Topo.DataCenterExists(option.DataCenter) {
|
||||||
|
writeJsonQuiet(w, r, http.StatusBadRequest, operation.AssignResult{
|
||||||
|
Error: fmt.Sprintf("data center %v not found in topology", option.DataCenter),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for time.Now().Sub(startTime) < maxTimeout {
|
for time.Now().Sub(startTime) < maxTimeout {
|
||||||
fid, count, dnList, shouldGrow, err := ms.Topo.PickForWrite(requestedCount, option, vl)
|
fid, count, dnList, shouldGrow, err := ms.Topo.PickForWrite(requestedCount, option, vl)
|
||||||
if shouldGrow && !vl.HasGrowRequest() {
|
if shouldGrow && !vl.HasGrowRequest() {
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ func (ms *MasterServer) volumeGrowHandler(w http.ResponseWriter, r *http.Request
|
|||||||
if count, err = strconv.Atoi(r.FormValue("count")); err == nil {
|
if count, err = strconv.Atoi(r.FormValue("count")); err == nil {
|
||||||
if ms.Topo.AvailableSpaceFor(option) < int64(count*option.ReplicaPlacement.GetCopyCount()) {
|
if ms.Topo.AvailableSpaceFor(option) < int64(count*option.ReplicaPlacement.GetCopyCount()) {
|
||||||
err = fmt.Errorf("only %d volumes left, not enough for %d", ms.Topo.AvailableSpaceFor(option), count*option.ReplicaPlacement.GetCopyCount())
|
err = fmt.Errorf("only %d volumes left, not enough for %d", ms.Topo.AvailableSpaceFor(option), count*option.ReplicaPlacement.GetCopyCount())
|
||||||
|
} else if !ms.Topo.DataCenterExists(option.DataCenter) {
|
||||||
|
err = fmt.Errorf("data center %v not found in topology", option.DataCenter)
|
||||||
} else {
|
} else {
|
||||||
var newVidLocations []*master_pb.VolumeLocation
|
var newVidLocations []*master_pb.VolumeLocation
|
||||||
newVidLocations, err = ms.vg.GrowByCountAndType(ms.grpcDialOption, count, option, ms.Topo)
|
newVidLocations, err = ms.vg.GrowByCountAndType(ms.grpcDialOption, count, option, ms.Topo)
|
||||||
|
|||||||
@@ -285,6 +285,22 @@ func (t *Topology) UnRegisterVolumeLayout(v storage.VolumeInfo, dn *DataNode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Topology) DataCenterExists(dcName string) bool {
|
||||||
|
return dcName == "" || t.GetOrCreateDataCenter(dcName) != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Topology) GetDataCenter(dcName string) (dc *DataCenter) {
|
||||||
|
t.RLock()
|
||||||
|
defer t.RUnlock()
|
||||||
|
for _, c := range t.children {
|
||||||
|
dc = c.(*DataCenter)
|
||||||
|
if string(dc.Id()) == dcName {
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Topology) GetOrCreateDataCenter(dcName string) *DataCenter {
|
func (t *Topology) GetOrCreateDataCenter(dcName string) *DataCenter {
|
||||||
t.Lock()
|
t.Lock()
|
||||||
defer t.Unlock()
|
defer t.Unlock()
|
||||||
|
|||||||
Reference in New Issue
Block a user