From 576c113c594ed82331f5ca7c03dc17aeef96c8c8 Mon Sep 17 00:00:00 2001 From: chrislu Date: Sat, 10 Sep 2022 11:22:16 -0700 Subject: [PATCH] replace PR https://github.com/seaweedfs/seaweedfs/pull/3621 replace https://github.com/seaweedfs/seaweedfs/pull/3621 --- weed/topology/data_center.go | 4 +++- weed/topology/rack.go | 4 +++- weed/topology/topology.go | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/weed/topology/data_center.go b/weed/topology/data_center.go index 35f63b11f..5ffbe4bb8 100644 --- a/weed/topology/data_center.go +++ b/weed/topology/data_center.go @@ -20,7 +20,9 @@ func NewDataCenter(id string) *DataCenter { } func (dc *DataCenter) GetOrCreateRack(rackName string) *Rack { - for _, c := range dc.Children() { + dc.Lock() + defer dc.Unlock() + for _, c := range dc.children { rack := c.(*Rack) if string(rack.Id()) == rackName { return rack diff --git a/weed/topology/rack.go b/weed/topology/rack.go index 97e0a400e..d388e9c61 100644 --- a/weed/topology/rack.go +++ b/weed/topology/rack.go @@ -32,7 +32,9 @@ func (r *Rack) FindDataNode(ip string, port int) *DataNode { return nil } func (r *Rack) GetOrCreateDataNode(ip string, port int, grpcPort int, publicUrl string, maxVolumeCounts map[string]uint32) *DataNode { - for _, c := range r.Children() { + r.Lock() + defer r.Unlock() + for _, c := range r.children { dn := c.(*DataNode) if dn.MatchLocation(ip, port) { dn.LastSeen = time.Now().Unix() diff --git a/weed/topology/topology.go b/weed/topology/topology.go index 35224d280..406ee30f6 100644 --- a/weed/topology/topology.go +++ b/weed/topology/topology.go @@ -258,7 +258,9 @@ func (t *Topology) UnRegisterVolumeLayout(v storage.VolumeInfo, dn *DataNode) { } func (t *Topology) GetOrCreateDataCenter(dcName string) *DataCenter { - for _, c := range t.Children() { + t.Lock() + defer t.Unlock() + for _, c := range t.children { dc := c.(*DataCenter) if string(dc.Id()) == dcName { return dc