Skip to content

Commit

Permalink
Move nil check condition
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hulk committed Jan 5, 2025
1 parent 856ca41 commit ecef811
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
4 changes: 4 additions & 0 deletions controller/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions store/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ func NewCluster(name string, nodes []string, replicas int) (*Cluster, error) {
}

func (cluster *Cluster) Clone() *Cluster {
if cluster == nil {
return nil
}

clone := &Cluster{
Name: cluster.Name,
Shards: make([]*Shard, 0),
Expand Down
4 changes: 0 additions & 4 deletions store/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ import (
)

func TestCluster_Clone(t *testing.T) {
var cluster *Cluster
emptyCluster := cluster.Clone()
require.Nil(t, emptyCluster)

cluster, err := NewCluster("test", []string{"node1", "node2", "node3"}, 1)
require.NoError(t, err)

Expand Down

0 comments on commit ecef811

Please sign in to comment.