Skip to content

Commit 8a903c8

Browse files
luoluoyuyuJackieTien97
authored andcommitted
Load: Fix excessive GC caused by loading too many TsFiles at once (#16853)
* Fix excessive GC caused by loading too many TsFiles at once When loading multiple TsFiles, all file resources were loaded into memory simultaneously, causing excessive memory consumption and frequent GC pauses. This commit introduces batch execution for multi-file loading scenarios: 1. Split LoadTsFileStatement/LoadTsFile into sub-statements, each handling one TsFile, to avoid loading all file resources at once 2. Refactor duplicate code in ClientRPCServiceImpl by extracting helper methods for both tree model and table model 3. Add progress logging to track the loading status of each file 4. Support both synchronous and asynchronous loading modes Changes: - Added getSubStatement() method to LoadTsFileStatement and LoadTsFile for splitting multi-file statements - Extracted shouldSplitLoadTsFileStatement() and shouldSplitTableLoadTsFile() to determine if splitting is needed - Extracted executeBatchLoadTsFile() and executeBatchTableLoadTsFile() to handle batch execution with progress logging - Applied the optimization to 4 execution paths (tree/table model, sync/async loading) This fix significantly reduces memory pressure and improves system stability when loading large numbers of TsFiles. * fix * update (cherry picked from commit bc4f8e9)
1 parent ce0e776 commit 8a903c8

File tree

7 files changed

+511
-44
lines changed

7 files changed

+511
-44
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,21 @@ public class IoTDBConfig {
11211121

11221122
private int loadTsFileSpiltPartitionMaxSize = 10;
11231123

1124+
/**
1125+
* The threshold for splitting statement when loading multiple TsFiles. When the number of TsFiles
1126+
* exceeds this threshold, the statement will be split into multiple sub-statements for batch
1127+
* execution to limit resource consumption during statement analysis. Default value is 10, which
1128+
* means splitting will occur when there are more than 10 files.
1129+
*/
1130+
private int loadTsFileStatementSplitThreshold = 10;
1131+
1132+
/**
1133+
* The number of TsFiles that each sub-statement handles when splitting a statement. This
1134+
* parameter controls how many files are grouped together in each sub-statement during batch
1135+
* execution. Default value is 10, which means each sub-statement handles 10 files.
1136+
*/
1137+
private int loadTsFileSubStatementBatchSize = 10;
1138+
11241139
private String[] loadActiveListeningDirs =
11251140
new String[] {
11261141
IoTDBConstant.EXT_FOLDER_NAME
@@ -4057,6 +4072,46 @@ public void setLoadTsFileSpiltPartitionMaxSize(int loadTsFileSpiltPartitionMaxSi
40574072
this.loadTsFileSpiltPartitionMaxSize = loadTsFileSpiltPartitionMaxSize;
40584073
}
40594074

4075+
public int getLoadTsFileStatementSplitThreshold() {
4076+
return loadTsFileStatementSplitThreshold;
4077+
}
4078+
4079+
public void setLoadTsFileStatementSplitThreshold(final int loadTsFileStatementSplitThreshold) {
4080+
if (loadTsFileStatementSplitThreshold < 0) {
4081+
logger.warn(
4082+
"Invalid loadTsFileStatementSplitThreshold value: {}. Using default value: 10",
4083+
loadTsFileStatementSplitThreshold);
4084+
return;
4085+
}
4086+
if (this.loadTsFileStatementSplitThreshold != loadTsFileStatementSplitThreshold) {
4087+
logger.info(
4088+
"loadTsFileStatementSplitThreshold changed from {} to {}",
4089+
this.loadTsFileStatementSplitThreshold,
4090+
loadTsFileStatementSplitThreshold);
4091+
}
4092+
this.loadTsFileStatementSplitThreshold = loadTsFileStatementSplitThreshold;
4093+
}
4094+
4095+
public int getLoadTsFileSubStatementBatchSize() {
4096+
return loadTsFileSubStatementBatchSize;
4097+
}
4098+
4099+
public void setLoadTsFileSubStatementBatchSize(final int loadTsFileSubStatementBatchSize) {
4100+
if (loadTsFileSubStatementBatchSize <= 0) {
4101+
logger.warn(
4102+
"Invalid loadTsFileSubStatementBatchSize value: {}. Using default value: 10",
4103+
loadTsFileSubStatementBatchSize);
4104+
return;
4105+
}
4106+
if (this.loadTsFileSubStatementBatchSize != loadTsFileSubStatementBatchSize) {
4107+
logger.info(
4108+
"loadTsFileSubStatementBatchSize changed from {} to {}",
4109+
this.loadTsFileSubStatementBatchSize,
4110+
loadTsFileSubStatementBatchSize);
4111+
}
4112+
this.loadTsFileSubStatementBatchSize = loadTsFileSubStatementBatchSize;
4113+
}
4114+
40604115
public String[] getPipeReceiverFileDirs() {
40614116
return (Objects.isNull(this.pipeReceiverFileDirs) || this.pipeReceiverFileDirs.length == 0)
40624117
? new String[] {systemDir + File.separator + "pipe" + File.separator + "receiver"}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,6 +2406,18 @@ private void loadLoadTsFileProps(TrimProperties properties) {
24062406
properties.getProperty(
24072407
"skip_failed_table_schema_check",
24082408
String.valueOf(conf.isSkipFailedTableSchemaCheck()))));
2409+
2410+
conf.setLoadTsFileStatementSplitThreshold(
2411+
Integer.parseInt(
2412+
properties.getProperty(
2413+
"load_tsfile_statement_split_threshold",
2414+
Integer.toString(conf.getLoadTsFileStatementSplitThreshold()))));
2415+
2416+
conf.setLoadTsFileSubStatementBatchSize(
2417+
Integer.parseInt(
2418+
properties.getProperty(
2419+
"load_tsfile_sub_statement_batch_size",
2420+
Integer.toString(conf.getLoadTsFileSubStatementBatchSize()))));
24092421
}
24102422

24112423
private void loadLoadTsFileHotModifiedProp(TrimProperties properties) throws IOException {
@@ -2454,6 +2466,18 @@ private void loadLoadTsFileHotModifiedProp(TrimProperties properties) throws IOE
24542466
"load_tsfile_split_partition_max_size",
24552467
Integer.toString(conf.getLoadTsFileSpiltPartitionMaxSize()))));
24562468

2469+
conf.setLoadTsFileStatementSplitThreshold(
2470+
Integer.parseInt(
2471+
properties.getProperty(
2472+
"load_tsfile_statement_split_threshold",
2473+
Integer.toString(conf.getLoadTsFileStatementSplitThreshold()))));
2474+
2475+
conf.setLoadTsFileSubStatementBatchSize(
2476+
Integer.parseInt(
2477+
properties.getProperty(
2478+
"load_tsfile_sub_statement_batch_size",
2479+
Integer.toString(conf.getLoadTsFileSubStatementBatchSize()))));
2480+
24572481
conf.setSkipFailedTableSchemaCheck(
24582482
Boolean.parseBoolean(
24592483
properties.getProperty(

0 commit comments

Comments
 (0)