mochengqian commented on code in PR #919:
URL: https://github.com/apache/dubbo-go-pixiu/pull/919#discussion_r3186646651


##########
pkg/server/cluster_manager.go:
##########
@@ -143,16 +143,27 @@ func (cm *ClusterManager) NewStore(version int32) 
*ClusterStore {
        return &ClusterStore{Version: version, clustersMap: 
map[string]*cluster.Cluster{}}
 }
 
+// CompareAndSetStore swaps the store only when versions match.
+// Version mismatch must leave both stores and runtime clusters untouched.
 func (cm *ClusterManager) CompareAndSetStore(store *ClusterStore) bool {
        cm.rw.Lock()
-       defer cm.rw.Unlock()
 
        if store.Version != cm.store.Version {
+               cm.rw.Unlock()
                return false
        }
 
-       store.carryOverRuntimeStateFrom(cm.store)
+       currentStore := cm.store
+       replacedClusters := store.ensureRuntimeClusters()
+       store.carryOverRuntimeStateFrom(currentStore)
        cm.store = store
+       if store != currentStore {
+               replacedClusters = append(replacedClusters, 
currentStore.runtimeClustersNotIn(store)...)
+       }
+       cm.rw.Unlock()

Review Comment:
   thanks for guidance!



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to