This is an automated email from the ASF dual-hosted git repository.
jt2594838 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 7b0cce43162 Avoid tablet fallback after uncertain LOAD RPC failures
(#19427)
7b0cce43162 is described below
commit 7b0cce43162e84bedfff37e8597fef2a8eeab0f0
Author: Caideyipi <[email protected]>
AuthorDate: Wed Dec 2 22:02:04 2026 +0800
Avoid tablet fallback after uncertain LOAD RPC failures (#19427)
* Retry LOAD RPC transport failures safely
* Clean up LOAD fallback control flow
* Fix LOAD retry and fallback safety
* Allow more time for DataNode restart log
* Fix LOAD fallback after confirmed rollback
* Fix DataNode test failures on Java 17
* Block fallback after unacknowledged LOAD commit
* Restore datanode unit test fork count
* Test LOAD fallback suppression paths
---
.../it/schema/IoTDBTableMetaLeaseIT.java | 2 +-
.../iotdb/db/i18n/DataNodeQueryMessages.java | 5 +
.../iotdb/db/i18n/DataNodeQueryMessages.java | 5 +
.../plan/analyze/ClusterPartitionFetcher.java | 3 +-
.../scheduler/load/LoadConsensusSubmitter.java | 29 +++++
.../plan/scheduler/load/LoadFallbackHandler.java | 118 +++++++++++------
.../plan/scheduler/load/LoadTsFileScheduler.java | 19 ++-
.../plan/scheduler/load/TsFileLoadStrategy.java | 10 ++
.../load/TwoPhaseConsensusLoadStrategy.java | 23 ++++
.../scheduler/load/LoadConsensusSubmitterTest.java | 140 ++++++++++++++++++++-
.../scheduler/load/LoadFallbackHandlerTest.java | 93 +++++++++++++-
.../scheduler/load/LoadTsFileSchedulerTest.java | 126 +++++++++++++++++++
.../TwoPhaseConsensusLoadStrategyAbortTest.java | 78 ++++++++++++
pom.xml | 1 +
14 files changed, 600 insertions(+), 52 deletions(-)
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 8fb421490f4..41c02bde215 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 class IoTDBTableMetaLeaseIT {
dataNodeWrapper.clearLogContent();
EnvFactory.getEnv().startDataNode(0);
Awaitility.await()
- .atMost(10, TimeUnit.SECONDS)
+ .atMost(30, TimeUnit.SECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.untilAsserted(
() ->
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 149e2a90460..b81f80cc525 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_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 =
"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 efedcfb81ed..ce300fe8a2e 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_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 =
"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 824e3a4fbe0..81c3145c95d 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 class ClusterPartitionFetcher implements
IPartitionFetcher {
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 8c91027bdb4..3a5e0e8d4ca 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.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.consensus.ConsensusFactory;
@@ -45,12 +46,15 @@ import
org.apache.iotdb.mpp.rpc.thrift.TSendSinglePlanNodeResp;
import org.apache.iotdb.rpc.RpcUtils;
import org.apache.iotdb.rpc.TSStatusCode;
+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;
+import java.util.concurrent.TimeoutException;
/**
* Submits LOAD consensus lifecycle commands (PIECE, PREPARE, COMMIT, ABORT)
to target DataRegions
@@ -64,6 +68,7 @@ public class LoadConsensusSubmitter {
private final TEndPoint localEndPoint;
private final IClientManager<TEndPoint, SyncDataNodeInternalServiceClient>
clientManager;
+ private boolean lastSubmissionRpcTransportFailure;
public LoadConsensusSubmitter(
final IClientManager<TEndPoint, SyncDataNodeInternalServiceClient>
clientManager) {
@@ -125,6 +130,7 @@ public class LoadConsensusSubmitter {
/** 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 +163,11 @@ public class LoadConsensusSubmitter {
: 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 +254,7 @@ public class LoadConsensusSubmitter {
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 +268,23 @@ public class LoadConsensusSubmitter {
}
}
+ private static boolean isRpcTransportException(Throwable error) {
+ return isPotentiallyUnstableRpcFailure(error);
+ }
+
+ static boolean isPotentiallyUnstableRpcFailure(Throwable error) {
+ while (error != null) {
+ if (error instanceof ClientManagerException
+ || error instanceof TTransportException
+ || error instanceof TimeoutException
+ || error instanceof SocketTimeoutException) {
+ 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 52049414517..e51469c7bdf 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.Iterator;
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<LoadSingleTsFileNode> tsFileNodeList;
private final List<Integer> failedTsFileNodeIndexes;
+ private final Set<Integer> tabletFallbackBlockedNodeIndexes;
private final QueryStateMachine stateMachine;
public LoadFallbackHandler(
@@ -68,6 +70,22 @@ public class LoadFallbackHandler {
final List<LoadSingleTsFileNode> tsFileNodeList,
final List<Integer> failedTsFileNodeIndexes,
final QueryStateMachine stateMachine) {
+ this(
+ queryContext,
+ isGeneratedByPipe,
+ tsFileNodeList,
+ failedTsFileNodeIndexes,
+ Collections.emptySet(),
+ stateMachine);
+ }
+
+ public LoadFallbackHandler(
+ final MPPQueryContext queryContext,
+ final boolean isGeneratedByPipe,
+ final List<LoadSingleTsFileNode> tsFileNodeList,
+ final List<Integer> failedTsFileNodeIndexes,
+ final Set<Integer> tabletFallbackBlockedNodeIndexes,
+ final QueryStateMachine stateMachine) {
this.queryContext =
Objects.requireNonNull(
queryContext,
DataNodeQueryMessages.EXCEPTION_QUERYCONTEXT_CANNOT_BE_NULL_C2B25B22);
@@ -79,6 +97,8 @@ public class LoadFallbackHandler {
Objects.requireNonNull(
failedTsFileNodeIndexes,
DataNodeQueryMessages.EXCEPTION_FAILEDTSFILENODEINDEXES_CANNOT_BE_NULL_D1C0E7C6);
+ this.tabletFallbackBlockedNodeIndexes =
+ Objects.requireNonNull(tabletFallbackBlockedNodeIndexes);
this.stateMachine =
Objects.requireNonNull(
stateMachine,
DataNodeQueryMessages.EXCEPTION_STATEMACHINE_CANNOT_BE_NULL_4AF40790);
@@ -96,10 +116,12 @@ public class LoadFallbackHandler {
}
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.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,48 +155,65 @@ public class LoadFallbackHandler {
final LoadSingleTsFileNode failedNode = tsFileNodeList.get(nodeIndex);
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 =
- 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) {
+ if (tabletFallbackBlockedNodeIndexes.contains(nodeIndex)) {
final String message =
String.format(
DataNodeQueryMessages
-
.EXCEPTION_FAILED_TO_CONVERT_TSFILE_ARG_TO_TABLETS_ARG_96358FDD,
- filePath,
- e);
+
.EXCEPTION_TSFILE_ARG_HAS_AN_UNCERTAIN_LOAD_OUTCOME_RETRY_WAS_SKIPPED_70149528,
+ filePath);
failureDetails.add(message);
- LOGGER.warn(message, e);
+ LOGGER.warn(message);
+ } else {
+ convertFailedTsFileToTablets(converter, failedNode, iterator,
failureDetails);
}
}
resolveFinalState(failureDetails);
}
+ private void convertFailedTsFileToTablets(
+ final LoadTsFileDataTypeConverter converter,
+ final LoadSingleTsFileNode failedNode,
+ final Iterator<Integer> iterator,
+ final List<String> 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 =
+ 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) {
+ 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);
+ }
+ }
+
static TSStatus convertTsFileToTablets(
final LoadTsFileDataTypeConverter converter,
final LoadSingleTsFileNode node,
@@ -233,8 +272,10 @@ public class LoadFallbackHandler {
final String message =
String.format(
- DataNodeQueryMessages
-
.EXCEPTION_FAILED_TO_LOAD_TSFILES_AFTER_TABLET_CONVERSION_DETAILS_ARG_53647EC5,
+
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,
String.join("; ", failureDetails));
LOGGER.warn(message);
stateMachine.transitionToFailed(new LoadFileException(message));
@@ -247,6 +288,7 @@ public class LoadFallbackHandler {
private String getFailedFilePathsString() {
return failedTsFileNodeIndexes.stream()
.filter(index -> index >= 0 && index < tsFileNodeList.size())
+ .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 24c78410dd5..82f0d419251 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 org.slf4j.LoggerFactory;
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 class LoadTsFileScheduler implements IScheduler {
}
stateMachine.transitionToRunning();
boolean allFilesSucceeded = true;
+ final Set<Integer> tabletFallbackBlockedNodeIndexes = new HashSet<>();
final int totalFiles = tsFileNodeList.size();
for (int i = 0; i < totalFiles; ++i) {
@@ -374,7 +376,7 @@ public class LoadTsFileScheduler implements IScheduler {
partitionFetcher.setDatabase(getPartitionQueryDatabase(node,
isGeneratedByPipe));
- if (!processSingleNode(node, i, totalFiles, userName)) {
+ if (!processSingleNode(node, i, totalFiles, userName,
tabletFallbackBlockedNodeIndexes)) {
allFilesSucceeded = false;
failedTsFileNodeIndexes.add(i);
continue;
@@ -392,6 +394,7 @@ public class LoadTsFileScheduler implements IScheduler {
isGeneratedByPipe,
tsFileNodeList,
failedTsFileNodeIndexes,
+ tabletFallbackBlockedNodeIndexes,
stateMachine)
.convertFailedTsFilesToTablets();
}
@@ -417,10 +420,12 @@ public class LoadTsFileScheduler implements IScheduler {
final LoadSingleTsFileNode node,
final int index,
final int totalFiles,
- final String userName) {
+ final String userName,
+ final Set<Integer> tabletFallbackBlockedNodeIndexes) {
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 @@ public class LoadTsFileScheduler implements IScheduler {
return true;
}
- final TsFileLoadStrategy strategy = resolveStrategy(node, userName);
+ strategy = resolveStrategy(node, userName);
final boolean loadSuccess = strategy.execute(node);
+ if (!loadSuccess && strategy.shouldSkipTabletFallback()) {
+ tabletFallbackBlockedNodeIndexes.add(index);
+ }
if (isRegionMigrating(startTimeMs)) {
LOGGER.warn(
@@ -456,6 +464,9 @@ public class LoadTsFileScheduler implements IScheduler {
return true;
} catch (final Exception e) {
+ if (strategy != null && strategy.shouldSkipTabletFallback()) {
+ tabletFallbackBlockedNodeIndexes.add(index);
+ }
LOGGER.warn(DataNodeQueryMessages.LOADTSFILESCHEDULER_LOADS_TSFILE_ERROR,
filePath, e);
return false;
} finally {
@@ -469,7 +480,7 @@ public class LoadTsFileScheduler implements IScheduler {
* 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/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 97b89f8208a..fe3603121d3 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,14 @@ 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;
+ }
+
+ /** 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 aa0ec86cddd..e1f910a534f 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,8 @@ public class TwoPhaseConsensusLoadStrategy implements
TsFileLoadStrategy {
private final LoadTsFileDataCacheMemoryBlock block;
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;
@@ -145,6 +147,8 @@ public class TwoPhaseConsensusLoadStrategy implements
TsFileLoadStrategy {
@Override
public boolean execute(LoadSingleTsFileNode node) {
this.currentNode = node;
+ rpcTransportFailure = false;
+ unresolvedLoadTransaction = false;
dispatcher.setUuid(UUID.randomUUID().toString());
regionRoutes.clear();
regionLoadIds.clear();
@@ -174,6 +178,16 @@ public class TwoPhaseConsensusLoadStrategy implements
TsFileLoadStrategy {
return isFirstPhaseSuccess && isSecondPhaseSuccess;
}
+ @Override
+ public boolean hasRpcTransportFailure() {
+ return rpcTransportFailure;
+ }
+
+ @Override
+ public boolean shouldSkipTabletFallback() {
+ return rpcTransportFailure || unresolvedLoadTransaction;
+ }
+
private boolean firstPhase(LoadSingleTsFileNode node) {
final TsFileSplitConsumer pipeline =
new TsFileSplitConsumer(
@@ -187,6 +201,7 @@ public class TwoPhaseConsensusLoadStrategy implements
TsFileLoadStrategy {
.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 +209,7 @@ public class TwoPhaseConsensusLoadStrategy implements
TsFileLoadStrategy {
e);
return false;
} catch (Exception e) {
+ rpcTransportFailure |=
LoadConsensusSubmitter.isPotentiallyUnstableRpcFailure(e);
LOGGER.warn(
String.format(
DataNodeQueryMessages.PARSE_OR_SEND_TSFILE_S_ERROR,
@@ -250,6 +266,7 @@ public class TwoPhaseConsensusLoadStrategy implements
TsFileLoadStrategy {
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 +312,7 @@ public class TwoPhaseConsensusLoadStrategy implements
TsFileLoadStrategy {
break;
}
status = consensusSubmitter.submit(replicaSet, node);
+ rpcTransportFailure |=
consensusSubmitter.isLastSubmissionRpcTransportFailure();
}
return status;
}
@@ -434,8 +452,12 @@ public class TwoPhaseConsensusLoadStrategy implements
TsFileLoadStrategy {
TSStatusCode.representOf(status.getCode()).name(),
status.getMessage());
allAborted = false;
+ unresolvedLoadTransaction = true;
}
}
+ if (allAborted) {
+ rpcTransportFailure = false;
+ }
return allAborted;
}
@@ -541,6 +563,7 @@ public class TwoPhaseConsensusLoadStrategy implements
TsFileLoadStrategy {
* 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),
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 b224b873822..62c6670eeab 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.TConsensusGroupType;
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,14 @@ import org.apache.iotdb.db.conf.IoTDBDescriptor;
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.TApplicationException;
+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 +56,16 @@ import
org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
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;
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 +152,123 @@ public class LoadConsensusSubmitterTest {
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<TEndPoint, SyncDataNodeInternalServiceClient>
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 testGenericThriftFailureIsNotClassifiedAsTransportFailure()
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<TEndPoint, SyncDataNodeInternalServiceClient>
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());
+ assertFalse(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<TEndPoint, SyncDataNodeInternalServiceClient>
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 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
+ 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<TEndPoint, SyncDataNodeInternalServiceClient>
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 +349,13 @@ public class LoadConsensusSubmitterTest {
@SuppressWarnings("unchecked")
private static LoadConsensusSubmitter newSubmitter() {
- return new LoadConsensusSubmitter(
- (IClientManager<TEndPoint, SyncDataNodeInternalServiceClient>)
- Mockito.mock(IClientManager.class));
+ return new LoadConsensusSubmitter(newClientManager());
+ }
+
+ @SuppressWarnings("unchecked")
+ private static IClientManager<TEndPoint, SyncDataNodeInternalServiceClient>
newClientManager() {
+ return (IClientManager<TEndPoint, SyncDataNodeInternalServiceClient>)
+ 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 e72b1c66d38..1f619cfafb0 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.db.storageengine.load.metrics.LoadTsFileCostMetricsSet;
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.api.mockito.PowerMockito;
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;
@@ -62,11 +67,18 @@ import java.util.Optional;
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;
@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 {
@@ -76,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)
@@ -145,6 +153,81 @@ public class LoadFallbackHandlerTest {
Assert.assertTrue(failedIndexes.isEmpty());
}
+ @Test
+ public void testUncertainLoadOutcomeSkipsTabletFallback() throws Exception {
+ final LoadSingleTsFileNode node = newNode("uncertain.tsfile", false);
+ final List<Integer> 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()));
+ Assert.assertTrue(
+ stateMachine.getFailureStatus().getMessage().contains("uncertain LOAD
outcome"));
+ verify(converter, never()).convertForTreeModel(any());
+ verify(converter, never()).convertForTableModel(any());
+ }
+
+ @Test
+ public void testBlockedFilesAreExcludedFromFallbackInfoLog() throws
Exception {
+ final String fallbackFilePath = "fallback.tsfile";
+ final String blockedFilePath = "uncertain.tsfile";
+ final List<LoadSingleTsFileNode> nodes =
+ Arrays.asList(newNode(fallbackFilePath, false),
newNode(blockedFilePath, false));
+
when(converter.convertForTreeModel(any())).thenReturn(Optional.of(RpcUtils.SUCCESS_STATUS));
+ final List<Integer> 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<ILoggingEvent> 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 f576245056e..8180064f202 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.QueryState;
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.Constructor;
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,119 @@ public class LoadTsFileSchedulerTest {
Assert.assertEquals("test",
LoadTsFileScheduler.getPartitionQueryDatabase(node, false));
}
+ @Test
+ public void testPartitionClientManagerFailureAllowsTabletFallback() {
+ 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<Pair<IDeviceID, TTimePartitionSlot>>,
List<TRegionReplicaSet>>
+ 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.<DataPartitionQueryParam>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.assertFalse(stateMachine.getFailureMessage().contains("uncertain
LOAD outcome"));
+ Mockito.verify(partitionFetcher)
+ .getOrCreateDataPartition(Mockito.<DataPartitionQueryParam>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 =
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 2c855ec0314..4b8ab6916ae 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.TConsensusGroupType;
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.assertFalse;
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,78 @@ 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());
+ }
+
+ @Test
+ public void
testSuccessfulPreCommitAbortAllowsTabletFallbackAfterTransportRetry()
+ throws Exception {
+ final List<String> 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
@@ -326,6 +401,7 @@ public class TwoPhaseConsensusLoadStrategyAbortTest {
assertFalse(prepareAndCommit(strategy));
assertEquals(Arrays.asList("PREPARE@1", "PREPARE@2", "ABORT@1",
"ABORT@2"), submitted);
+ assertFalse(strategy.shouldSkipTabletFallback());
}
@Test
@@ -382,6 +458,7 @@ public class TwoPhaseConsensusLoadStrategyAbortTest {
pieceCounts());
assertFalse(prepareAndCommit(strategy));
+ assertTrue(strategy.shouldSkipTabletFallback());
assertEquals(
Arrays.asList("PREPARE@1", "PREPARE@2", "COMMIT@1", "COMMIT@2",
"ABORT@2"), submitted);
}
@@ -465,5 +542,6 @@ public class TwoPhaseConsensusLoadStrategyAbortTest {
Arrays.asList(
"PREPARE@1", "ABORT@1", "ABORT@1", "ABORT@1", "ABORT@2",
"ABORT@2", "ABORT@2"),
submitted);
+ assertTrue(strategy.shouldSkipTabletFallback());
}
}
diff --git a/pom.xml b/pom.xml
index 293049a47ff..b72f70763b8 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