Skip to content

Commit ae37192

Browse files
authored
[To dev/1.3] Pipe: Avoided timeIndexes' memory occupation for deleted tsFiles && Removed useless stale logic && Improved the memory calculation of tsFileResource && Avoided the potential failure for permission check when the source file is deleted (#16399) (#16415)
* Pipe: Avoided timeIndexes' memory occupation for deleted tsFiles && Removed useless stale logic && Improved the memory calculation of tsFileResource && Avoided the potential failure for permission check when the source file is deleted (#16399) * fix * partial * reduce unnecessary * Fix * may fix * Fix * bishop * fix * nonnull * fix * enrich * fix * fix * comp * fix * fix * Refactor * fix
1 parent f21870c commit ae37192

5 files changed

Lines changed: 30 additions & 18 deletions

File tree

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/connection/PipeEventCollector.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,7 @@ private void parseAndCollectEvent(final PipeTsFileInsertionEvent sourceEvent) th
129129
return;
130130
}
131131

132-
if (skipParsing) {
133-
collectEvent(sourceEvent);
134-
return;
135-
}
136-
137-
if (!forceTabletFormat && canSkipParsing4TsFileEvent(sourceEvent)) {
132+
if (skipParsing || !forceTabletFormat && canSkipParsing4TsFileEvent(sourceEvent)) {
138133
collectEvent(sourceEvent);
139134
return;
140135
}

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/PipeTsFileInsertionEvent.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public class PipeTsFileInsertionEvent extends EnrichedEvent
8686
protected long flushPointCount = TsFileProcessor.FLUSH_POINT_COUNT_NOT_SET;
8787

8888
protected volatile ProgressIndex overridingProgressIndex;
89+
private Set<String> tableNames;
8990

9091
public PipeTsFileInsertionEvent(final TsFileResource resource, final boolean isLoaded) {
9192
// The modFile must be copied before the event is assigned to the listening pipes
@@ -122,6 +123,7 @@ public PipeTsFileInsertionEvent(
122123
this.isGeneratedByPipe = resource.isGeneratedByPipe();
123124
this.isGeneratedByPipeConsensus = resource.isGeneratedByPipeConsensus();
124125
this.isGeneratedByHistoricalExtractor = isGeneratedByHistoricalExtractor;
126+
this.tableNames = tableNames;
125127

126128
this.dataContainer = new AtomicReference<>(null);
127129

@@ -394,7 +396,7 @@ public boolean mayEventPathsOverlappedWithPattern() {
394396
deviceID ->
395397
pipePattern.mayOverlapWithDevice(((PlainDeviceID) deviceID).toStringID()));
396398
} catch (final Exception e) {
397-
LOGGER.warn(
399+
LOGGER.info(
398400
"Pipe {}: failed to get devices from TsFile {}, extract it anyway",
399401
pipeName,
400402
resource.getTsFilePath(),

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/historical/PipeHistoricalDataRegionTsFileSource.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class PipeHistoricalDataRegionTsFileSource implements PipeHistoricalDataR
111111
private PipePattern pipePattern;
112112
private boolean isDbNameCoveredByPattern = false;
113113

114-
private boolean isHistoricalExtractorEnabled = false;
114+
private boolean isHistoricalSourceEnabled = false;
115115
private long historicalDataExtractionStartTime = Long.MIN_VALUE; // Event time
116116
private long historicalDataExtractionEndTime = Long.MAX_VALUE; // Event time
117117

@@ -174,7 +174,7 @@ public void validate(final PipeParameterValidator validator) {
174174
EXTRACTOR_START_TIME_KEY,
175175
SOURCE_END_TIME_KEY,
176176
EXTRACTOR_END_TIME_KEY)) {
177-
isHistoricalExtractorEnabled = true;
177+
isHistoricalSourceEnabled = true;
178178

179179
try {
180180
historicalDataExtractionStartTime =
@@ -214,7 +214,7 @@ public void validate(final PipeParameterValidator validator) {
214214
// enabled, the pipe will lose some historical data.
215215
// 2. User may set the EXTRACTOR_HISTORY_START_TIME and EXTRACTOR_HISTORY_END_TIME without
216216
// enabling the historical data extraction, which may affect the realtime data extraction.
217-
isHistoricalExtractorEnabled =
217+
isHistoricalSourceEnabled =
218218
parameters.getBooleanOrDefault(
219219
SystemConstant.RESTART_KEY, SystemConstant.RESTART_DEFAULT_VALUE)
220220
|| parameters.getBooleanOrDefault(
@@ -382,7 +382,7 @@ public synchronized void start() {
382382
.peek(originalResourceList::add)
383383
.filter(
384384
resource ->
385-
isHistoricalExtractorEnabled
385+
isHistoricalSourceEnabled
386386
&&
387387
// Some resource is marked as deleted but not removed from the list.
388388
!resource.isDeleted()
@@ -408,7 +408,7 @@ && mayTsFileResourceOverlappedWithPattern(resource)))
408408
.peek(originalResourceList::add)
409409
.filter(
410410
resource ->
411-
isHistoricalExtractorEnabled
411+
isHistoricalSourceEnabled
412412
&&
413413
// Some resource is marked as deleted but not removed from the list.
414414
!resource.isDeleted()

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ public class TsFileResource {
107107
protected TsFileResource next;
108108

109109
/** time index */
110-
private ITimeIndex timeIndex;
110+
private volatile ITimeIndex timeIndex;
111+
112+
private final AtomicReference<Boolean> isEmpty = new AtomicReference<>();
111113

112114
@SuppressWarnings("squid:S3077")
113115
private volatile ModificationFile modFile;
@@ -121,11 +123,11 @@ public class TsFileResource {
121123
/** used for check whether this file has internal unsorted data in compaction selection */
122124
private TsFileRepairStatus tsFileRepairStatus = TsFileRepairStatus.NORMAL;
123125

124-
private TsFileLock tsFileLock = new TsFileLock();
126+
private final TsFileLock tsFileLock = new TsFileLock();
125127

126128
private boolean isSeq;
127129

128-
private FSFactory fsFactory = FSFactoryProducer.getFSFactory();
130+
private final FSFactory fsFactory = FSFactoryProducer.getFSFactory();
129131

130132
private DataRegion.SettleTsFileCallBack settleTsFileCallBack;
131133

@@ -647,6 +649,10 @@ public void removeModFile() throws IOException {
647649
*/
648650
public boolean remove() {
649651
forceMarkDeleted();
652+
// To release the memory occupied by pipe if held by it
653+
// Note that pipe can safely handle the case that the time index does not exist
654+
isEmpty();
655+
degradeTimeIndex();
650656
try {
651657
fsFactory.deleteIfExists(file);
652658
fsFactory.deleteIfExists(
@@ -935,13 +941,18 @@ public void setModFile(ModificationFile modFile) {
935941
* @return resource map size
936942
*/
937943
public long calculateRamSize() {
944+
final ProgressIndex progressIndex = maxProgressIndex.get();
938945
if (timeIndex.getTimeIndexType() == ITimeIndex.FILE_TIME_INDEX_TYPE) {
939-
return INSTANCE_SIZE + timeIndex.calculateRamSize();
946+
return INSTANCE_SIZE
947+
+ timeIndex.calculateRamSize()
948+
+ (Objects.nonNull(progressIndex) ? progressIndex.ramBytesUsed() : 0);
940949
}
941950
if (deviceTimeIndexRamSize == 0) {
942951
deviceTimeIndexRamSize = timeIndex.calculateRamSize();
943952
}
944-
return INSTANCE_SIZE + deviceTimeIndexRamSize;
953+
return INSTANCE_SIZE
954+
+ deviceTimeIndexRamSize
955+
+ (Objects.nonNull(progressIndex) ? progressIndex.ramBytesUsed() : 0);
945956
}
946957

947958
// used for compaction
@@ -1219,7 +1230,9 @@ public ProgressIndex getMaxProgressIndex() {
12191230
}
12201231

12211232
public boolean isEmpty() {
1222-
return getFileStartTime() == Long.MAX_VALUE && getFileEndTime() == Long.MIN_VALUE;
1233+
isEmpty.compareAndSet(
1234+
null, getFileStartTime() == Long.MAX_VALUE && getFileEndTime() == Long.MIN_VALUE);
1235+
return isEmpty.get();
12231236
}
12241237

12251238
public String getDatabaseName() {

‎iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/AbstractCompactionTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
4545
import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResourceStatus;
4646
import org.apache.iotdb.db.storageengine.dataregion.wal.WALManager;
47+
import org.apache.iotdb.db.storageengine.rescon.memory.TsFileResourceManager;
4748
import org.apache.iotdb.db.tools.validate.TsFileValidationTool;
4849
import org.apache.iotdb.db.utils.EnvironmentUtils;
4950
import org.apache.iotdb.db.utils.constant.TestConstant;
@@ -504,6 +505,7 @@ public void tearDown() throws IOException, StorageEngineException {
504505
}
505506
registeredTimePartitionDirs.clear();
506507
tsFileManager.clear();
508+
TsFileResourceManager.getInstance().clear();
507509
}
508510

509511
private void removeFiles() throws IOException {

0 commit comments

Comments
 (0)