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:
Konstantin Lebedev 2024-07-12 23:19:08 +05:00 committed by GitHub
parent 3a82f5ffad
commit 04f4b10884
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 31 additions and 0 deletions

View File

@ -69,6 +69,10 @@ func (ms *MasterServer) Assign(ctx context.Context, req *master_pb.AssignRequest
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)
var (

View File

@ -59,6 +59,8 @@ func (ms *MasterServer) ProcessGrowRequest() {
for _, newVidLocation := range newVidLocations {
ms.broadcastToClients(&master_pb.KeepConnectedResponse{VolumeLocation: newVidLocation})
}
} else {
glog.V(1).Infof("automatic volume grow failed: %+v", err)
}
vl.DoneGrowRequest()

View File

@ -126,6 +126,13 @@ func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request)
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 {
fid, count, dnList, shouldGrow, err := ms.Topo.PickForWrite(requestedCount, option, vl)
if shouldGrow && !vl.HasGrowRequest() {

View File

@ -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 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())
} else if !ms.Topo.DataCenterExists(option.DataCenter) {
err = fmt.Errorf("data center %v not found in topology", option.DataCenter)
} else {
var newVidLocations []*master_pb.VolumeLocation
newVidLocations, err = ms.vg.GrowByCountAndType(ms.grpcDialOption, count, option, ms.Topo)

View File

@ -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 {
t.Lock()
defer t.Unlock()