From f9e44a24a2b9a451f66818c36b455b2fff83c123 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Fri, 27 Nov 2026 14:05:41 +0800 Subject: [PATCH 1/9] Retry LOAD RPC transport failures safely --- .../iotdb/db/i18n/DataNodeQueryMessages.java | 5 + .../iotdb/db/i18n/DataNodeQueryMessages.java | 5 + .../plan/analyze/ClusterPartitionFetcher.java | 3 +- .../load/LoadConsensusSubmitter.java | 27 ++++ .../scheduler/load/LoadFallbackHandler.java | 47 ++++++- .../scheduler/load/LoadTsFileScheduler.java | 18 ++- .../scheduler/load/TsFileLoadStrategy.java | 5 + .../load/TwoPhaseConsensusLoadStrategy.java | 11 ++ .../load/LoadConsensusSubmitterTest.java | 121 +++++++++++++++++- .../load/LoadFallbackHandlerTest.java | 27 ++++ .../load/LoadTsFileSchedulerTest.java | 68 ++++++++++ ...woPhaseConsensusLoadStrategyAbortTest.java | 31 +++++ 12 files changed, 355 insertions(+), 13 deletions(-) diff --git a/iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java b/iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java index 149e2a904608e..e13fd1cd1a88c 100644 --- a/iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java +++ b/iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java @@ -44,6 +44,11 @@ public final class DataNodeQueryMessages { "Failed to read TsFile model information before tablet conversion for statement %s: %s"; public static final String EXCEPTION_FAILED_TO_LOAD_TSFILES_AFTER_TABLET_CONVERSION_DETAILS_ARG_53647EC5 = "Failed to load TsFiles after tablet conversion. Details: %s"; + public static final String + EXCEPTION_TSFILE_ARG_IS_UNCERTAIN_AFTER_AN_RPC_TRANSPORT_FAILURE_2A59AF17 = + "TsFile %s is uncertain after an RPC transport failure."; + public static final String EXCEPTION_FAILED_TO_LOAD_TSFILES_DETAILS_ARG_D79C19DB = + "Failed to load TsFiles. Details: %s"; public static final String LOG_LOAD_REJECTED_UUID_ARG_REGION_ARG_ENDPOINT_ARG_STATUS_ARG_8ED0679E = "LOAD rejected: uuid={}, region={}, endpoint={}, status={}"; public static final String MESSAGE_TARGET_NODE_REJECTED_LOAD_WITHOUT_A_STATUS_OR_A_MESSAGE_F4E4C645 = diff --git a/iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java b/iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java index efedcfb81eddb..3fc857922b78d 100644 --- a/iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java +++ b/iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java @@ -44,6 +44,11 @@ public final class DataNodeQueryMessages { "执行语句 %s 时,在转换为 tablet 前读取 TsFile 模型信息失败:%s"; public static final String EXCEPTION_FAILED_TO_LOAD_TSFILES_AFTER_TABLET_CONVERSION_DETAILS_ARG_53647EC5 = "将 TsFile 转换为 tablet 后加载仍失败。详情:%s"; + public static final String + EXCEPTION_TSFILE_ARG_IS_UNCERTAIN_AFTER_AN_RPC_TRANSPORT_FAILURE_2A59AF17 = + "RPC 传输失败后,TsFile %s 的加载结果不确定。"; + public static final String EXCEPTION_FAILED_TO_LOAD_TSFILES_DETAILS_ARG_D79C19DB = + "TsFile 加载失败。详情:%s"; public static final String LOG_LOAD_REJECTED_UUID_ARG_REGION_ARG_ENDPOINT_ARG_STATUS_ARG_8ED0679E = "LOAD 被拒绝:uuid={},region={},endpoint={},status={}"; public static final String MESSAGE_TARGET_NODE_REJECTED_LOAD_WITHOUT_A_STATUS_OR_A_MESSAGE_F4E4C645 = diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ClusterPartitionFetcher.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ClusterPartitionFetcher.java index 824e3a4fbe08d..81c3145c95d04 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ClusterPartitionFetcher.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ClusterPartitionFetcher.java @@ -347,7 +347,8 @@ public DataPartition getOrCreateDataPartition( String.format( DataNodeQueryMessages .QUERY_EXCEPTION_AN_ERROR_OCCURRED_WHEN_EXECUTING_GETORCREATEDATAPARTITION_2EB2EBBE, - e.getMessage())); + e.getMessage()), + e); } return dataPartition; } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitter.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitter.java index 8c91027bdb42e..7eae991ec4fb7 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitter.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitter.java @@ -25,6 +25,7 @@ import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet; import org.apache.iotdb.common.rpc.thrift.TSStatus; import org.apache.iotdb.commons.client.IClientManager; +import org.apache.iotdb.commons.client.exception.ClientManagerException; import org.apache.iotdb.commons.client.sync.SyncDataNodeInternalServiceClient; import org.apache.iotdb.commons.consensus.ConsensusGroupId; import org.apache.iotdb.consensus.ConsensusFactory; @@ -45,12 +46,14 @@ import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; +import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.concurrent.TimeoutException; /** * Submits LOAD consensus lifecycle commands (PIECE, PREPARE, COMMIT, ABORT) to target DataRegions @@ -64,6 +67,7 @@ public class LoadConsensusSubmitter { private final TEndPoint localEndPoint; private final IClientManager clientManager; + private boolean lastSubmissionRpcTransportFailure; public LoadConsensusSubmitter( final IClientManager clientManager) { @@ -125,6 +129,7 @@ public TRegionReplicaSet resolveRoute(final TConsensusGroupId regionId, final in /** Submits a consensus command node to the resolved active write peer of the replica set. */ public TSStatus submit(final TRegionReplicaSet replicaSet, final LoadTsFileConsensusNode node) { + lastSubmissionRpcTransportFailure = false; Objects.requireNonNull( replicaSet, StorageEngineMessages.EXCEPTION_REPLICASET_CANNOT_BE_NULL_A7340AC3); Objects.requireNonNull(node, StorageEngineMessages.EXCEPTION_NODE_CANNOT_BE_NULL_BC7D5BB9); @@ -157,6 +162,11 @@ public TSStatus submit(final TRegionReplicaSet replicaSet, final LoadTsFileConse : writeRemote(targetEndPoint, regionId, node); } + /** Returns whether the last command submission failed on its RPC transport path. */ + boolean isLastSubmissionRpcTransportFailure() { + return lastSubmissionRpcTransportFailure; + } + /** * Resolves the primary write peer: Ratis matches active elected leader, IoTConsensus routes to * index 0. @@ -243,6 +253,7 @@ private TSStatus writeRemote( TSStatusCode.DISPATCH_ERROR, StorageEngineMessages.MESSAGE_TARGET_NODE_REJECTED_COMMAND_WITHOUT_STATUS_12009B10); } catch (final Exception e) { + lastSubmissionRpcTransportFailure = isRpcTransportException(e); LOGGER.warn( StorageEngineMessages.LOG_FAILED_TO_DISPATCH_LOAD_COMMAND_TO_REMOTE_ENDPOINT_ARG_142A712A, endPoint, @@ -256,6 +267,22 @@ private TSStatus writeRemote( } } + private static boolean isRpcTransportException(Throwable error) { + return isPotentiallyUnstableRpcFailure(error); + } + + static boolean isPotentiallyUnstableRpcFailure(Throwable error) { + while (error != null) { + if (error instanceof ClientManagerException + || error instanceof TException + || error instanceof TimeoutException) { + return true; + } + error = error.getCause(); + } + return false; + } + private boolean isLocal(final TEndPoint endPoint) { return localEndPoint.equals(endPoint); } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java index 5204941451738..bfcbbd488bc7f 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java @@ -40,6 +40,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; import static org.apache.iotdb.db.storageengine.load.config.LoadTsFileConfigurator.AUTO_CREATE_SCHEMA_KEY; @@ -60,6 +61,7 @@ public class LoadFallbackHandler { private final boolean isGeneratedByPipe; private final List tsFileNodeList; private final List failedTsFileNodeIndexes; + private final Set rpcTransportFailureNodeIndexes; private final QueryStateMachine stateMachine; public LoadFallbackHandler( @@ -68,6 +70,22 @@ public LoadFallbackHandler( final List tsFileNodeList, final List failedTsFileNodeIndexes, final QueryStateMachine stateMachine) { + this( + queryContext, + isGeneratedByPipe, + tsFileNodeList, + failedTsFileNodeIndexes, + Collections.emptySet(), + stateMachine); + } + + public LoadFallbackHandler( + final MPPQueryContext queryContext, + final boolean isGeneratedByPipe, + final List tsFileNodeList, + final List failedTsFileNodeIndexes, + final Set rpcTransportFailureNodeIndexes, + final QueryStateMachine stateMachine) { this.queryContext = Objects.requireNonNull( queryContext, DataNodeQueryMessages.EXCEPTION_QUERYCONTEXT_CANNOT_BE_NULL_C2B25B22); @@ -79,6 +97,7 @@ public LoadFallbackHandler( Objects.requireNonNull( failedTsFileNodeIndexes, DataNodeQueryMessages.EXCEPTION_FAILEDTSFILENODEINDEXES_CANNOT_BE_NULL_D1C0E7C6); + this.rpcTransportFailureNodeIndexes = Objects.requireNonNull(rpcTransportFailureNodeIndexes); this.stateMachine = Objects.requireNonNull( stateMachine, DataNodeQueryMessages.EXCEPTION_STATEMACHINE_CANNOT_BE_NULL_4AF40790); @@ -96,10 +115,12 @@ public void convertFailedTsFilesToTablets() { } final String initialFailedFiles = getFailedFilePathsString(); - LOGGER.info( - DataNodeQueryMessages - .LOAD_TSFILE_S_FAILED_WILL_TRY_TO_CONVERT_TO_TABLETS_AND_INSERT_FAILED_TSFILES_ARG, - initialFailedFiles); + if (initialFailedFiles != null && !initialFailedFiles.isEmpty()) { + LOGGER.info( + DataNodeQueryMessages + .LOAD_TSFILE_S_FAILED_WILL_TRY_TO_CONVERT_TO_TABLETS_AND_INSERT_FAILED_TSFILES_ARG, + initialFailedFiles); + } final long startTime = System.nanoTime(); try { @@ -133,6 +154,17 @@ private void convertAndRetry() { final LoadSingleTsFileNode failedNode = tsFileNodeList.get(nodeIndex); final String filePath = failedNode.getTsFileResource().getTsFilePath(); + if (rpcTransportFailureNodeIndexes.contains(nodeIndex)) { + final String message = + String.format( + DataNodeQueryMessages + .EXCEPTION_TSFILE_ARG_IS_UNCERTAIN_AFTER_AN_RPC_TRANSPORT_FAILURE_2A59AF17, + filePath); + failureDetails.add(message); + LOGGER.warn(message); + continue; + } + try { final TSStatus status = convertTsFileToTablets( @@ -233,8 +265,10 @@ private void resolveFinalState(final List failureDetails) { final String message = String.format( - DataNodeQueryMessages - .EXCEPTION_FAILED_TO_LOAD_TSFILES_AFTER_TABLET_CONVERSION_DETAILS_ARG_53647EC5, + failedTsFileNodeIndexes.stream().anyMatch(rpcTransportFailureNodeIndexes::contains) + ? DataNodeQueryMessages.EXCEPTION_FAILED_TO_LOAD_TSFILES_DETAILS_ARG_D79C19DB + : DataNodeQueryMessages + .EXCEPTION_FAILED_TO_LOAD_TSFILES_AFTER_TABLET_CONVERSION_DETAILS_ARG_53647EC5, String.join("; ", failureDetails)); LOGGER.warn(message); stateMachine.transitionToFailed(new LoadFileException(message)); @@ -247,6 +281,7 @@ private void resolveFinalState(final List failureDetails) { private String getFailedFilePathsString() { return failedTsFileNodeIndexes.stream() .filter(index -> index >= 0 && index < tsFileNodeList.size()) + .filter(index -> !rpcTransportFailureNodeIndexes.contains(index)) .map(index -> tsFileNodeList.get(index).getTsFileResource().getTsFilePath()) .collect(Collectors.joining(", ")); } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java index 24c78410dd5a5..00eb4d9d274ed 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java @@ -44,6 +44,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -362,6 +363,7 @@ public void start() { } stateMachine.transitionToRunning(); boolean allFilesSucceeded = true; + final Set rpcTransportFailureNodeIndexes = new HashSet<>(); final int totalFiles = tsFileNodeList.size(); for (int i = 0; i < totalFiles; ++i) { @@ -374,7 +376,7 @@ public void start() { partitionFetcher.setDatabase(getPartitionQueryDatabase(node, isGeneratedByPipe)); - if (!processSingleNode(node, i, totalFiles, userName)) { + if (!processSingleNode(node, i, totalFiles, userName, rpcTransportFailureNodeIndexes)) { allFilesSucceeded = false; failedTsFileNodeIndexes.add(i); continue; @@ -392,6 +394,7 @@ public void start() { isGeneratedByPipe, tsFileNodeList, failedTsFileNodeIndexes, + rpcTransportFailureNodeIndexes, stateMachine) .convertFailedTsFilesToTablets(); } @@ -417,10 +420,12 @@ private boolean processSingleNode( final LoadSingleTsFileNode node, final int index, final int totalFiles, - final String userName) { + final String userName, + final Set rpcTransportFailureNodeIndexes) { final String filePath = node.getTsFileResource().getTsFilePath(); final long startTimeMs = System.currentTimeMillis(); boolean lockAcquired = false; + TsFileLoadStrategy strategy = null; try { if (!ACTIVE_LOADING_FILES.add(filePath)) { @@ -437,8 +442,11 @@ private boolean processSingleNode( return true; } - final TsFileLoadStrategy strategy = resolveStrategy(node, userName); + strategy = resolveStrategy(node, userName); final boolean loadSuccess = strategy.execute(node); + if (!loadSuccess && strategy.hasRpcTransportFailure()) { + rpcTransportFailureNodeIndexes.add(index); + } if (isRegionMigrating(startTimeMs)) { LOGGER.warn( @@ -456,6 +464,10 @@ private boolean processSingleNode( return true; } catch (final Exception e) { + if (LoadConsensusSubmitter.isPotentiallyUnstableRpcFailure(e) + || (strategy != null && strategy.hasRpcTransportFailure())) { + rpcTransportFailureNodeIndexes.add(index); + } LOGGER.warn(DataNodeQueryMessages.LOADTSFILESCHEDULER_LOADS_TSFILE_ERROR, filePath, e); return false; } finally { diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TsFileLoadStrategy.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TsFileLoadStrategy.java index 97b89f8208af1..e672fa37c8727 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TsFileLoadStrategy.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TsFileLoadStrategy.java @@ -43,4 +43,9 @@ public interface TsFileLoadStrategy { * @return true if the file was loaded successfully */ boolean execute(LoadSingleTsFileNode node) throws IoTDBException; + + /** Returns whether executing this file encountered an RPC transport failure. */ + default boolean hasRpcTransportFailure() { + return false; + } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java index aa0ec86cddd07..7316511d8c3e1 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java @@ -96,6 +96,7 @@ public class TwoPhaseConsensusLoadStrategy implements TsFileLoadStrategy { private final LoadTsFileDataCacheMemoryBlock block; private final LoadConsensusSubmitter consensusSubmitter; private final boolean isGeneratedByPipe; + private boolean rpcTransportFailure; /** The source file being loaded, kept for the phase-two commands. */ private LoadSingleTsFileNode currentNode; @@ -145,6 +146,7 @@ public TwoPhaseConsensusLoadStrategy( @Override public boolean execute(LoadSingleTsFileNode node) { this.currentNode = node; + rpcTransportFailure = false; dispatcher.setUuid(UUID.randomUUID().toString()); regionRoutes.clear(); regionLoadIds.clear(); @@ -174,6 +176,11 @@ public boolean execute(LoadSingleTsFileNode node) { return isFirstPhaseSuccess && isSecondPhaseSuccess; } + @Override + public boolean hasRpcTransportFailure() { + return rpcTransportFailure; + } + private boolean firstPhase(LoadSingleTsFileNode node) { final TsFileSplitConsumer pipeline = new TsFileSplitConsumer( @@ -187,6 +194,7 @@ private boolean firstPhase(LoadSingleTsFileNode node) { .splitTsFileByDataPartition(); return pipeline.sendAllTsFileData(); } catch (IllegalStateException e) { + rpcTransportFailure |= LoadConsensusSubmitter.isPotentiallyUnstableRpcFailure(e); LOGGER.warn( String.format( DataNodeQueryMessages.DISPATCH_TSFILEDATA_ERROR_WHEN_PARSING_TSFILE_S, @@ -194,6 +202,7 @@ private boolean firstPhase(LoadSingleTsFileNode node) { e); return false; } catch (Exception e) { + rpcTransportFailure |= LoadConsensusSubmitter.isPotentiallyUnstableRpcFailure(e); LOGGER.warn( String.format( DataNodeQueryMessages.PARSE_OR_SEND_TSFILE_S_ERROR, @@ -250,6 +259,7 @@ private TSStatus submitWithRetry( final boolean retryEveryFailure) { TRegionReplicaSet replicaSet = currentRoute(regionId); TSStatus status = consensusSubmitter.submit(replicaSet, node); + rpcTransportFailure |= consensusSubmitter.isLastSubmissionRpcTransportFailure(); for (int attempt = 1; attempt < LOAD_CONSENSUS_SUBMIT_MAX_RETRIES; attempt++) { if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode() || (!retryEveryFailure && !isTransientConsensusFailure(status))) { @@ -295,6 +305,7 @@ private TSStatus submitWithRetry( break; } status = consensusSubmitter.submit(replicaSet, node); + rpcTransportFailure |= consensusSubmitter.isLastSubmissionRpcTransportFailure(); } return status; } diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitterTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitterTest.java index b224b8738228c..3d377c052a857 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitterTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitterTest.java @@ -24,7 +24,9 @@ import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation; import org.apache.iotdb.common.rpc.thrift.TEndPoint; import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet; +import org.apache.iotdb.common.rpc.thrift.TSStatus; import org.apache.iotdb.commons.client.IClientManager; +import org.apache.iotdb.commons.client.exception.ClientManagerException; import org.apache.iotdb.commons.client.sync.SyncDataNodeInternalServiceClient; import org.apache.iotdb.commons.consensus.ConsensusGroupId; import org.apache.iotdb.commons.queryengine.plan.planner.plan.node.PlanNodeId; @@ -36,8 +38,13 @@ import org.apache.iotdb.db.consensus.DataRegionConsensusImpl; import org.apache.iotdb.db.queryengine.plan.analyze.ClusterPartitionFetcher; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.load.LoadTsFileConsensusNode; +import org.apache.iotdb.mpp.rpc.thrift.TSendBatchPlanNodeResp; +import org.apache.iotdb.mpp.rpc.thrift.TSendSinglePlanNodeResp; +import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; +import org.apache.thrift.TException; +import org.apache.thrift.transport.TTransportException; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -48,11 +55,14 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import java.io.IOException; import java.util.Arrays; import java.util.Collections; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * Pins how the write peer of a LOAD consensus command is resolved. @@ -139,6 +149,107 @@ public void testCommandIsNotSentWhenNoWritePeerCanBeResolved() { assertEquals(TSStatusCode.DISPATCH_ERROR, status); } + @Test + public void testTransportExceptionIsClassified() throws Exception { + config.setDataRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS); + stubLeader(11); + final TEndPoint endPoint = new TEndPoint("192.0.2.1", 9003); + final SyncDataNodeInternalServiceClient client = + Mockito.mock(SyncDataNodeInternalServiceClient.class); + final IClientManager clientManager = + newClientManager(); + Mockito.when(clientManager.borrowClient(endPoint)).thenReturn(client); + Mockito.when(client.sendBatchPlanNode(Mockito.any())).thenThrow(new TTransportException()); + final LoadTsFileConsensusNode node = + LoadTsFileConsensusNode.prepare( + new PlanNodeId("load-prepare"), "load-id", 0, 0L, false, Collections.emptyMap()); + final LoadConsensusSubmitter submitter = new LoadConsensusSubmitter(clientManager); + + final TSStatus status = + submitter.submit(replicaSet(location(11, endPoint.getIp(), endPoint.getPort())), node); + + assertEquals(TSStatusCode.DISPATCH_ERROR.getStatusCode(), status.getCode()); + assertTrue(submitter.isLastSubmissionRpcTransportFailure()); + } + + @Test + public void testGenericThriftFailureIsClassified() throws Exception { + config.setDataRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS); + stubLeader(11); + final TEndPoint endPoint = new TEndPoint("192.0.2.1", 9003); + final SyncDataNodeInternalServiceClient client = + Mockito.mock(SyncDataNodeInternalServiceClient.class); + final IClientManager clientManager = + newClientManager(); + Mockito.when(clientManager.borrowClient(endPoint)).thenReturn(client); + Mockito.when(client.sendBatchPlanNode(Mockito.any())).thenThrow(new TException("rpc failure")); + final LoadTsFileConsensusNode node = + LoadTsFileConsensusNode.prepare( + new PlanNodeId("load-prepare"), "load-id", 0, 0L, false, Collections.emptyMap()); + final LoadConsensusSubmitter submitter = new LoadConsensusSubmitter(clientManager); + + final TSStatus status = + submitter.submit(replicaSet(location(11, endPoint.getIp(), endPoint.getPort())), node); + + assertEquals(TSStatusCode.DISPATCH_ERROR.getStatusCode(), status.getCode()); + assertTrue(submitter.isLastSubmissionRpcTransportFailure()); + } + + @Test + public void testClientManagerFailureIsClassified() throws Exception { + config.setDataRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS); + stubLeader(11); + final TEndPoint endPoint = new TEndPoint("192.0.2.1", 9003); + final IClientManager clientManager = + newClientManager(); + Mockito.when(clientManager.borrowClient(endPoint)) + .thenThrow(new ClientManagerException("pool failure")); + final LoadTsFileConsensusNode node = + LoadTsFileConsensusNode.prepare( + new PlanNodeId("load-prepare"), "load-id", 0, 0L, false, Collections.emptyMap()); + final LoadConsensusSubmitter submitter = new LoadConsensusSubmitter(clientManager); + + final TSStatus status = + submitter.submit(replicaSet(location(11, endPoint.getIp(), endPoint.getPort())), node); + + assertEquals(TSStatusCode.DISPATCH_ERROR.getStatusCode(), status.getCode()); + assertTrue(submitter.isLastSubmissionRpcTransportFailure()); + } + + @Test + public void testLocalIOExceptionIsNotClassifiedAsUnstableRpcFailure() { + assertFalse( + LoadConsensusSubmitter.isPotentiallyUnstableRpcFailure(new IOException("local failure"))); + } + + @Test + public void testReceiverRejectionIsNotClassifiedAsTransportFailure() throws Exception { + config.setDataRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS); + stubLeader(11); + final TEndPoint endPoint = new TEndPoint("192.0.2.1", 9003); + final SyncDataNodeInternalServiceClient client = + Mockito.mock(SyncDataNodeInternalServiceClient.class); + final IClientManager clientManager = + newClientManager(); + Mockito.when(clientManager.borrowClient(endPoint)).thenReturn(client); + final TSendSinglePlanNodeResp singleResponse = new TSendSinglePlanNodeResp(); + singleResponse.setAccepted(false); + singleResponse.setStatus(RpcUtils.getStatus(TSStatusCode.DISPATCH_ERROR)); + final TSendBatchPlanNodeResp batchResponse = new TSendBatchPlanNodeResp(); + batchResponse.setResponses(Collections.singletonList(singleResponse)); + Mockito.when(client.sendBatchPlanNode(Mockito.any())).thenReturn(batchResponse); + final LoadTsFileConsensusNode node = + LoadTsFileConsensusNode.prepare( + new PlanNodeId("load-prepare"), "load-id", 0, 0L, false, Collections.emptyMap()); + final LoadConsensusSubmitter submitter = new LoadConsensusSubmitter(clientManager); + + final TSStatus status = + submitter.submit(replicaSet(location(11, endPoint.getIp(), endPoint.getPort())), node); + + assertEquals(TSStatusCode.DISPATCH_ERROR.getStatusCode(), status.getCode()); + assertFalse(submitter.isLastSubmissionRpcTransportFailure()); + } + /** * A route that is looked up again drops the cached route of that region first: a lookup answers * with the route the cache holds, and the route that has to be resolved again is the one that may @@ -219,9 +330,13 @@ private static TDataNodeLocation resolveWritePeer( @SuppressWarnings("unchecked") private static LoadConsensusSubmitter newSubmitter() { - return new LoadConsensusSubmitter( - (IClientManager) - Mockito.mock(IClientManager.class)); + return new LoadConsensusSubmitter(newClientManager()); + } + + @SuppressWarnings("unchecked") + private static IClientManager newClientManager() { + return (IClientManager) + Mockito.mock(IClientManager.class); } private static ConsensusGroupId groupId() { diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java index e72b1c66d38aa..1857b7a7a5957 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java @@ -62,6 +62,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -145,6 +146,32 @@ public void testSuccessfulConversionsStillFinishLoad() throws Exception { Assert.assertTrue(failedIndexes.isEmpty()); } + @Test + public void testRpcTransportFailureSkipsTabletFallback() throws Exception { + final LoadSingleTsFileNode node = newNode("rpc-failed.tsfile", false); + final List failedIndexes = new ArrayList<>(Collections.singletonList(0)); + final QueryStateMachine stateMachine = newStateMachine(); + + new LoadFallbackHandler( + mock(MPPQueryContext.class), + false, + Collections.singletonList(node), + failedIndexes, + Collections.singleton(0), + stateMachine) + .convertFailedTsFilesToTablets(); + + Assert.assertEquals(QueryState.FAILED, stateMachine.getState()); + Assert.assertEquals(Collections.singletonList(0), failedIndexes); + Assert.assertTrue( + stateMachine + .getFailureStatus() + .getMessage() + .contains(node.getTsFileResource().getTsFilePath())); + verify(converter, never()).convertForTreeModel(any()); + verify(converter, never()).convertForTableModel(any()); + } + @Test public void testTableFallbackPreservesRequestSchemaCreationSetting() throws Exception { assertTableConversionPreservesRequestSchemaCreationSetting(false); diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java index f576245056e73..5eac96a113f76 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java @@ -19,8 +19,14 @@ package org.apache.iotdb.db.queryengine.plan.scheduler.load; +import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet; +import org.apache.iotdb.common.rpc.thrift.TTimePartitionSlot; import org.apache.iotdb.commons.client.IClientManager; +import org.apache.iotdb.commons.client.exception.ClientManagerException; +import org.apache.iotdb.commons.partition.DataPartitionQueryParam; +import org.apache.iotdb.commons.queryengine.common.SessionInfo; import org.apache.iotdb.db.exception.load.LoadFileException; +import org.apache.iotdb.db.exception.sql.StatementAnalyzeException; import org.apache.iotdb.db.queryengine.common.MPPQueryContext; import org.apache.iotdb.db.queryengine.common.PlanFragmentId; import org.apache.iotdb.db.queryengine.common.QueryId; @@ -28,17 +34,22 @@ import org.apache.iotdb.db.queryengine.execution.QueryStateMachine; import org.apache.iotdb.db.queryengine.plan.analyze.IPartitionFetcher; import org.apache.iotdb.db.queryengine.plan.planner.plan.DistributedQueryPlan; +import org.apache.iotdb.db.queryengine.plan.planner.plan.FragmentInstance; import org.apache.iotdb.db.queryengine.plan.planner.plan.PlanFragment; import org.apache.iotdb.db.queryengine.plan.planner.plan.SubPlan; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.load.LoadSingleTsFileNode; import org.apache.iotdb.db.queryengine.plan.statement.crud.LoadTsFileStatement; +import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource; import org.apache.iotdb.db.storageengine.load.memory.LoadTsFileDataCacheMemoryBlock; import org.apache.ratis.thirdparty.com.google.common.util.concurrent.MoreExecutors; +import org.apache.tsfile.file.metadata.IDeviceID; +import org.apache.tsfile.utils.Pair; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import java.io.File; @@ -46,6 +57,8 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; +import java.util.List; +import java.util.function.Function; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -171,6 +184,61 @@ public void testGetPartitionQueryDatabaseForTableModelLoad() { Assert.assertEquals("test", LoadTsFileScheduler.getPartitionQueryDatabase(node, false)); } + @Test + public void testPartitionClientManagerFailureSkipsTabletFallback() { + final LoadSingleTsFileNode node = mock(LoadSingleTsFileNode.class); + final TsFileResource tsFileResource = mock(TsFileResource.class); + Mockito.when(node.getTsFileResource()).thenReturn(tsFileResource); + Mockito.when(tsFileResource.getTsFilePath()).thenReturn("partition-failed.tsfile"); + Mockito.when(node.isTsFileEmpty()).thenReturn(false); + Mockito.when(node.needDecodeTsFile(Mockito.any())) + .thenAnswer( + invocation -> { + final Function>, List> + partitionQuery = invocation.getArgument(0); + partitionQuery.apply( + Collections.singletonList( + new Pair<>(mock(IDeviceID.class), mock(TTimePartitionSlot.class)))); + return true; + }); + final FragmentInstance instance = Mockito.mock(FragmentInstance.class); + final PlanFragment fragment = Mockito.mock(PlanFragment.class); + Mockito.when(instance.getFragment()).thenReturn(fragment); + Mockito.when(fragment.getPlanNodeTree()).thenReturn(node); + Mockito.when(distributedQueryPlan.getInstances()) + .thenReturn(Collections.singletonList(instance)); + + final QueryStateMachine stateMachine = newStateMachine("load_partition_rpc_failure"); + final MPPQueryContext queryContext = mock(MPPQueryContext.class); + final SessionInfo sessionInfo = mock(SessionInfo.class); + Mockito.when(queryContext.getSession()).thenReturn(sessionInfo); + Mockito.when(sessionInfo.getUserName()).thenReturn("root"); + final IPartitionFetcher partitionFetcher = mock(IPartitionFetcher.class); + Mockito.when( + partitionFetcher.getOrCreateDataPartition( + Mockito.anyList(), Mockito.anyString())) + .thenThrow( + new StatementAnalyzeException( + "partition query failed", new ClientManagerException("pool failure"))); + + final LoadTsFileScheduler scheduler = + new LoadTsFileScheduler( + distributedQueryPlan, + queryContext, + stateMachine, + mock(IClientManager.class), + partitionFetcher, + false); + + scheduler.start(); + + Assert.assertEquals(QueryState.FAILED, stateMachine.getState()); + Assert.assertTrue(stateMachine.getFailureMessage().contains("partition-failed.tsfile")); + Assert.assertTrue(stateMachine.getFailureMessage().contains("RPC transport failure")); + Mockito.verify(partitionFetcher) + .getOrCreateDataPartition(Mockito.anyList(), Mockito.anyString()); + } + @Test public void testBuildRetryTreeLoadStatementUpdatesDatabaseLevel() throws Exception { final LoadFallbackHandler fallbackHandler = diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java index 2c855ec031438..d86b9a6817275 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java @@ -24,6 +24,7 @@ import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation; import org.apache.iotdb.common.rpc.thrift.TEndPoint; import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet; +import org.apache.iotdb.common.rpc.thrift.TSStatus; import org.apache.iotdb.commons.queryengine.plan.planner.plan.node.PlanNodeId; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.load.LoadTsFileConsensusNode; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.load.LoadTsFileConsensusOp; @@ -49,6 +50,8 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; /** @@ -65,6 +68,34 @@ public class TwoPhaseConsensusLoadStrategyAbortTest { private static final TConsensusGroupId REGION_2 = new TConsensusGroupId(TConsensusGroupType.DataRegion, 2); + @Test + public void testExhaustedTransportRetriesRemainClassified() throws Exception { + final LoadConsensusSubmitter submitter = mock(LoadConsensusSubmitter.class); + when(submitter.submit(any(), any())) + .thenReturn(RpcUtils.getStatus(TSStatusCode.DISPATCH_ERROR)); + when(submitter.isLastSubmissionRpcTransportFailure()).thenReturn(true); + when(submitter.resolveRoute(any(), any(Integer.class))) + .thenAnswer(invocation -> currentRoute(invocation.getArgument(0))); + final TwoPhaseConsensusLoadStrategy strategy = + strategy(submitter, twoRegionsInOrder(), loadIds(), pieceCounts()); + final Method submitWithRetry = + TwoPhaseConsensusLoadStrategy.class.getDeclaredMethod( + "submitWithRetry", + TConsensusGroupId.class, + LoadTsFileConsensusNode.class, + boolean.class); + submitWithRetry.setAccessible(true); + final LoadTsFileConsensusNode command = + LoadTsFileConsensusNode.abort( + new PlanNodeId("load-abort"), "load-id", false, Collections.emptyMap()); + + final TSStatus status = (TSStatus) submitWithRetry.invoke(strategy, REGION_1, command, false); + + assertEquals(TSStatusCode.DISPATCH_ERROR.getStatusCode(), status.getCode()); + assertTrue(strategy.hasRpcTransportFailure()); + verify(submitter, times(3)).submit(any(), any()); + } + /** * Fails the given operation for the given region with a permanent error, accepts the rest. The * route of a region stays resolvable, so a command that is retried is retried on the route the From 2dd69d95e3314399c86afcd741ac409a258f1f3d Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Fri, 27 Nov 2026 14:32:29 +0800 Subject: [PATCH 2/9] Clean up LOAD fallback control flow --- .../scheduler/load/LoadFallbackHandler.java | 80 ++++++++++--------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java index bfcbbd488bc7f..46080a6113834 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java @@ -162,49 +162,55 @@ private void convertAndRetry() { filePath); failureDetails.add(message); LOGGER.warn(message); - continue; + } else { + convertFailedTsFileToTablets(converter, failedNode, iterator, failureDetails); } + } + + resolveFinalState(failureDetails); + } - try { - final TSStatus status = - convertTsFileToTablets( - converter, failedNode, isGeneratedByPipe, failedNode.isDeleteAfterLoad()); - - if (converter.isSuccessful(status)) { - iterator.remove(); - LOGGER.info( - DataNodeQueryMessages - .LOAD_SUCCESSFULLY_CONVERTED_TSFILE_ARG_INTO_TABLETS_AND_INSERTED, - filePath); - } else { - final String message = - status == null - ? String.format( - DataNodeQueryMessages - .EXCEPTION_FAILED_TO_CONVERT_TSFILE_ARG_TO_TABLETS_ARG_96358FDD, - filePath, - DataNodeQueryMessages.MESSAGE_TABLET_CONVERSION_RETURNED_NO_STATUS_88BAB5D3) - : String.format( - DataNodeQueryMessages - .EXCEPTION_FAILED_TO_CONVERT_TSFILE_ARG_TO_TABLETS_STATUS_ARG_E7C9F477, - filePath, - status); - failureDetails.add(message); - LOGGER.warn(message); - } - } catch (final Exception e) { + private void convertFailedTsFileToTablets( + final LoadTsFileDataTypeConverter converter, + final LoadSingleTsFileNode failedNode, + final Iterator iterator, + final List failureDetails) { + final String filePath = failedNode.getTsFileResource().getTsFilePath(); + try { + final TSStatus status = + convertTsFileToTablets( + converter, failedNode, isGeneratedByPipe, failedNode.isDeleteAfterLoad()); + + if (converter.isSuccessful(status)) { + iterator.remove(); + LOGGER.info( + DataNodeQueryMessages.LOAD_SUCCESSFULLY_CONVERTED_TSFILE_ARG_INTO_TABLETS_AND_INSERTED, + filePath); + } else { final String message = - String.format( - DataNodeQueryMessages - .EXCEPTION_FAILED_TO_CONVERT_TSFILE_ARG_TO_TABLETS_ARG_96358FDD, - filePath, - e); + status == null + ? String.format( + DataNodeQueryMessages + .EXCEPTION_FAILED_TO_CONVERT_TSFILE_ARG_TO_TABLETS_ARG_96358FDD, + filePath, + DataNodeQueryMessages.MESSAGE_TABLET_CONVERSION_RETURNED_NO_STATUS_88BAB5D3) + : String.format( + DataNodeQueryMessages + .EXCEPTION_FAILED_TO_CONVERT_TSFILE_ARG_TO_TABLETS_STATUS_ARG_E7C9F477, + filePath, + status); failureDetails.add(message); - LOGGER.warn(message, e); + LOGGER.warn(message); } + } catch (final Exception e) { + final String message = + String.format( + DataNodeQueryMessages.EXCEPTION_FAILED_TO_CONVERT_TSFILE_ARG_TO_TABLETS_ARG_96358FDD, + filePath, + e); + failureDetails.add(message); + LOGGER.warn(message, e); } - - resolveFinalState(failureDetails); } static TSStatus convertTsFileToTablets( From 184fa84399ab8bc1dd21f07ea06c59134645c868 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:12:19 +0800 Subject: [PATCH 3/9] Fix LOAD retry and fallback safety --- .../iotdb/db/i18n/DataNodeQueryMessages.java | 4 +-- .../iotdb/db/i18n/DataNodeQueryMessages.java | 4 +-- .../load/LoadConsensusSubmitter.java | 8 +++--- .../scheduler/load/LoadFallbackHandler.java | 15 +++++------ .../scheduler/load/LoadTsFileScheduler.java | 16 ++++++------ .../scheduler/load/TsFileLoadStrategy.java | 5 ++++ .../load/TwoPhaseConsensusLoadStrategy.java | 9 +++++++ .../load/LoadConsensusSubmitterTest.java | 25 ++++++++++++++++--- .../load/LoadFallbackHandlerTest.java | 6 +++-- .../load/LoadTsFileSchedulerTest.java | 2 +- ...woPhaseConsensusLoadStrategyAbortTest.java | 2 ++ 11 files changed, 68 insertions(+), 28 deletions(-) diff --git a/iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java b/iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java index e13fd1cd1a88c..b81f80cc5257d 100644 --- a/iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java +++ b/iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java @@ -45,8 +45,8 @@ public final class DataNodeQueryMessages { public static final String EXCEPTION_FAILED_TO_LOAD_TSFILES_AFTER_TABLET_CONVERSION_DETAILS_ARG_53647EC5 = "Failed to load TsFiles after tablet conversion. Details: %s"; public static final String - EXCEPTION_TSFILE_ARG_IS_UNCERTAIN_AFTER_AN_RPC_TRANSPORT_FAILURE_2A59AF17 = - "TsFile %s is uncertain after an RPC transport failure."; + EXCEPTION_TSFILE_ARG_HAS_AN_UNCERTAIN_LOAD_OUTCOME_RETRY_WAS_SKIPPED_70149528 = + "TsFile %s has an uncertain LOAD outcome; retry was skipped."; public static final String EXCEPTION_FAILED_TO_LOAD_TSFILES_DETAILS_ARG_D79C19DB = "Failed to load TsFiles. Details: %s"; public static final String LOG_LOAD_REJECTED_UUID_ARG_REGION_ARG_ENDPOINT_ARG_STATUS_ARG_8ED0679E = diff --git a/iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java b/iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java index 3fc857922b78d..ce300fe8a2ec3 100644 --- a/iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java +++ b/iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java @@ -45,8 +45,8 @@ public final class DataNodeQueryMessages { public static final String EXCEPTION_FAILED_TO_LOAD_TSFILES_AFTER_TABLET_CONVERSION_DETAILS_ARG_53647EC5 = "将 TsFile 转换为 tablet 后加载仍失败。详情:%s"; public static final String - EXCEPTION_TSFILE_ARG_IS_UNCERTAIN_AFTER_AN_RPC_TRANSPORT_FAILURE_2A59AF17 = - "RPC 传输失败后,TsFile %s 的加载结果不确定。"; + EXCEPTION_TSFILE_ARG_HAS_AN_UNCERTAIN_LOAD_OUTCOME_RETRY_WAS_SKIPPED_70149528 = + "TsFile %s 的 LOAD 结果不确定,已跳过重试。"; public static final String EXCEPTION_FAILED_TO_LOAD_TSFILES_DETAILS_ARG_D79C19DB = "TsFile 加载失败。详情:%s"; public static final String LOG_LOAD_REJECTED_UUID_ARG_REGION_ARG_ENDPOINT_ARG_STATUS_ARG_8ED0679E = diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitter.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitter.java index 7eae991ec4fb7..3a5e0e8d4ca3e 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitter.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitter.java @@ -46,10 +46,11 @@ import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; -import org.apache.thrift.TException; +import org.apache.thrift.transport.TTransportException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.net.SocketTimeoutException; import java.util.Collections; import java.util.List; import java.util.Objects; @@ -274,8 +275,9 @@ private static boolean isRpcTransportException(Throwable error) { static boolean isPotentiallyUnstableRpcFailure(Throwable error) { while (error != null) { if (error instanceof ClientManagerException - || error instanceof TException - || error instanceof TimeoutException) { + || error instanceof TTransportException + || error instanceof TimeoutException + || error instanceof SocketTimeoutException) { return true; } error = error.getCause(); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java index 46080a6113834..eaa7f0a00a299 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java @@ -61,7 +61,7 @@ public class LoadFallbackHandler { private final boolean isGeneratedByPipe; private final List tsFileNodeList; private final List failedTsFileNodeIndexes; - private final Set rpcTransportFailureNodeIndexes; + private final Set tabletFallbackBlockedNodeIndexes; private final QueryStateMachine stateMachine; public LoadFallbackHandler( @@ -84,7 +84,7 @@ public LoadFallbackHandler( final boolean isGeneratedByPipe, final List tsFileNodeList, final List failedTsFileNodeIndexes, - final Set rpcTransportFailureNodeIndexes, + final Set tabletFallbackBlockedNodeIndexes, final QueryStateMachine stateMachine) { this.queryContext = Objects.requireNonNull( @@ -97,7 +97,8 @@ public LoadFallbackHandler( Objects.requireNonNull( failedTsFileNodeIndexes, DataNodeQueryMessages.EXCEPTION_FAILEDTSFILENODEINDEXES_CANNOT_BE_NULL_D1C0E7C6); - this.rpcTransportFailureNodeIndexes = Objects.requireNonNull(rpcTransportFailureNodeIndexes); + this.tabletFallbackBlockedNodeIndexes = + Objects.requireNonNull(tabletFallbackBlockedNodeIndexes); this.stateMachine = Objects.requireNonNull( stateMachine, DataNodeQueryMessages.EXCEPTION_STATEMACHINE_CANNOT_BE_NULL_4AF40790); @@ -154,11 +155,11 @@ private void convertAndRetry() { final LoadSingleTsFileNode failedNode = tsFileNodeList.get(nodeIndex); final String filePath = failedNode.getTsFileResource().getTsFilePath(); - if (rpcTransportFailureNodeIndexes.contains(nodeIndex)) { + if (tabletFallbackBlockedNodeIndexes.contains(nodeIndex)) { final String message = String.format( DataNodeQueryMessages - .EXCEPTION_TSFILE_ARG_IS_UNCERTAIN_AFTER_AN_RPC_TRANSPORT_FAILURE_2A59AF17, + .EXCEPTION_TSFILE_ARG_HAS_AN_UNCERTAIN_LOAD_OUTCOME_RETRY_WAS_SKIPPED_70149528, filePath); failureDetails.add(message); LOGGER.warn(message); @@ -271,7 +272,7 @@ private void resolveFinalState(final List failureDetails) { final String message = String.format( - failedTsFileNodeIndexes.stream().anyMatch(rpcTransportFailureNodeIndexes::contains) + failedTsFileNodeIndexes.stream().anyMatch(tabletFallbackBlockedNodeIndexes::contains) ? DataNodeQueryMessages.EXCEPTION_FAILED_TO_LOAD_TSFILES_DETAILS_ARG_D79C19DB : DataNodeQueryMessages .EXCEPTION_FAILED_TO_LOAD_TSFILES_AFTER_TABLET_CONVERSION_DETAILS_ARG_53647EC5, @@ -287,7 +288,7 @@ private void resolveFinalState(final List failureDetails) { private String getFailedFilePathsString() { return failedTsFileNodeIndexes.stream() .filter(index -> index >= 0 && index < tsFileNodeList.size()) - .filter(index -> !rpcTransportFailureNodeIndexes.contains(index)) + .filter(index -> !tabletFallbackBlockedNodeIndexes.contains(index)) .map(index -> tsFileNodeList.get(index).getTsFileResource().getTsFilePath()) .collect(Collectors.joining(", ")); } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java index 00eb4d9d274ed..57fb3689080e5 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java @@ -363,7 +363,7 @@ public void start() { } stateMachine.transitionToRunning(); boolean allFilesSucceeded = true; - final Set rpcTransportFailureNodeIndexes = new HashSet<>(); + final Set tabletFallbackBlockedNodeIndexes = new HashSet<>(); final int totalFiles = tsFileNodeList.size(); for (int i = 0; i < totalFiles; ++i) { @@ -376,7 +376,7 @@ public void start() { partitionFetcher.setDatabase(getPartitionQueryDatabase(node, isGeneratedByPipe)); - if (!processSingleNode(node, i, totalFiles, userName, rpcTransportFailureNodeIndexes)) { + if (!processSingleNode(node, i, totalFiles, userName, tabletFallbackBlockedNodeIndexes)) { allFilesSucceeded = false; failedTsFileNodeIndexes.add(i); continue; @@ -394,7 +394,7 @@ public void start() { isGeneratedByPipe, tsFileNodeList, failedTsFileNodeIndexes, - rpcTransportFailureNodeIndexes, + tabletFallbackBlockedNodeIndexes, stateMachine) .convertFailedTsFilesToTablets(); } @@ -421,7 +421,7 @@ private boolean processSingleNode( final int index, final int totalFiles, final String userName, - final Set rpcTransportFailureNodeIndexes) { + final Set tabletFallbackBlockedNodeIndexes) { final String filePath = node.getTsFileResource().getTsFilePath(); final long startTimeMs = System.currentTimeMillis(); boolean lockAcquired = false; @@ -444,8 +444,8 @@ private boolean processSingleNode( strategy = resolveStrategy(node, userName); final boolean loadSuccess = strategy.execute(node); - if (!loadSuccess && strategy.hasRpcTransportFailure()) { - rpcTransportFailureNodeIndexes.add(index); + if (!loadSuccess && strategy.shouldSkipTabletFallback()) { + tabletFallbackBlockedNodeIndexes.add(index); } if (isRegionMigrating(startTimeMs)) { @@ -465,8 +465,8 @@ private boolean processSingleNode( return true; } catch (final Exception e) { if (LoadConsensusSubmitter.isPotentiallyUnstableRpcFailure(e) - || (strategy != null && strategy.hasRpcTransportFailure())) { - rpcTransportFailureNodeIndexes.add(index); + || (strategy != null && strategy.shouldSkipTabletFallback())) { + tabletFallbackBlockedNodeIndexes.add(index); } LOGGER.warn(DataNodeQueryMessages.LOADTSFILESCHEDULER_LOADS_TSFILE_ERROR, filePath, e); return false; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TsFileLoadStrategy.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TsFileLoadStrategy.java index e672fa37c8727..fe3603121d339 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TsFileLoadStrategy.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TsFileLoadStrategy.java @@ -48,4 +48,9 @@ public interface TsFileLoadStrategy { default boolean hasRpcTransportFailure() { return false; } + + /** Returns whether the file's LOAD outcome is unsafe to retry through tablet conversion. */ + default boolean shouldSkipTabletFallback() { + return hasRpcTransportFailure(); + } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java index 7316511d8c3e1..f642eaa19ab15 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java @@ -97,6 +97,7 @@ public class TwoPhaseConsensusLoadStrategy implements TsFileLoadStrategy { private final LoadConsensusSubmitter consensusSubmitter; private final boolean isGeneratedByPipe; private boolean rpcTransportFailure; + private boolean unresolvedLoadTransaction; /** The source file being loaded, kept for the phase-two commands. */ private LoadSingleTsFileNode currentNode; @@ -147,6 +148,7 @@ public TwoPhaseConsensusLoadStrategy( public boolean execute(LoadSingleTsFileNode node) { this.currentNode = node; rpcTransportFailure = false; + unresolvedLoadTransaction = false; dispatcher.setUuid(UUID.randomUUID().toString()); regionRoutes.clear(); regionLoadIds.clear(); @@ -181,6 +183,11 @@ public boolean hasRpcTransportFailure() { return rpcTransportFailure; } + @Override + public boolean shouldSkipTabletFallback() { + return rpcTransportFailure || unresolvedLoadTransaction; + } + private boolean firstPhase(LoadSingleTsFileNode node) { final TsFileSplitConsumer pipeline = new TsFileSplitConsumer( @@ -445,6 +452,7 @@ private boolean abortRegions() { TSStatusCode.representOf(status.getCode()).name(), status.getMessage()); allAborted = false; + unresolvedLoadTransaction = true; } } return allAborted; @@ -560,6 +568,7 @@ private void resolveTheCommitOutcomeOf(final TConsensusGroupId regionId, final S regionExpectedDataEnd.getOrDefault(regionId, Collections.emptyMap())); final TSStatus abortStatus = submitTerminalCommandWithRetry(regionId, abort); if (abortStatus.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { + unresolvedLoadTransaction = true; LOGGER.warn( DataNodeQueryMessages .LOG_THE_COMMIT_OUTCOME_OF_LOAD_TASK_ARG_IN_REGION_ARG_COULD_NOT_BE_RESOLVED_ARG_89B6F261, diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitterTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitterTest.java index 3d377c052a857..62c6670eeab4d 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitterTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadConsensusSubmitterTest.java @@ -43,6 +43,7 @@ import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; +import org.apache.thrift.TApplicationException; import org.apache.thrift.TException; import org.apache.thrift.transport.TTransportException; import org.junit.After; @@ -56,8 +57,10 @@ import org.powermock.modules.junit4.PowerMockRunner; import java.io.IOException; +import java.net.SocketTimeoutException; import java.util.Arrays; import java.util.Collections; +import java.util.concurrent.TimeoutException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -173,7 +176,7 @@ public void testTransportExceptionIsClassified() throws Exception { } @Test - public void testGenericThriftFailureIsClassified() throws Exception { + public void testGenericThriftFailureIsNotClassifiedAsTransportFailure() throws Exception { config.setDataRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS); stubLeader(11); final TEndPoint endPoint = new TEndPoint("192.0.2.1", 9003); @@ -192,7 +195,7 @@ public void testGenericThriftFailureIsClassified() throws Exception { submitter.submit(replicaSet(location(11, endPoint.getIp(), endPoint.getPort())), node); assertEquals(TSStatusCode.DISPATCH_ERROR.getStatusCode(), status.getCode()); - assertTrue(submitter.isLastSubmissionRpcTransportFailure()); + assertFalse(submitter.isLastSubmissionRpcTransportFailure()); } @Test @@ -217,9 +220,25 @@ public void testClientManagerFailureIsClassified() throws Exception { } @Test - public void testLocalIOExceptionIsNotClassifiedAsUnstableRpcFailure() { + public void testStableFailuresAreNotClassifiedAsUnstableRpcFailure() { assertFalse( LoadConsensusSubmitter.isPotentiallyUnstableRpcFailure(new IOException("local failure"))); + assertFalse( + LoadConsensusSubmitter.isPotentiallyUnstableRpcFailure(new TException("protocol failure"))); + assertFalse( + LoadConsensusSubmitter.isPotentiallyUnstableRpcFailure( + new TApplicationException( + TApplicationException.INTERNAL_ERROR, "application failure"))); + } + + @Test + public void testTimeoutsAreClassifiedAsUnstableRpcFailures() { + assertTrue( + LoadConsensusSubmitter.isPotentiallyUnstableRpcFailure( + new TimeoutException("rpc timeout"))); + assertTrue( + LoadConsensusSubmitter.isPotentiallyUnstableRpcFailure( + new SocketTimeoutException("socket timeout"))); } @Test diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java index 1857b7a7a5957..8e2e0ef8f574f 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java @@ -147,8 +147,8 @@ public void testSuccessfulConversionsStillFinishLoad() throws Exception { } @Test - public void testRpcTransportFailureSkipsTabletFallback() throws Exception { - final LoadSingleTsFileNode node = newNode("rpc-failed.tsfile", false); + public void testUncertainLoadOutcomeSkipsTabletFallback() throws Exception { + final LoadSingleTsFileNode node = newNode("uncertain.tsfile", false); final List failedIndexes = new ArrayList<>(Collections.singletonList(0)); final QueryStateMachine stateMachine = newStateMachine(); @@ -168,6 +168,8 @@ public void testRpcTransportFailureSkipsTabletFallback() throws Exception { .getFailureStatus() .getMessage() .contains(node.getTsFileResource().getTsFilePath())); + Assert.assertTrue( + stateMachine.getFailureStatus().getMessage().contains("uncertain LOAD outcome")); verify(converter, never()).convertForTreeModel(any()); verify(converter, never()).convertForTableModel(any()); } diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java index 5eac96a113f76..e51ab9c8bad1d 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java @@ -234,7 +234,7 @@ public void testPartitionClientManagerFailureSkipsTabletFallback() { Assert.assertEquals(QueryState.FAILED, stateMachine.getState()); Assert.assertTrue(stateMachine.getFailureMessage().contains("partition-failed.tsfile")); - Assert.assertTrue(stateMachine.getFailureMessage().contains("RPC transport failure")); + Assert.assertTrue(stateMachine.getFailureMessage().contains("uncertain LOAD outcome")); Mockito.verify(partitionFetcher) .getOrCreateDataPartition(Mockito.anyList(), Mockito.anyString()); } diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java index d86b9a6817275..e0781379f734a 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java @@ -357,6 +357,7 @@ public void testPrepareFailureOfTheSecondRegionRollsBackEveryRegion() throws Exc assertFalse(prepareAndCommit(strategy)); assertEquals(Arrays.asList("PREPARE@1", "PREPARE@2", "ABORT@1", "ABORT@2"), submitted); + assertFalse(strategy.shouldSkipTabletFallback()); } @Test @@ -496,5 +497,6 @@ public void testAbortIsRetriedOnFailure() throws Exception { Arrays.asList( "PREPARE@1", "ABORT@1", "ABORT@1", "ABORT@1", "ABORT@2", "ABORT@2", "ABORT@2"), submitted); + assertTrue(strategy.shouldSkipTabletFallback()); } } From 95e6f3e4db1caffa9926aeac8e2c42a73fb37ea0 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Fri, 27 Nov 2026 18:59:00 +0800 Subject: [PATCH 4/9] Allow more time for DataNode restart log --- .../iotdb/relational/it/schema/IoTDBTableMetaLeaseIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableMetaLeaseIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableMetaLeaseIT.java index 8fb421490f4d4..41c02bde21569 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableMetaLeaseIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableMetaLeaseIT.java @@ -71,7 +71,7 @@ public void testDnRestartLogsFenceThreshold() throws Exception { dataNodeWrapper.clearLogContent(); EnvFactory.getEnv().startDataNode(0); Awaitility.await() - .atMost(10, TimeUnit.SECONDS) + .atMost(30, TimeUnit.SECONDS) .pollInterval(1, TimeUnit.SECONDS) .untilAsserted( () -> From e53128decf13987da58fc42c875578388bb9fbb8 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Fri, 27 Nov 2026 19:30:04 +0800 Subject: [PATCH 5/9] Fix LOAD fallback after confirmed rollback --- .../scheduler/load/LoadTsFileScheduler.java | 3 +- .../load/TwoPhaseConsensusLoadStrategy.java | 3 ++ .../load/LoadTsFileSchedulerTest.java | 4 +- ...woPhaseConsensusLoadStrategyAbortTest.java | 44 +++++++++++++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java index 57fb3689080e5..355f201668439 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java @@ -464,8 +464,7 @@ private boolean processSingleNode( return true; } catch (final Exception e) { - if (LoadConsensusSubmitter.isPotentiallyUnstableRpcFailure(e) - || (strategy != null && strategy.shouldSkipTabletFallback())) { + if (strategy != null && strategy.shouldSkipTabletFallback()) { tabletFallbackBlockedNodeIndexes.add(index); } LOGGER.warn(DataNodeQueryMessages.LOADTSFILESCHEDULER_LOADS_TSFILE_ERROR, filePath, e); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java index f642eaa19ab15..fc1f35db6a652 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java @@ -455,6 +455,9 @@ private boolean abortRegions() { unresolvedLoadTransaction = true; } } + if (allAborted) { + rpcTransportFailure = false; + } return allAborted; } diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java index e51ab9c8bad1d..192213e3571d0 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java @@ -185,7 +185,7 @@ public void testGetPartitionQueryDatabaseForTableModelLoad() { } @Test - public void testPartitionClientManagerFailureSkipsTabletFallback() { + public void testPartitionClientManagerFailureAllowsTabletFallback() { final LoadSingleTsFileNode node = mock(LoadSingleTsFileNode.class); final TsFileResource tsFileResource = mock(TsFileResource.class); Mockito.when(node.getTsFileResource()).thenReturn(tsFileResource); @@ -234,7 +234,7 @@ public void testPartitionClientManagerFailureSkipsTabletFallback() { Assert.assertEquals(QueryState.FAILED, stateMachine.getState()); Assert.assertTrue(stateMachine.getFailureMessage().contains("partition-failed.tsfile")); - Assert.assertTrue(stateMachine.getFailureMessage().contains("uncertain LOAD outcome")); + Assert.assertFalse(stateMachine.getFailureMessage().contains("uncertain LOAD outcome")); Mockito.verify(partitionFetcher) .getOrCreateDataPartition(Mockito.anyList(), Mockito.anyString()); } diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java index e0781379f734a..af365d8c9196f 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java @@ -96,6 +96,50 @@ public void testExhaustedTransportRetriesRemainClassified() throws Exception { verify(submitter, times(3)).submit(any(), any()); } + @Test + public void testSuccessfulPreCommitAbortAllowsTabletFallbackAfterTransportRetry() + throws Exception { + final List submitted = new ArrayList<>(); + final boolean[] lastSubmissionWasRpcTransportFailure = {false}; + final int[] pieceSubmissionAttempts = {0}; + final LoadConsensusSubmitter submitter = mock(LoadConsensusSubmitter.class); + when(submitter.submit(any(), any())) + .thenAnswer( + invocation -> { + final TRegionReplicaSet replicaSet = invocation.getArgument(0); + final LoadTsFileConsensusNode node = invocation.getArgument(1); + submitted.add(node.getOp().name() + "@" + replicaSet.getRegionId().getId()); + if (node.getOp() == LoadTsFileConsensusOp.PIECE + && pieceSubmissionAttempts[0]++ == 0) { + lastSubmissionWasRpcTransportFailure[0] = true; + return RpcUtils.getStatus(TSStatusCode.DISPATCH_ERROR); + } + lastSubmissionWasRpcTransportFailure[0] = false; + if (node.getOp() == LoadTsFileConsensusOp.PREPARE + && replicaSet.getRegionId().equals(REGION_1)) { + return RpcUtils.getStatus(TSStatusCode.LOAD_FILE_ERROR); + } + return RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS); + }); + when(submitter.isLastSubmissionRpcTransportFailure()) + .thenAnswer(invocation -> lastSubmissionWasRpcTransportFailure[0]); + when(submitter.resolveRoute(any(), any(Integer.class))) + .thenAnswer(invocation -> currentRoute(invocation.getArgument(0))); + final TwoPhaseConsensusLoadStrategy strategy = + strategy( + submitter, + new LinkedHashSet<>(Collections.singletonList(currentRoute(REGION_1))), + loadIds(), + pieceCounts()); + + assertEquals(TSStatusCode.SUCCESS_STATUS, submitPiece(strategy, REGION_1)); + assertTrue(strategy.shouldSkipTabletFallback()); + assertFalse(prepareAndCommit(strategy)); + + assertEquals(Arrays.asList("PIECE@1", "PIECE@1", "PREPARE@1", "ABORT@1"), submitted); + assertFalse(strategy.shouldSkipTabletFallback()); + } + /** * Fails the given operation for the given region with a permanent error, accepts the rest. The * route of a region stays resolvable, so a command that is retried is retried on the route the From 1255cf3cf92abfde963de766328be902f629f785 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Fri, 27 Nov 2026 19:17:15 +0800 Subject: [PATCH 6/9] Fix DataNode test failures on Java 17 --- .github/workflows/unit-test.yml | 4 ++-- .../plan/scheduler/load/LoadFallbackHandlerTest.java | 8 +++++++- pom.xml | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 64a20a1f9a25a..cff0fe3c94c4f 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -70,14 +70,14 @@ jobs: - name: Test Datanode Module with Maven shell: bash if: ${{ matrix.it_task == 'datanode'}} - # forkCount=4 runs up to 4 surefire JVMs in parallel. reuseForks=false + # forkCount=2 runs up to 2 surefire JVMs in parallel. reuseForks=false # is left on (set in iotdb-core/datanode/pom.xml) so each test class # still gets a fresh JVM — only cross-fork parallelism changes. # The pom already wires ...fork_${surefire.forkNumber} # for filesystem isolation; datanode UTs do no socket binding (grep'd: # zero ServerSocket / bind() / TServer.serve() calls in tests), so # cross-fork resource conflicts are not a concern. - run: mvn clean integration-test -Dtest.port.closed=true -pl iotdb-core/datanode -am -DskipTests -Diotdb.test.only=true -DforkCount=4 + run: mvn clean integration-test -Dtest.port.closed=true -pl iotdb-core/datanode -am -DskipTests -Diotdb.test.only=true -DforkCount=2 - name: Test Other Modules with Maven shell: bash if: ${{ matrix.it_task == 'others'}} diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java index 8e2e0ef8f574f..ac6dcff72ba47 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java @@ -67,7 +67,13 @@ import static org.mockito.Mockito.when; @RunWith(PowerMockRunner.class) -@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) +@PowerMockIgnore({ + "com.sun.org.apache.xerces.*", + "javax.xml.*", + "org.xml.*", + "javax.management.*", + "java.util.stream.*" +}) @PrepareForTest(LoadFallbackHandler.class) public class LoadFallbackHandlerTest { diff --git a/pom.xml b/pom.xml index 3b8799b4f21b3..8f0ca00a9fb90 100644 --- a/pom.xml +++ b/pom.xml @@ -1408,6 +1408,7 @@ --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED + --add-opens=java.base/java.util.stream=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/java.nio.file=ALL-UNNAMED --add-opens=java.base/java.nio.channels=ALL-UNNAMED From 2c6172fb4aa259e59ac355689a30653c14e093d8 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Mon, 30 Nov 2026 11:48:53 +0800 Subject: [PATCH 7/9] Block fallback after unacknowledged LOAD commit --- .../plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java | 2 +- .../scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java index fc1f35db6a652..e1f910a534fe4 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategy.java @@ -563,6 +563,7 @@ private boolean commitAllRegions( * that did commit answers it with success as well, see {@code LoadTsFileManager#deleteAll}. */ private void resolveTheCommitOutcomeOf(final TConsensusGroupId regionId, final String loadId) { + unresolvedLoadTransaction = true; final LoadTsFileConsensusNode abort = LoadTsFileConsensusNode.abort( new PlanNodeId("load-abort-unresolved-commit-" + loadId), @@ -571,7 +572,6 @@ private void resolveTheCommitOutcomeOf(final TConsensusGroupId regionId, final S regionExpectedDataEnd.getOrDefault(regionId, Collections.emptyMap())); final TSStatus abortStatus = submitTerminalCommandWithRetry(regionId, abort); if (abortStatus.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { - unresolvedLoadTransaction = true; LOGGER.warn( DataNodeQueryMessages .LOG_THE_COMMIT_OUTCOME_OF_LOAD_TASK_ARG_IN_REGION_ARG_COULD_NOT_BE_RESOLVED_ARG_89B6F261, diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java index af365d8c9196f..4b8ab6916ae7c 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/TwoPhaseConsensusLoadStrategyAbortTest.java @@ -458,6 +458,7 @@ public void testCommitRejectionIsResolvedWithTheTerminalAbort() throws Exception pieceCounts()); assertFalse(prepareAndCommit(strategy)); + assertTrue(strategy.shouldSkipTabletFallback()); assertEquals( Arrays.asList("PREPARE@1", "PREPARE@2", "COMMIT@1", "COMMIT@2", "ABORT@2"), submitted); } From 18771a022f58cb412439e658d665ea797128973b Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Wed, 2 Dec 2026 15:40:09 +0800 Subject: [PATCH 8/9] Restore datanode unit test fork count --- .github/workflows/unit-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index cff0fe3c94c4f..64a20a1f9a25a 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -70,14 +70,14 @@ jobs: - name: Test Datanode Module with Maven shell: bash if: ${{ matrix.it_task == 'datanode'}} - # forkCount=2 runs up to 2 surefire JVMs in parallel. reuseForks=false + # forkCount=4 runs up to 4 surefire JVMs in parallel. reuseForks=false # is left on (set in iotdb-core/datanode/pom.xml) so each test class # still gets a fresh JVM — only cross-fork parallelism changes. # The pom already wires ...fork_${surefire.forkNumber} # for filesystem isolation; datanode UTs do no socket binding (grep'd: # zero ServerSocket / bind() / TServer.serve() calls in tests), so # cross-fork resource conflicts are not a concern. - run: mvn clean integration-test -Dtest.port.closed=true -pl iotdb-core/datanode -am -DskipTests -Diotdb.test.only=true -DforkCount=2 + run: mvn clean integration-test -Dtest.port.closed=true -pl iotdb-core/datanode -am -DskipTests -Diotdb.test.only=true -DforkCount=4 - name: Test Other Modules with Maven shell: bash if: ${{ matrix.it_task == 'others'}} From f02943c67cd27b312bb43fc0110c8b7b9b6f4a81 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Wed, 2 Dec 2026 17:54:21 +0800 Subject: [PATCH 9/9] Test LOAD fallback suppression paths --- .../scheduler/load/LoadFallbackHandler.java | 2 +- .../scheduler/load/LoadTsFileScheduler.java | 2 +- .../load/LoadFallbackHandlerTest.java | 56 ++++++++++++++++-- .../load/LoadTsFileSchedulerTest.java | 58 +++++++++++++++++++ 4 files changed, 112 insertions(+), 6 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java index eaa7f0a00a299..e51469c7bdfae 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandler.java @@ -116,7 +116,7 @@ public void convertFailedTsFilesToTablets() { } final String initialFailedFiles = getFailedFilePathsString(); - if (initialFailedFiles != null && !initialFailedFiles.isEmpty()) { + if (!initialFailedFiles.isEmpty()) { LOGGER.info( DataNodeQueryMessages .LOAD_TSFILE_S_FAILED_WILL_TRY_TO_CONVERT_TO_TABLETS_AND_INSERT_FAILED_TSFILES_ARG, diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java index 355f201668439..82f0d4192511a 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java @@ -480,7 +480,7 @@ private boolean processSingleNode( * Resolves the load strategy: LocalLoadStrategy for local non-decoded loads, or * TwoPhaseConsensusLoadStrategy for distributed decoded partition loads. */ - private TsFileLoadStrategy resolveStrategy(final LoadSingleTsFileNode node, final String userName) + TsFileLoadStrategy resolveStrategy(final LoadSingleTsFileNode node, final String userName) throws Exception { if (EncryptDBUtils.requiresFileRewrite()) { return new TabletRewriteLoadStrategy(queryContext, isGeneratedByPipe); diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java index ac6dcff72ba47..1f619cfafb06b 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadFallbackHandlerTest.java @@ -39,6 +39,10 @@ import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; import org.apache.ratis.thirdparty.com.google.common.util.concurrent.MoreExecutors; import org.junit.Assert; import org.junit.Before; @@ -51,6 +55,7 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import org.slf4j.LoggerFactory; import java.io.File; import java.util.ArrayList; @@ -83,10 +88,6 @@ public class LoadFallbackHandlerTest { @Before public void setUp() throws Exception { - // Progress-log formatting is unrelated to conversion results. Avoid instrumenting JDK Stream - // internals through this helper when running PowerMock on Java 17. - PowerMockito.suppress( - PowerMockito.method(LoadFallbackHandler.class, "getFailedFilePathsString")); converter = mock(LoadTsFileDataTypeConverter.class); when(converter.isSuccessful(any())).thenCallRealMethod(); PowerMockito.whenNew(LoadTsFileDataTypeConverter.class) @@ -180,6 +181,53 @@ public void testUncertainLoadOutcomeSkipsTabletFallback() throws Exception { verify(converter, never()).convertForTableModel(any()); } + @Test + public void testBlockedFilesAreExcludedFromFallbackInfoLog() throws Exception { + final String fallbackFilePath = "fallback.tsfile"; + final String blockedFilePath = "uncertain.tsfile"; + final List nodes = + Arrays.asList(newNode(fallbackFilePath, false), newNode(blockedFilePath, false)); + when(converter.convertForTreeModel(any())).thenReturn(Optional.of(RpcUtils.SUCCESS_STATUS)); + final List failedIndexes = new ArrayList<>(Arrays.asList(0, 1)); + final QueryStateMachine stateMachine = newStateMachine(); + final Logger logger = (Logger) LoggerFactory.getLogger(LoadFallbackHandler.class); + final Level originalLogLevel = logger.getLevel(); + final ListAppender appender = new ListAppender<>(); + logger.setLevel(Level.INFO); + appender.start(); + logger.addAppender(appender); + + try { + new LoadFallbackHandler( + mock(MPPQueryContext.class), + false, + nodes, + failedIndexes, + Collections.singleton(1), + stateMachine) + .convertFailedTsFilesToTablets(); + } finally { + logger.detachAppender(appender); + appender.stop(); + logger.setLevel(originalLogLevel); + } + + final ILoggingEvent fallbackLog = + appender.list.stream() + .filter(event -> event.getLevel().equals(Level.INFO)) + .filter( + event -> + event + .getMessage() + .equals( + DataNodeQueryMessages + .LOAD_TSFILE_S_FAILED_WILL_TRY_TO_CONVERT_TO_TABLETS_AND_INSERT_FAILED_TSFILES_ARG)) + .findFirst() + .orElseThrow(AssertionError::new); + Assert.assertTrue(fallbackLog.getFormattedMessage().contains(fallbackFilePath)); + Assert.assertFalse(fallbackLog.getFormattedMessage().contains(blockedFilePath)); + } + @Test public void testTableFallbackPreservesRequestSchemaCreationSetting() throws Exception { assertTableConversionPreservesRequestSchemaCreationSetting(false); diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java index 192213e3571d0..8180064f20258 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileSchedulerTest.java @@ -239,6 +239,64 @@ public void testPartitionClientManagerFailureAllowsTabletFallback() { .getOrCreateDataPartition(Mockito.anyList(), Mockito.anyString()); } + @Test + public void testStrategyFailureBlocksTabletFallback() throws Exception { + assertTabletFallbackBlocked(false, "load_strategy_failure"); + } + + @Test + public void testStrategyExceptionBlocksTabletFallback() throws Exception { + assertTabletFallbackBlocked(true, "load_strategy_exception"); + } + + private void assertTabletFallbackBlocked(final boolean executionThrows, final String queryId) + throws Exception { + final LoadSingleTsFileNode node = mock(LoadSingleTsFileNode.class); + final TsFileResource tsFileResource = mock(TsFileResource.class); + Mockito.when(node.getTsFileResource()).thenReturn(tsFileResource); + Mockito.when(tsFileResource.getTsFilePath()).thenReturn("fallback-blocked.tsfile"); + Mockito.when(node.isTsFileEmpty()).thenReturn(false); + + final FragmentInstance instance = Mockito.mock(FragmentInstance.class); + final PlanFragment fragment = Mockito.mock(PlanFragment.class); + Mockito.when(instance.getFragment()).thenReturn(fragment); + Mockito.when(fragment.getPlanNodeTree()).thenReturn(node); + Mockito.when(distributedQueryPlan.getInstances()) + .thenReturn(Collections.singletonList(instance)); + + final QueryStateMachine stateMachine = newStateMachine(queryId); + final MPPQueryContext queryContext = mock(MPPQueryContext.class); + final SessionInfo sessionInfo = mock(SessionInfo.class); + Mockito.when(queryContext.getSession()).thenReturn(sessionInfo); + Mockito.when(sessionInfo.getUserName()).thenReturn("root"); + final TsFileLoadStrategy strategy = mock(TsFileLoadStrategy.class); + if (executionThrows) { + Mockito.when(strategy.execute(node)).thenThrow(new RuntimeException("strategy failed")); + } else { + Mockito.when(strategy.execute(node)).thenReturn(false); + } + Mockito.when(strategy.shouldSkipTabletFallback()).thenReturn(true); + + final LoadTsFileScheduler scheduler = + spy( + new LoadTsFileScheduler( + distributedQueryPlan, + queryContext, + stateMachine, + mock(IClientManager.class), + mock(IPartitionFetcher.class), + false)); + Mockito.doReturn(strategy).when(scheduler).resolveStrategy(node, "root"); + + scheduler.start(); + + Assert.assertEquals(QueryState.FAILED, stateMachine.getState()); + Assert.assertTrue(stateMachine.getFailureMessage().contains("fallback-blocked.tsfile")); + Assert.assertTrue(stateMachine.getFailureMessage().contains("uncertain LOAD outcome")); + Mockito.verify(strategy).execute(node); + Mockito.verify(strategy).shouldSkipTabletFallback(); + } + @Test public void testBuildRetryTreeLoadStatementUpdatesDatabaseLevel() throws Exception { final LoadFallbackHandler fallbackHandler =