YvCeung commented on code in PR #7903:
URL: https://github.com/apache/incubator-seata/pull/7903#discussion_r2777204934
##########
server/src/main/java/org/apache/seata/server/cluster/manager/ClusterWatcherManager.java:
##########
@@ -89,36 +141,104 @@ public void init() {
@Async
public void onChangeEvent(ClusterChangeEvent event) {
if (event.getTerm() > 0) {
- GROUP_UPDATE_TERM.put(event.getGroup(), event.getTerm());
- // Notifications are made of changes in cluster information
- Optional.ofNullable(WATCHERS.remove(event.getGroup()))
- .ifPresent(watchers ->
watchers.parallelStream().forEach(this::notifyWatcher));
+ String group = event.getGroup();
+ Long eventTerm = event.getTerm();
+
+ Long currentTerm = GROUP_UPDATE_TERM.get(group);
+ if (currentTerm != null && eventTerm <= currentTerm) {
+ logger.info(
+ "Discarding outdated event with term {} for group {},
current term is {}",
+ eventTerm,
+ group,
+ currentTerm);
+ return;
+ }
+
+ GROUP_UPDATE_TERM.put(group, eventTerm);
+
+ // Handle HTTP/1.1 watchers: remove and notify (one-time request)
+ Optional.ofNullable(HTTP1_WATCHERS.remove(group))
+ .ifPresent(watchers ->
watchers.parallelStream().forEach(watcher -> {
+ notifyWatcher(watcher, eventTerm);
+ // HTTP/1.1 watcher is done after notification
+ watcher.setDone(true);
+ }));
+
+ // Handle HTTP/2 watchers: notify without removing (long-lived
connection)
+ Queue<Watcher<HttpContext>> http2Watchers =
HTTP2_WATCHERS.get(group);
+ if (http2Watchers != null && !http2Watchers.isEmpty()) {
+ List<Watcher<HttpContext>> watchersToNotify = new
ArrayList<>(http2Watchers);
+ watchersToNotify.forEach(watcher -> {
+ if
(watcher.getAsyncContext().getContext().channel().isActive() &&
!watcher.isDone()) {
+ if (eventTerm > watcher.getTerm()) {
+ notifyWatcher(watcher, eventTerm);
+ } else {
+ logger.info(
+ "Skipping notification for watcher with
term {} >= event term {} for group {}",
+ watcher.getTerm(),
+ eventTerm,
+ group);
+ }
Review Comment:
done in
[f15c19a](https://github.com/apache/incubator-seata/pull/7903/commits/f15c19a0f73e6d3100f26945185e9d72be718533)
--
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]