funky-eyes commented on code in PR #7903:
URL: https://github.com/apache/incubator-seata/pull/7903#discussion_r2757997034


##########
server/src/main/java/org/apache/seata/server/cluster/manager/ClusterWatcherManager.java:
##########
@@ -128,31 +248,131 @@ private void sendWatcherResponse(Watcher<HttpContext> 
watcher, HttpResponseStatu
             } else {
                 ctx.writeAndFlush(response);
             }
-        } else {
-            // HTTP/2 response (h2c support)
-            // Send headers frame
+            return;
+        }
+
+        // For HTTP/2, headers must be sent first on the initial response
+        if (sendHeaders) {
             Http2Headers headers = new 
DefaultHttp2Headers().status(nettyStatus.codeAsText());
-            headers.set(HttpHeaderNames.CONTENT_LENGTH, "0");
+            headers.set(HttpHeaderNames.CONTENT_TYPE, "text/event-stream; 
charset=utf-8");
+            headers.set(HttpHeaderNames.CACHE_CONTROL, "no-cache");
+
             ctx.write(new DefaultHttp2HeadersFrame(headers));
+        }
 
-            // Send empty data frame with endStream=true to close the stream
-            ctx.writeAndFlush(new DefaultHttp2DataFrame(Unpooled.EMPTY_BUFFER, 
true))
-                    .addListener(f -> {
-                        if (!f.isSuccess()) {
-                            logger.warn("HTTP2 response send failed, 
group={}", group, f.cause());
-                        }
-                    });
+        String group = watcher.getGroup();
+        String eventData = buildEventData(group);
+        ByteBuf content = Unpooled.copiedBuffer(eventData, 
StandardCharsets.UTF_8);
+
+        // Send DATA frame (if closeStream is true, it will end the current 
stream)
+        ctx.write(new DefaultHttp2DataFrame(content, closeStream));
+        ctx.flush();
+    }
+
+    /**
+     * Get current cluster metadata for the given group.
+     * This method extracts the logic from ClusterController#cluster to avoid 
circular dependency.
+     *
+     * @param group the group name
+     * @return the MetadataResponse containing current cluster metadata
+     */
+    public MetadataResponse getMetadataResponse(String group) {
+        MetadataResponse metadataResponse = new MetadataResponse();
+        if (StringUtils.isBlank(group)) {
+            group = ConfigurationFactory.getInstance()
+                    .getConfig(ConfigurationKeys.SERVER_RAFT_GROUP, 
DEFAULT_SEATA_GROUP);
+        }
+        RaftServer raftServer = RaftServerManager.getRaftServer(group);
+        if (raftServer != null) {
+            String mode = 
ConfigurationFactory.getInstance().getConfig(STORE_MODE);
+            metadataResponse.setStoreMode(mode);
+            RouteTable routeTable = RouteTable.getInstance();
+            try {
+                
routeTable.refreshLeader(RaftServerManager.getCliClientServiceInstance(), 
group, 1000);
+                PeerId leader = routeTable.selectLeader(group);

Review Comment:
   I believe these code changes are no longer necessary.



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