From a82c44972b122ff869ae70e53eea1f8bcc5a67e3 Mon Sep 17 00:00:00 2001 From: chrislu Date: Tue, 20 Jun 2023 00:12:59 -0700 Subject: [PATCH] refactor --- weed/cluster/cluster.go | 4 +--- weed/cluster/group_members.go | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/weed/cluster/cluster.go b/weed/cluster/cluster.go index 2e753812c..52d32f697 100644 --- a/weed/cluster/cluster.go +++ b/weed/cluster/cluster.go @@ -44,9 +44,7 @@ func newClusterNodeGroups() *ClusterNodeGroups { func (g *ClusterNodeGroups) getGroupMembers(filerGroup FilerGroupName, createIfNotFound bool) *GroupMembers { members, found := g.groupMembers[filerGroup] if !found && createIfNotFound { - members = &GroupMembers{ - members: make(map[pb.ServerAddress]*ClusterNode), - } + members = newGroupMembers() g.groupMembers[filerGroup] = members } return members diff --git a/weed/cluster/group_members.go b/weed/cluster/group_members.go index 01b97feae..79bd78790 100644 --- a/weed/cluster/group_members.go +++ b/weed/cluster/group_members.go @@ -9,6 +9,12 @@ type GroupMembers struct { members map[pb.ServerAddress]*ClusterNode } +func newGroupMembers() *GroupMembers { + return &GroupMembers{ + members: make(map[pb.ServerAddress]*ClusterNode), + } +} + func (m *GroupMembers) addMember(dataCenter DataCenter, rack Rack, address pb.ServerAddress, version string) *ClusterNode { if existingNode, found := m.members[address]; found { existingNode.counter++