torwig commented on code in PR #237:
URL:
https://github.com/apache/kvrocks-controller/pull/237#discussion_r1895841436
##########
store/cluster.go:
##########
@@ -77,6 +77,18 @@ func NewCluster(name string, nodes []string, replicas int)
(*Cluster, error) {
return cluster, nil
}
+func (cluster *Cluster) Clone() *Cluster {
+ clone := &Cluster{
+ Name: cluster.Name,
+ Shards: make([]*Shard, 0),
+ }
+ clone.Version.Store(cluster.Version.Load())
+ for _, shard := range cluster.Shards {
Review Comment:
Is it possible that someone can modify `cluster.Shards` (it's a slice) while
we are iterating over it?
I see this:
```
case <-ticker.C:
c.clusterMu.Lock()
cluster := c.cluster
c.clusterMu.Unlock()
if cluster == nil {
continue
}
c.tryUpdateMigrationStatus(c.ctx, cluster.Clone())
```
But technically `cluster := c.cluster` doesn't make a deep copy. Maybe we
need to call `cluster.Clone()` under the lock instead of assignment?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]