hello-stephen commented on code in PR #71174:
URL: https://github.com/apache/doris/pull/71174#discussion_r4785923516
##########
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:
[P2] Provide RPC endpoint discovery for newly added colocated FEs
A freshly added FE has no recorded RPC port: Env.addFrontend constructs
Frontend from its host and edit-log port, and the RPC port is populated only by
an OK heartbeat. The initial Config.rpc_port fallback is therefore ambiguous
when the remote host already has another FE; the new member can learn the
existing member's endpoint instead of its own. On the master's own host, the
guard above instead rejects the unknown endpoint indefinitely. The new
publication/registration barrier makes either outcome a startup failure with
enforcing workers. The earlier fix handles peers with known ports, but does not
supply a way for a new member to learn its port. Please register/discover the
peer RPC endpoint using its full membership identity, and cover initial joins
on both colocated configurations.
##########
fe/fe-core/src/main/java/org/apache/doris/system/HeartbeatMgr.java:
##########
@@ -178,17 +192,30 @@ protected void runAfterCatalogReady() {
return;
}
clearRemovedBackendHeartbeatPools();
- for (Backend backend : bes) {
- BackendHeartbeatHandler handler = new
BackendHeartbeatHandler(backend, feInfos);
- hbResponses.add(executor.submit(handler));
- }
-
// send frontend heartbeat
List<Frontend> frontends = Env.getCurrentEnv().getFrontends(null);
+ List<FutureTask<HeartbeatResponse>> deferredFrontends =
Lists.newArrayList();
for (Frontend frontend : frontends) {
FrontendHeartbeatHandler handler = new
FrontendHeartbeatHandler(frontend,
Env.getCurrentEnv().getClusterId(),
Env.getCurrentEnv().getToken());
+ try {
+ hbResponses.add(frontendExecutor.submit(handler));
+ } catch (RejectedExecutionException e) {
+ // The ordinary blocking rejection policy could otherwise
stall dispatch for a full minute.
+ FutureTask<HeartbeatResponse> deferred = new
FutureTask<>(handler);
+ deferredFrontends.add(deferred);
+ hbResponses.add(deferred);
+ }
+ }
+
+ HbPackage hbPackage = new HbPackage();
+ // Bound publication waiting so a stalled FE cannot withhold BE/broker
heartbeats.
+ // Retain late futures for the final collection; reachable
unregistered BEs still gate FE startup.
+ collectHeartbeatResponses(hbResponses, hbPackage, System.nanoTime() +
TimeUnit.MILLISECONDS.toNanos(100));
Review Comment:
[P2] Do not mark a recovering worker ready before late FE publication
reaches it
The early budget bounds dispatch latency, but it separates a late joining
FE's heartbeat acknowledgment from the authority snapshot sent to BEs. For a
newly registered BE whose BRPC port is still unknown in follower metadata, the
final HbPackage can apply the late FE acknowledgment before the BE heartbeat
entry. The startup thread can observe that acknowledgment, skip the
still-unknown BE endpoint, and complete; replay then makes the worker
schedulable even though that heartbeat did not contain the joining FE's key.
First legitimate queries can fail until the next heartbeat. Please couple
worker scheduling readiness to the authority distribution generation (or
otherwise ensure publication completes before that worker becomes available).
Add a test that covers a late joining FE alongside a newly registered worker,
rather than only an unrelated slow peer.
##########
be/src/service/internal_service.cpp:
##########
@@ -360,10 +361,56 @@ void
PInternalService::tablet_writer_open(google::protobuf::RpcController* contr
}
}
+bool PInternalService::_is_trusted_signing_key(std::string_view key) {
+ const auto frontends = _exec_env->get_frontends();
Review Comment:
[P3] Avoid copying the whole FE membership snapshot on every authenticated
RPC
The lookup only needs to answer whether one key belongs to the current
membership, but get_frontends() takes _frontends_lock and builds a vector
containing copies of every frontend address and key. This adds allocations and
serialized work to frequent requests such as point lookups as well as fragment
dispatch. Consider a membership-only lookup or immutable verification snapshot
that preserves heartbeat replacement semantics without deep-copying all entries
per request. Signature work can remain outside the lock.
##########
fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/TableQueryPlanAction.java:
##########
@@ -322,6 +324,18 @@ private void handleQuery(ConnectContext context, String
requestDb, String reques
String opaquedQueryPlan;
try {
serializer = new TSerializer();
+ byte[] unsignedPlan = serializer.serialize(tQueryPlanInfo);
+ InternalRpcRequestSigner.Authorization authorization =
InternalRpcRequestSigner.getInstance()
+ .signBytes("open_scanner", 0,
Env.getCurrentEnv().getClusterId(), unsignedPlan,
+ System.currentTimeMillis());
+ // This opaque plan can be opened on any of its tablet
backends. Bind it to this
+ // FE's authority and the exact bytes, without exposing a
reusable cluster token.
+ TQueryPlanAuthorization planAuthorization = new
TQueryPlanAuthorization();
+ planAuthorization.setSerializedPlan(unsignedPlan);
Review Comment:
[P2] Preserve the exported scanner plan's existing message-size budget
The compatibility envelope now stores the complete original serialization
and also serializes all the required legacy fields around it. After Base64
encoding, the opaque plan sent in TScanOpenParams is approximately twice its
old size. The BE's Thrift transport still enforces thrift_max_message_size (100
MiB by default), so an existing valid plan near the configured limit can no
longer be opened, including during compatibility mode. This matters for plans
with large tablet maps or descriptors. Please account for the old wire-size
budget with a compatible versioned representation or an explicit migration of
the size limit; include a large exported-plan compatibility test.
##########
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:
[P2] Keep management startup available when a non-schedulable worker cannot
receive publication
This loop probes all known BEs, including dead ones that
Backend.isQueryAvailable already excludes from scheduling. Consider a
previously registered BE whose heartbeat endpoint is unavailable but whose BRPC
service responds, while a new FE starts with a key the worker has not received.
Its retained BRPC endpoint produces explicit FALSE every round, so even after
the master's journal acknowledgment this FE eventually exits before SQL/HTTP
management listeners open. Operators cannot repair that worker through the
starting FE. This is the inverse endpoint-availability case of the earlier
unreachable-BRPC fix. Keep management availability separate from worker
execution readiness and add independent heartbeat/BRPC outage coverage; the
receiving signature check should stay enforced.
--
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]