Gabriel39 commented on code in PR #71174:
URL: https://github.com/apache/doris/pull/71174#discussion_r4788810129
##########
fe/fe-core/src/main/java/org/apache/doris/system/HeartbeatMgr.java:
##########
@@ -506,26 +564,56 @@ 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() {
+ int rpcPort = fe.getRpcPort() > 0 ? fe.getRpcPort() :
Config.rpc_port;
Review Comment:
Fixed in df7c41ad5988. A new FE registers its full membership identity and
actual RPC endpoint with the master. The master checks existing DDL membership,
independently pings that endpoint with the expected node name/edit-log port,
then journals the verified identity before acknowledging it. Registration does
not guess a peer's RPC port. Revision/epoch checks prevent an older in-flight
response from overwriting the result.
Unit coverage exercises new members on the master's host and another host.
An additional local same-IP process scenario passes two fresh FE first queries
with periodic heartbeats paused and each key initially absent at the BE. That
harness seeds only existing ROLE/VERSION bootstrap metadata to handle the
separate shared-HTTP-port bootstrap assumption; it never seeds an RPC endpoint,
signing key or worker trust.
##########
fe/fe-core/src/main/java/org/apache/doris/rpc/FrontendRpcKeyRegistration.java:
##########
@@ -0,0 +1,121 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.rpc;
+
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.Config;
+import org.apache.doris.system.Backend;
+import org.apache.doris.system.Frontend;
+import org.apache.doris.thrift.TNetworkAddress;
+
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.function.BooleanSupplier;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+/** Keeps query listeners closed until heartbeat publication and reachable
workers acknowledge the key. */
+public final class FrontendRpcKeyRegistration {
+ private static final Logger LOG =
LogManager.getLogger(FrontendRpcKeyRegistration.class);
+
+ private FrontendRpcKeyRegistration() {
+ }
+
+ public static void awaitPublication() throws IOException,
InterruptedException {
+ String key = InternalRpcRequestSigner.getInstance().getPublicKey();
+ BackendServiceProxy proxy = BackendServiceProxy.getInstance();
+ // Zero is the uninitialized heartbeat position, so it cannot
acknowledge a startup.
+ long journalFence = Math.max(1,
Env.getCurrentEnv().getReplayedJournalId());
+ // Publication and recovering-worker registration can span two
configured heartbeat rounds.
+ long timeoutMs = 120_000 + TimeUnit.SECONDS.toMillis(2L *
Config.heartbeat_interval_second);
+ long started = System.nanoTime();
+ LOG.info("Waiting for FE heartbeat publication and reachable backend
signing key registration");
+ awaitPublication(() ->
Env.getCurrentSystemInfo().getAllClusterBackendsNoException().values(),
+ backend -> proxy.isFrontendKeyRegistered(
+ new TNetworkAddress(backend.getHost(),
backend.getBrpcPort()), key),
+ () -> isHeartbeatPublished(journalFence), timeoutMs);
+ LOG.info("FE signing key publication completed after {} ms",
+ TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started));
+ }
+
+ static boolean isHeartbeatPublished(long journalFence) {
+ Env env = Env.getCurrentEnv();
+ Frontend self = env.getFeByName(env.getNodeName());
+ // An older process's heartbeat is journaled after its reported replay
position;
+ // it cannot acknowledge the later journal position replayed during
this startup.
+ return self != null && self.getReplayedJournalId() >= journalFence;
+ }
+
+ static void awaitPublication(Supplier<Collection<Backend>> backends,
+ Function<Backend, ListenableFuture<Boolean>> probe,
BooleanSupplier heartbeatPublished, long timeoutMs)
+ throws IOException, InterruptedException {
+ long deadline = System.nanoTime() +
TimeUnit.MILLISECONDS.toNanos(timeoutMs);
+ while (true) {
+ // A new FE can miss this round's ping while all BEs are down.
Wait for the master's
+ // replay-position acknowledgment so the next recovery heartbeat
already knows this FE's key.
+ boolean complete = heartbeatPublished.getAsBoolean();
+ Map<Backend, ListenableFuture<Boolean>> pending = new
LinkedHashMap<>();
+ try {
+ for (Backend backend : backends.get()) {
+ // A newly registered BE has no BRPC endpoint until its
first heartbeat.
+ pending.put(backend, backend.getBrpcPort() > 0 ?
probe.apply(backend)
+ : Futures.immediateFuture(null));
+ }
+ // Issue probes together: dead workers must not add one
network timeout each
+ // to startup. All calls use the existing gRPC executors and
their own deadlines.
+ long roundDeadline = Math.min(deadline, System.nanoTime() +
TimeUnit.SECONDS.toNanos(2));
+ for (Map.Entry<Backend, ListenableFuture<Boolean>> entry :
pending.entrySet()) {
+ Boolean registered;
+ try {
+ registered = entry.getValue().get(Math.max(0,
roundDeadline - System.nanoTime()),
+ TimeUnit.NANOSECONDS);
+ } catch (TimeoutException e) {
+ registered = null;
+ } catch (ExecutionException e) {
+ throw new IOException("Cannot check backend
registration of the FE signing key", e.getCause());
+ }
+ // Heartbeat liveness does not prove BRPC reachability.
Keep management listeners
+ // available for repairing unreachable workers; their RPC
admission still fails closed.
+ if (Boolean.FALSE.equals(registered)) {
Review Comment:
Fixed in df7c41ad5988 by removing the global startup publication barrier.
Management listeners start after FE catalog/Thrift readiness, independently of
worker heartbeat or BRPC availability. Executable requests instead use a shared
per-target admission gate; unreachable or unacknowledged authority fails that
caller without preventing management startup. Receiver signature checks remain
enforced.
The packaged two-FE/zero-BE regression passes while periodic publication is
paused. The packaged HA regression also passes BE-down joins and first queries
after recovery. These runs use the final full FE/BE package.
--
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]