Caideyipi commented on code in PR #19222: URL: https://github.com/apache/iotdb/pull/19222#discussion_r4546147145
########## iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/client/async/DataNodeTransportFailureUtils.java: ########## @@ -0,0 +1,92 @@ +/* + * 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.iotdb.confignode.client.async; + +import org.apache.iotdb.common.rpc.thrift.TSStatus; +import org.apache.iotdb.rpc.TSStatusCode; + +import org.apache.thrift.TApplicationException; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.transport.TTransportException; + +import java.net.SocketException; +import java.net.SocketTimeoutException; +import java.nio.channels.ClosedChannelException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Set; +import java.util.concurrent.TimeoutException; + +public final class DataNodeTransportFailureUtils { + + private static final int TRANSPORT_FAILURE_STATUS_CODE = + TSStatusCode.CAN_NOT_CONNECT_DATANODE.getStatusCode(); + + private DataNodeTransportFailureUtils() {} + + public static boolean isTransportException(final Exception exception) { + final Set<Throwable> visited = Collections.newSetFromMap(new IdentityHashMap<>()); + for (Throwable cause = exception; + cause != null && visited.add(cause); + cause = cause.getCause()) { + if (cause instanceof TApplicationException || cause instanceof TProtocolException) { + return false; + } + if (cause instanceof TTransportException) { + final int type = ((TTransportException) cause).getType(); + // Corrupt frames and opening an already-open transport are not connection failures. + return type == TTransportException.UNKNOWN + || type == TTransportException.NOT_OPEN + || type == TTransportException.TIMED_OUT + || type == TTransportException.END_OF_FILE; + } + if (cause instanceof SocketException + || cause instanceof SocketTimeoutException + || cause instanceof ClosedChannelException + || cause instanceof TimeoutException) { + return true; + } + } + return false; + } + + public static TSStatus markTransportFailure(final TSStatus status) { + // CN-local provenance: preserve the metadata error code used by existing callers. + final List<TSStatus> subStatus = new ArrayList<>(); + if (status.isSetSubStatus() && status.getSubStatus() != null) { + subStatus.addAll(status.getSubStatus()); + } + subStatus.add(new TSStatus(TRANSPORT_FAILURE_STATUS_CODE)); + status.setSubStatus(subStatus); + return status; + } Review Comment: Keeping a copy is deliberate. The existing sub-status entries are preserved, but the marker is appended to a fresh list before assigning it back to the same status. This avoids mutating a potentially shared or immutable list while retaining the existing metadata-push error as the top-level code. ########## iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/client/async/DataNodeTransportFailureUtils.java: ########## @@ -0,0 +1,92 @@ +/* + * 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.iotdb.confignode.client.async; + +import org.apache.iotdb.common.rpc.thrift.TSStatus; +import org.apache.iotdb.rpc.TSStatusCode; + +import org.apache.thrift.TApplicationException; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.transport.TTransportException; + +import java.net.SocketException; +import java.net.SocketTimeoutException; +import java.nio.channels.ClosedChannelException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Set; +import java.util.concurrent.TimeoutException; + +public final class DataNodeTransportFailureUtils { + + private static final int TRANSPORT_FAILURE_STATUS_CODE = + TSStatusCode.CAN_NOT_CONNECT_DATANODE.getStatusCode(); + + private DataNodeTransportFailureUtils() {} + + public static boolean isTransportException(final Exception exception) { + final Set<Throwable> visited = Collections.newSetFromMap(new IdentityHashMap<>()); + for (Throwable cause = exception; + cause != null && visited.add(cause); + cause = cause.getCause()) { + if (cause instanceof TApplicationException || cause instanceof TProtocolException) { + return false; + } + if (cause instanceof TTransportException) { + final int type = ((TTransportException) cause).getType(); + // Corrupt frames and opening an already-open transport are not connection failures. + return type == TTransportException.UNKNOWN + || type == TTransportException.NOT_OPEN + || type == TTransportException.TIMED_OUT + || type == TTransportException.END_OF_FILE; + } + if (cause instanceof SocketException + || cause instanceof SocketTimeoutException + || cause instanceof ClosedChannelException + || cause instanceof TimeoutException) { + return true; + } + } + return false; + } + + public static TSStatus markTransportFailure(final TSStatus status) { + // CN-local provenance: preserve the metadata error code used by existing callers. + final List<TSStatus> subStatus = new ArrayList<>(); + if (status.isSetSubStatus() && status.getSubStatus() != null) { + subStatus.addAll(status.getSubStatus()); + } + subStatus.add(new TSStatus(TRANSPORT_FAILURE_STATUS_CODE)); + status.setSubStatus(subStatus); + return status; + } + + public static boolean isTransportFailure(final TSStatus status) { + return status != null + && status.isSetSubStatus() + && status.getSubStatus() != null + && status.getSubStatus().stream() + .anyMatch( + subStatus -> + subStatus != null && subStatus.getCode() == TRANSPORT_FAILURE_STATUS_CODE); + } +} Review Comment: In this RPC path, these handlers create PIPE_PUSH_META_ERROR or CONSUMER_PUSH_META_ERROR statuses and attach CAN_NOT_CONNECT_DATANODE as sub-status provenance. The top-level code is therefore not the transport marker, and the procedure also checks the metadata-push code before filtering. A top-level transport status is not produced by these handlers. ########## iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/subscription/consumer/AlterConsumerGroupProcedure.java: ########## @@ -127,6 +127,17 @@ public void executeFromOperateOnConfigNodes(ConfigNodeProcedureEnv env) @Override public void executeFromOperateOnDataNodes(ConfigNodeProcedureEnv env) throws SubscriptionException, IOException { + executeFromOperateOnDataNodes(env, false); + } + + public void executeFromOperateOnDataNodesForUnsubscribe(ConfigNodeProcedureEnv env) + throws SubscriptionException, IOException { + executeFromOperateOnDataNodes(env, true); + } Review Comment: I checked the other metadata operations. CreateSubscriptionProcedure uses the strict AlterConsumerGroupProcedure path because subscription creation needs successful consumer-group and pipe propagation. Topic create, alter, and drop procedures also retain their all-node failure and rollback behavior; drop and alter explicitly fail rather than relying on later metadata sync. This exception stays specific to unsubscribe cleanup. Broadening other operations would change their behavior and needs a separate contract decision. ########## iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/subscription/AbstractOperateSubscriptionProcedure.java: ########## @@ -333,6 +335,18 @@ protected abstract void rollbackFromOperateOnConfigNodes(ConfigNodeProcedureEnv protected abstract void rollbackFromOperateOnDataNodes(ConfigNodeProcedureEnv env) throws SubscriptionException, IOException; + protected static boolean isOfflineDataNodeTransportFailure( + final ConfigNodeProcedureEnv env, + final int dataNodeId, + final TSStatus status, + final int metadataPushErrorCode, + final boolean hasExceptionMessages) { + return status.getCode() == metadataPushErrorCode + && DataNodeTransportFailureUtils.isTransportFailure(status) + && !hasExceptionMessages + && env.getConfigManager().getLoadManager().getNodeStatus(dataNodeId).isOffline(); + } Review Comment: This guard keeps the filter limited to a transport-only response. The async error handlers add the marker when there is no DataNode response; a DataNode metadata rejection instead carries exceptionMessages. The guard prevents suppressing a remote metadata error if a response ever carries both signals. The tests include that rejection case. -- 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]
