This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go-pixiu.git


The following commit(s) were added to refs/heads/develop by this push:
     new 1c620957 fix cluster nil bug
     new d26000a1 Merge pull request #439 from ztelur/bugfix-0.5.1
1c620957 is described below

commit 1c6209573ffa9d337064ddbc2b7026179bc1bbaf
Author: randy <[email protected]>
AuthorDate: Sun Jun 5 16:52:51 2022 +0800

    fix cluster nil bug
---
 pkg/server/cluster_manager.go | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/pkg/server/cluster_manager.go b/pkg/server/cluster_manager.go
index d91894cc..c59e32fc 100644
--- a/pkg/server/cluster_manager.go
+++ b/pkg/server/cluster_manager.go
@@ -134,7 +134,7 @@ func (cm *ClusterManager) NewStore(version int32) 
*ClusterStore {
        cm.rw.Lock()
        defer cm.rw.Unlock()
 
-       return &ClusterStore{Version: version}
+       return &ClusterStore{Version: version, clustersMap: 
map[string]*cluster.Cluster{}}
 }
 
 func (cm *ClusterManager) CompareAndSetStore(store *ClusterStore) bool {
@@ -236,6 +236,11 @@ func (s *ClusterStore) UpdateCluster(new 
*model.ClusterConfig) {
 
 func (s *ClusterStore) SetEndpoint(clusterName string, endpoint 
*model.Endpoint) {
        cluster := s.clustersMap[clusterName]
+       if cluster == nil {
+               c := &model.ClusterConfig{Name: clusterName, LbStr: 
model.LoadBalancerRoundRobin, Endpoints: []*model.Endpoint{}}
+               s.AddCluster(c)
+               cluster = s.clustersMap[clusterName]
+       }
 
        for _, c := range s.Config {
                if c.Name == clusterName {
@@ -256,16 +261,13 @@ func (s *ClusterStore) SetEndpoint(clusterName string, 
endpoint *model.Endpoint)
                        return
                }
        }
-
-       // cluster create
-       c := &model.ClusterConfig{Name: clusterName, LbStr: 
model.LoadBalancerRoundRobin, Endpoints: []*model.Endpoint{endpoint}}
-       // not call AddCluster, because lock is not reenter
-       s.Config = append(s.Config, c)
 }
 
 func (s *ClusterStore) DeleteEndpoint(clusterName string, endpointID string) {
        cluster := s.clustersMap[clusterName]
-
+       if cluster == nil {
+               return
+       }
        for _, c := range s.Config {
                if c.Name == clusterName {
                        for i, e := range c.Endpoints {

Reply via email to