AsperforMias commented on code in PR #3482:
URL: https://github.com/apache/dubbo-go/pull/3482#discussion_r3591008141


##########
registry/polaris/core.go:
##########
@@ -72,60 +88,174 @@ func (watcher *PolarisServiceWatcher) lazyRun() {
        })
 }
 
+func (watcher *PolarisServiceWatcher) addSubscriberWithInitialSnapshot(
+       initialSnapshot []model.Instance,
+       subscriber item,
+) {
+       state := &subscriberState{
+               notify:          subscriber,
+               initialSnapshot: copyInstances(initialSnapshot),
+       }
+
+       func() {
+               watcher.lock.Lock()
+               defer watcher.lock.Unlock()
+
+               watcher.subscribers = append(watcher.subscribers, state)
+               if watcher.snapshotReady {
+                       watcher.reconcileSubscriberLocked(state)
+               }
+       }()
+
+       // Start only after the subscriber is registered and any available 
current
+       // snapshot has been replayed.
+       watcher.lazyRun()
+}
+
+// missingInitialInstances returns initial - current by model.InstanceKey while
+// preserving the order of the initial snapshot.
+func missingInitialInstances(initial []model.Instance, current 
[]model.Instance) []model.Instance {
+       currentInstances := make(map[model.InstanceKey]struct{}, len(current))
+       for _, instance := range current {
+               currentInstances[instance.GetInstanceKey()] = struct{}{}
+       }
+
+       missing := make([]model.Instance, 0, len(initial))
+       for _, instance := range initial {
+               if _, ok := currentInstances[instance.GetInstanceKey()]; !ok {
+                       missing = append(missing, instance)
+               }
+       }
+       return missing
+}
+
+// handleWatchSnapshot replaces the watcher's current state and reconciles each
+// subscriber's own synchronous-load baseline exactly once.
+func (watcher *PolarisServiceWatcher) handleWatchSnapshot(current 
[]model.Instance) {
+       watcher.lock.Lock()
+       defer watcher.lock.Unlock()
+
+       watcher.currentInstances = copyInstances(current)
+       watcher.snapshotReady = true
+       for _, subscriber := range watcher.subscribers {
+               if subscriber.reconciled {
+                       watcher.notifySubscriberLocked(subscriber, 
remoting.EventTypeAdd, watcher.currentInstances)

Review Comment:
   这个不属于 #3480 的范围,但也算同类情况。如果有点糊涂的话,你可以这么修:每次成功全量快照时,对已 `reconcile` 的 
subscriber 计算 `previous-current` 并先行 DEL。或者有自己想法也行



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