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 @@ -3912,7 +3912,11 @@ public void setLoadDiskSelectStrategy(String loadDiskSelectStrategy) {
}

public String getLoadDiskSelectStrategyForIoTV2AndPipe() {
return loadDiskSelectStrategyForIoTV2AndPipe;
return LoadDiskSelectorType.INHERIT_LOAD
.getValue()
.equals(loadDiskSelectStrategyForIoTV2AndPipe)
? getLoadDiskSelectStrategy()
: loadDiskSelectStrategyForIoTV2AndPipe;
}

public void setLoadDiskSelectStrategyForIoTV2AndPipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import org.apache.iotdb.commons.pipe.sink.payload.thrift.request.PipeTransferFileSealReqV2;
import org.apache.iotdb.commons.pipe.sink.payload.thrift.request.PipeTransferSliceReq;
import org.apache.iotdb.commons.schema.column.ColumnHeaderConstant;
import org.apache.iotdb.commons.utils.FileUtils;
import org.apache.iotdb.commons.utils.RetryUtils;
import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema;
import org.apache.iotdb.db.auth.AuthorityChecker;
import org.apache.iotdb.db.conf.IoTDBConfig;
Expand Down Expand Up @@ -95,6 +93,7 @@
import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement;
import org.apache.iotdb.db.queryengine.plan.statement.crud.LoadTsFileStatement;
import org.apache.iotdb.db.queryengine.plan.statement.pipe.PipeEnrichedStatement;
import org.apache.iotdb.db.storageengine.load.active.ActiveLoadUtil;
import org.apache.iotdb.db.storageengine.rescon.disk.FolderManager;
import org.apache.iotdb.db.storageengine.rescon.disk.strategy.DirectoryStrategyType;
import org.apache.iotdb.db.tools.schema.SRStatementGenerator;
Expand All @@ -110,7 +109,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Paths;
Expand Down Expand Up @@ -567,35 +565,9 @@ protected TSStatus loadFileV2(

private TSStatus loadTsFileAsync(final String dataBaseName, final List<String> absolutePaths)
throws IOException {
final String loadActiveListeningPipeDir = IOTDB_CONFIG.getLoadActiveListeningPipeDir();
if (Objects.isNull(loadActiveListeningPipeDir)) {
if (!ActiveLoadUtil.loadFilesToActiveDir(dataBaseName, absolutePaths, true)) {
throw new PipeException("Load active listening pipe dir is not set.");
}

if (Objects.nonNull(dataBaseName)) {
final File targetDir = new File(loadActiveListeningPipeDir, dataBaseName);
return this.loadTsFileAsyncToTargetDir(targetDir, absolutePaths);
}

return loadTsFileAsyncToTargetDir(new File(loadActiveListeningPipeDir), absolutePaths);
}

private TSStatus loadTsFileAsyncToTargetDir(
final File targetDir, final List<String> absolutePaths) throws IOException {
for (final String absolutePath : absolutePaths) {
if (absolutePath == null) {
continue;
}
final File sourceFile = new File(absolutePath);
if (!Objects.equals(
targetDir.getAbsolutePath(), sourceFile.getParentFile().getAbsolutePath())) {
RetryUtils.retryOnException(
() -> {
FileUtils.moveFileWithMD5Check(sourceFile, targetDir);
return null;
});
}
}
return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.iotdb.common.rpc.thrift.TSStatus;
import org.apache.iotdb.commons.auth.AuthException;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.utils.RetryUtils;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.exception.load.LoadAnalyzeException;
import org.apache.iotdb.db.exception.load.LoadAnalyzeTypeMismatchException;
Expand All @@ -45,6 +44,7 @@
import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResourceStatus;
import org.apache.iotdb.db.storageengine.dataregion.utils.TsFileResourceUtils;
import org.apache.iotdb.db.storageengine.load.active.ActiveLoadUtil;
import org.apache.iotdb.db.storageengine.load.converter.LoadTsFileDataTypeConverter;
import org.apache.iotdb.db.storageengine.load.metrics.LoadTsFileCostMetricsSet;
import org.apache.iotdb.db.utils.TimestampPrecisionUtils;
Expand Down Expand Up @@ -75,8 +75,6 @@
import java.util.Objects;
import java.util.Optional;

import static org.apache.iotdb.commons.utils.FileUtils.copyFileWithMD5Check;
import static org.apache.iotdb.commons.utils.FileUtils.moveFileWithMD5Check;
import static org.apache.iotdb.db.queryengine.plan.execution.config.TableConfigTaskVisitor.DATABASE_NOT_SPECIFIED;
import static org.apache.iotdb.db.storageengine.load.metrics.LoadTsFileCostMetricsSet.ANALYSIS;
import static org.apache.iotdb.db.storageengine.load.metrics.LoadTsFileCostMetricsSet.ANALYSIS_ASYNC_MOVE;
Expand Down Expand Up @@ -276,83 +274,29 @@ private boolean checkBeforeAnalyzeFileByFile(IAnalysis analysis) {
private boolean doAsyncLoad(final IAnalysis analysis) {
final long startTime = System.nanoTime();
try {
final String[] loadActiveListeningDirs =
IoTDBDescriptor.getInstance().getConfig().getLoadActiveListeningDirs();
String targetFilePath = null;
for (int i = 0, size = loadActiveListeningDirs == null ? 0 : loadActiveListeningDirs.length;
i < size;
i++) {
if (loadActiveListeningDirs[i] != null) {
targetFilePath = loadActiveListeningDirs[i];
break;
}
}
if (targetFilePath == null) {
LOGGER.warn("Load active listening dir is not set. Will try sync load instead.");
return false;
final String databaseName;
if (Objects.nonNull(databaseForTableData)
|| (Objects.nonNull(context) && context.getDatabaseName().isPresent())) {
databaseName =
Objects.nonNull(databaseForTableData)
? databaseForTableData
: context.getDatabaseName().get();
} else {
databaseName = null;
}

try {
if (Objects.nonNull(databaseForTableData)
|| (Objects.nonNull(context) && context.getDatabaseName().isPresent())) {
loadTsFilesAsyncToTargetDir(
new File(
targetFilePath,
databaseForTableData =
Objects.nonNull(databaseForTableData)
? databaseForTableData
: context.getDatabaseName().get()),
tsFiles);
} else {
loadTsFilesAsyncToTargetDir(new File(targetFilePath), tsFiles);
}
} catch (Exception e) {
LOGGER.warn(
"Failed to async load tsfiles {} to target dir {}. Will try sync load instead.",
tsFiles,
targetFilePath,
e);
return false;
if (ActiveLoadUtil.loadTsFileAsyncToActiveDir(tsFiles, databaseName, isDeleteAfterLoad)) {
analysis.setFinishQueryAfterAnalyze(true);
setRealStatement(analysis);
return true;
}

analysis.setFinishQueryAfterAnalyze(true);
setRealStatement(analysis);
return true;
LOGGER.info("Async Load has failed, and is now trying to load sync");
return false;
} finally {
LoadTsFileCostMetricsSet.getInstance()
.recordPhaseTimeCost(ANALYSIS_ASYNC_MOVE, System.nanoTime() - startTime);
}
}

private void loadTsFilesAsyncToTargetDir(final File targetDir, final List<File> files)
throws IOException {
for (final File file : files) {
if (file == null) {
continue;
}

loadTsFileAsyncToTargetDir(targetDir, file);
loadTsFileAsyncToTargetDir(targetDir, new File(file.getAbsolutePath() + ".resource"));
loadTsFileAsyncToTargetDir(targetDir, new File(file.getAbsolutePath() + ".mods"));
}
}

private void loadTsFileAsyncToTargetDir(final File targetDir, final File file)
throws IOException {
if (!file.exists()) {
return;
}
RetryUtils.retryOnException(
() -> {
if (isDeleteAfterLoad) {
moveFileWithMD5Check(file, targetDir);
} else {
copyFileWithMD5Check(file, targetDir);
}
return null;
});
}

private boolean doAnalyzeFileByFile(IAnalysis analysis) {
// analyze tsfile metadata file by file
for (int i = 0, tsfileNum = tsFiles.size(); i < tsfileNum; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.iotdb.commons.cluster.NodeStatus;
import org.apache.iotdb.commons.concurrent.IoTDBThreadPoolFactory;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.conf.IoTDBConstant;
import org.apache.iotdb.commons.consensus.DataRegionId;
import org.apache.iotdb.commons.exception.MetadataException;
import org.apache.iotdb.commons.file.SystemFileFactory;
Expand Down Expand Up @@ -137,8 +138,6 @@
import org.apache.iotdb.db.storageengine.dataregion.wal.utils.listener.WALFlushListener;
import org.apache.iotdb.db.storageengine.dataregion.wal.utils.listener.WALRecoverListener;
import org.apache.iotdb.db.storageengine.load.disk.ILoadDiskSelector;
import org.apache.iotdb.db.storageengine.load.disk.InheritSystemMultiDisksStrategySelector;
import org.apache.iotdb.db.storageengine.load.disk.MinIOSelector;
import org.apache.iotdb.db.storageengine.load.limiter.LoadTsFileRateLimiter;
import org.apache.iotdb.db.storageengine.rescon.disk.TierManager;
import org.apache.iotdb.db.storageengine.rescon.memory.SystemInfo;
Expand Down Expand Up @@ -430,27 +429,30 @@ public DataRegion(String databaseName, String id) {
}

private void initDiskSelector() {
switch (ILoadDiskSelector.LoadDiskSelectorType.fromValue(config.getLoadDiskSelectStrategy())) {
case INHERIT_SYSTEM_MULTI_DISKS_SELECT_STRATEGY:
ordinaryLoadDiskSelector = new InheritSystemMultiDisksStrategySelector();
break;
case MIN_IO_FIRST:
default:
ordinaryLoadDiskSelector = new MinIOSelector();
}
final ILoadDiskSelector.DiskDirectorySelector selector =
(sourceDirectory, fileName, tierLevel) -> {
try {
return TierManager.getInstance()
.getFolderManager(tierLevel, false)
.getNextWithRetry(folder -> fsFactory.getFile(folder, fileName));
} catch (DiskSpaceInsufficientException e) {
throw e;
} catch (Exception e) {
throw new LoadFileException(
String.format("Storage allocation failed for %s (tier %d)", fileName, tierLevel),
e);
}
};

switch (ILoadDiskSelector.LoadDiskSelectorType.fromValue(
config.getLoadDiskSelectStrategyForIoTV2AndPipe())) {
case MIN_IO_FIRST:
pipeAndIoTV2LoadDiskSelector = new MinIOSelector();
break;
case INHERIT_SYSTEM_MULTI_DISKS_SELECT_STRATEGY:
pipeAndIoTV2LoadDiskSelector = new InheritSystemMultiDisksStrategySelector();
break;
case INHERIT_LOAD:
default:
pipeAndIoTV2LoadDiskSelector = ordinaryLoadDiskSelector;
}
final String[] dirs =
Arrays.stream(config.getTierDataDirs()[0])
.map(v -> fsFactory.getFile(v, IoTDBConstant.UNSEQUENCE_FOLDER_NAME).getPath())
.toArray(String[]::new);
ordinaryLoadDiskSelector =
ILoadDiskSelector.initDiskSelector(config.getLoadDiskSelectStrategy(), dirs, selector);
pipeAndIoTV2LoadDiskSelector =
ILoadDiskSelector.initDiskSelector(
config.getLoadDiskSelectStrategyForIoTV2AndPipe(), dirs, selector);
}

@Override
Expand Down Expand Up @@ -3274,22 +3276,20 @@ private boolean loadTsFileToUnSequence(
boolean isGeneratedByPipe)
throws LoadFileException, DiskSpaceInsufficientException {
final int targetTierLevel = 0;
final String fileName =
databaseName
+ File.separatorChar
+ dataRegionId
+ File.separatorChar
+ filePartitionId
+ File.separator
+ tsFileResource.getTsFile().getName();
final File targetFile =
(tsFileResource.isGeneratedByPipeConsensus() || tsFileResource.isGeneratedByPipe())
? pipeAndIoTV2LoadDiskSelector.getTargetFile(
tsFileToLoad,
databaseName,
dataRegionId,
filePartitionId,
tsFileResource.getTsFile().getName(),
targetTierLevel)
: ordinaryLoadDiskSelector.getTargetFile(
tsFileToLoad,
databaseName,
dataRegionId,
filePartitionId,
tsFileResource.getTsFile().getName(),
targetTierLevel);
? pipeAndIoTV2LoadDiskSelector.selectTargetDirectory(
tsFileToLoad.getParentFile(), fileName, true, targetTierLevel)
: ordinaryLoadDiskSelector.selectTargetDirectory(
tsFileToLoad.getParentFile(), fileName, true, targetTierLevel);

tsFileResource.setFile(targetFile);
if (tsFileManager.contains(tsFileResource, false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ private void hotReloadActiveLoadDirs() {

listeningDirsConfig.set(IOTDB_CONFIG.getLoadActiveListeningDirs());
listeningDirs.addAll(Arrays.asList(IOTDB_CONFIG.getLoadActiveListeningDirs()));
ActiveLoadUtil.updateLoadDiskSelector();
}
}
}
Expand Down
Loading
Loading