Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,12 +46,15 @@
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
Expand All @@ -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) {
Expand Down Expand Up @@ -125,6 +130,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);
Expand Down Expand Up @@ -157,6 +163,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.
Expand Down Expand Up @@ -243,6 +254,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,
Expand All @@ -256,6 +268,23 @@ 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 TTransportException
|| error instanceof TimeoutException
|| error instanceof SocketTimeoutException) {
return true;
}
error = error.getCause();
}
return false;
}

private boolean isLocal(final TEndPoint endPoint) {
return localEndPoint.equals(endPoint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand All @@ -68,6 +70,22 @@ public 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);
Expand All @@ -79,6 +97,8 @@ public 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);
Expand All @@ -96,10 +116,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.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 {
Expand Down Expand Up @@ -133,48 +155,65 @@ private void convertAndRetry() {
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,
Expand Down Expand Up @@ -233,8 +272,10 @@ private void resolveFinalState(final List<String> failureDetails) {

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));
Expand All @@ -247,6 +288,7 @@ private void resolveFinalState(final List<String> failureDetails) {
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(", "));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -362,6 +363,7 @@ public void start() {
}
stateMachine.transitionToRunning();
boolean allFilesSucceeded = true;
final Set<Integer> tabletFallbackBlockedNodeIndexes = new HashSet<>();

final int totalFiles = tsFileNodeList.size();
for (int i = 0; i < totalFiles; ++i) {
Expand All @@ -374,7 +376,7 @@ public void start() {

partitionFetcher.setDatabase(getPartitionQueryDatabase(node, isGeneratedByPipe));

if (!processSingleNode(node, i, totalFiles, userName)) {
if (!processSingleNode(node, i, totalFiles, userName, tabletFallbackBlockedNodeIndexes)) {
allFilesSucceeded = false;
failedTsFileNodeIndexes.add(i);
continue;
Expand All @@ -392,6 +394,7 @@ public void start() {
isGeneratedByPipe,
tsFileNodeList,
failedTsFileNodeIndexes,
tabletFallbackBlockedNodeIndexes,
stateMachine)
.convertFailedTsFilesToTablets();
}
Expand All @@ -417,10 +420,12 @@ private boolean processSingleNode(
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)) {
Expand All @@ -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.shouldSkipTabletFallback()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/scheduler/load/LoadTsFileScheduler.java:447 — Fallback-suppression wiring in LoadTsFileScheduler has no regression test

Trigger: the new decision of the PR - recording the index from strategy.shouldSkipTabletFallback() (lines 447-449) and the catch branch (467-469). The only scheduler test (LoadTsFileSchedulerTest:188) covers the pre-dispatch partition failure where strategy == null, and the strategy/handler tests never go through the scheduler, so a regression (wrong index recorded, !loadSuccess flipped, catch branch dropped) passes every test.

Fix: Add a scheduler test where a stub strategy returns false with shouldSkipTabletFallback() true and assert the file is passed to LoadFallbackHandler as blocked and never converted to tablets.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added scheduler coverage with a stub strategy for both a false result and an exception while shouldSkipTabletFallback() is true. The tests assert the fallback handler reports the file as blocked instead of converting it to tablets. The focused scheduler and fallback test run passed (18 tests total).

tabletFallbackBlockedNodeIndexes.add(index);
}

if (isRegionMigrating(startTimeMs)) {
LOGGER.warn(
Expand All @@ -456,6 +464,9 @@ private boolean processSingleNode(

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 {
Expand All @@ -469,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);
Expand Down
Loading
Loading