hello-stephen commented on code in PR #71174:
URL: https://github.com/apache/doris/pull/71174#discussion_r4750939732


##########
fe/fe-core/src/main/java/org/apache/doris/datasource/doris/FeServiceClient.java:
##########
@@ -246,16 +247,31 @@ private <T> T masterCallWithRetry(ThriftCall<T> call, 
String errorMsg, int timeo
         throw new RuntimeException(errorMsg + ":" + lastMessage, 
lastException);
     }
 
+    public int getClusterId() {
+        Integer destination = clusterId;
+        if (destination == null) {
+            listBackends();

Review Comment:
   [P2] Refresh an unknown remote identity once per catalog per query
   
   An older remote FE omits `cluster_id`, so `listBackends()` leaves 
`clusterId` null. `PipelineExecutionTaskBuilder.buildMultiFragmentTasks()` 
binds each distinct worker in a serial loop, and each binding calls this getter 
through `BackendServiceProxy.bindTarget()`. Consequently, a native remote scan 
using N workers now makes N synchronous full-topology metadata RPCs and 
reconstructs N×M Backend objects for M remote backends, even with a warm 
`DorisExternalMetaCache`; this repeats on every query against a legacy peer. 
Resolve the identity once per catalog per query, including the unknown result, 
while allowing later queries to refresh it after upgrade. The current 
single-worker transition tests do not detect this fan-out.



##########
fe/fe-core/src/main/java/org/apache/doris/system/HeartbeatMgr.java:
##########
@@ -505,26 +508,36 @@ public FrontendHeartbeatHandler(Frontend fe, int 
clusterId, String token) {
         @Override
         public HeartbeatResponse call() {
             HostInfo selfNode = Env.getCurrentEnv().getSelfNode();
-            if (fe.getHost().equals(selfNode.getHost())) {
+            // A host can contain multiple FE membership identities with 
separate signing keys.
+            if (fe.getHost().equals(selfNode.getHost()) && fe.getEditLogPort() 
== selfNode.getPort()) {
                 // heartbeat to self
                 if (Env.getCurrentEnv().isReady()) {
                     return new FrontendHbResponse(fe.getNodeName(), 
Config.query_port, Config.rpc_port,
                             Config.arrow_flight_sql_port, 
Env.getCurrentEnv().getMaxJournalId(),
                             System.currentTimeMillis(),
                             Version.DORIS_BUILD_VERSION + "-" + 
Version.DORIS_BUILD_SHORT_HASH,
                             ExecuteEnv.getInstance().getStartupTime(), 
ExecuteEnv.getInstance().getDiskInfos(),
-                            ExecuteEnv.getInstance().getProcessUUID(), 
Config.local_resource_group);
+                            ExecuteEnv.getInstance().getProcessUUID(), 
Config.local_resource_group)
+                            
.withRpcPublicKey(InternalRpcRequestSigner.getInstance().getPublicKey());
                 } else {
                     return new FrontendHbResponse(fe.getNodeName(), "not 
ready");
                 }
             }
 
+            // Falling back to our own socket would publish our key under the 
peer's identity.
+            if (fe.getHost().equals(selfNode.getHost())
+                    && (fe.getRpcPort() <= 0 || fe.getRpcPort() == 
Config.rpc_port)) {
+                return new FrontendHbResponse(fe.getNodeName(),
+                        "Colocated frontend requires a known RPC endpoint 
distinct from the local endpoint");
+            }
             return getHeartbeatResponse();
         }
 
         private HeartbeatResponse getHeartbeatResponse() {
             FrontendService.Client client = null;
-            TNetworkAddress addr = new TNetworkAddress(fe.getHost(), 
Config.rpc_port);
+            // Use the discovered peer endpoint; the local port is only a 
bootstrap default.
+            int rpcPort = fe.getRpcPort() > 0 ? fe.getRpcPort() : 
Config.rpc_port;

Review Comment:
   [P2] Rediscover peer RPC ports after a configuration restart
   
   If an established cluster on different hosts changes `rpc_port` from 9020 to 
9021 and restarts, replaying a pre-restart `OP_HEARTBEAT` after the latest 
image restores each peer's old positive `rpcPort`. This selection then contacts 
9020 forever: only an OK heartbeat updates the port, and the failure path 
neither clears it nor tries the newly configured port. The peers remain BAD, 
and their new startup-publication gate eventually exits before opening query 
listeners. The previous code used the new `Config.rpc_port` and could recover 
this restart. Add safe discovery/fallback for stale remote-host endpoints while 
retaining the colocated self-endpoint guard, and cover heartbeat replay 
followed by a port change.



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