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

twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks-controller.git


The following commit(s) were added to refs/heads/unstable by this push:
     new d18234d  Fix nil pointer when cloning the cluster (#242)
d18234d is described below

commit d18234da527233e4462f5aad082d20c15b3bd432
Author: hulk <[email protected]>
AuthorDate: Sun Jan 5 22:35:13 2025 +0800

    Fix nil pointer when cloning the cluster (#242)
    
    * Fix nil pointer when cloning the cluster
    
    * Move nil check condition
---
 controller/cluster.go | 4 ++++
 store/cluster_test.go | 9 +++++++++
 2 files changed, 13 insertions(+)

diff --git a/controller/cluster.go b/controller/cluster.go
index 2b975d2..eea8ff8 100644
--- a/controller/cluster.go
+++ b/controller/cluster.go
@@ -341,6 +341,10 @@ func (c *ClusterChecker) migrationLoop() {
                        return
                case <-ticker.C:
                        c.clusterMu.Lock()
+                       if c.cluster == nil {
+                               c.clusterMu.Unlock()
+                               continue
+                       }
                        clonedCluster := c.cluster.Clone()
                        c.clusterMu.Unlock()
                        if clonedCluster == nil {
diff --git a/store/cluster_test.go b/store/cluster_test.go
index 4c39b90..cb62545 100644
--- a/store/cluster_test.go
+++ b/store/cluster_test.go
@@ -29,6 +29,15 @@ import (
        "github.com/apache/kvrocks-controller/consts"
 )
 
+func TestCluster_Clone(t *testing.T) {
+       cluster, err := NewCluster("test", []string{"node1", "node2", "node3"}, 
1)
+       require.NoError(t, err)
+
+       clusterCopy := cluster.Clone()
+       require.Equal(t, cluster.Name, clusterCopy.Name)
+       require.Equal(t, cluster.Shards, clusterCopy.Shards)
+}
+
 func TestCluster_FindIndexShardBySlot(t *testing.T) {
        cluster, err := NewCluster("test", []string{"node1", "node2", "node3"}, 
1)
        require.NoError(t, err)

Reply via email to