Browse Source

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
pull/5783/head
Konstantin Lebedev 6 months ago
committed by GitHub
parent
commit
04f4b10884
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      weed/server/master_grpc_server_assign.go
  2. 2
      weed/server/master_grpc_server_volume.go
  3. 7
      weed/server/master_server_handlers.go
  4. 2
      weed/server/master_server_handlers_admin.go
  5. 16
      weed/topology/topology.go

4
weed/server/master_grpc_server_assign.go

@ -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 (

2
weed/server/master_grpc_server_volume.go

@ -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()

7
weed/server/master_server_handlers.go

@ -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() {

2
weed/server/master_server_handlers_admin.go

@ -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)

16
weed/topology/topology.go

@ -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()

Loading…
Cancel
Save