Skip to content

Commit a36cf15

Browse files
authored
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 (apache#16399)
* fix * partial * reduce unnecessary * Fix * may fix * Fix * bishop * fix * nonnull * fix * enrich * fix * fix * comp * fix * fix
1 parent 03e8e51 commit a36cf15

File tree

10 files changed

+107
-130
lines changed

10 files changed

+107
-130
lines changed

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
@@ -130,12 +130,7 @@ private void parseAndCollectEvent(final PipeTsFileInsertionEvent sourceEvent) th
130130
return;
131131
}
132132

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

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/PipeInsertionEvent.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,6 @@ protected PipeInsertionEvent(
117117
null);
118118
}
119119

120-
public void markAsTableModelEvent() {
121-
isTableModelEvent = Boolean.TRUE;
122-
}
123-
124-
public void markAsTreeModelEvent() {
125-
isTableModelEvent = Boolean.FALSE;
126-
}
127-
128120
public boolean isTableModelEvent() {
129121
if (isTableModelEvent == null) {
130122
if (sourceDatabaseNameFromDataRegion == null) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public PipeCompactedTsFileInsertionEvent(
5656
bindIsWithMod(originalEvents),
5757
bindIsLoaded(originalEvents),
5858
bindIsGeneratedByHistoricalExtractor(originalEvents),
59+
// The table name shall not be used anymore when compacted
60+
null,
5961
committerKey.getPipeName(),
6062
committerKey.getCreationTime(),
6163
anyOfOriginalEvents.getPipeTaskMeta(),

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

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import org.apache.iotdb.pipe.api.exception.PipeException;
5050

5151
import org.apache.tsfile.file.metadata.IDeviceID;
52-
import org.apache.tsfile.file.metadata.PlainDeviceID;
5352
import org.slf4j.Logger;
5453
import org.slf4j.LoggerFactory;
5554

@@ -65,14 +64,10 @@
6564
import java.util.concurrent.atomic.AtomicLong;
6665
import java.util.concurrent.atomic.AtomicReference;
6766

68-
import static org.apache.tsfile.common.constant.TsFileConstant.PATH_ROOT;
69-
import static org.apache.tsfile.common.constant.TsFileConstant.PATH_SEPARATOR;
70-
7167
public class PipeTsFileInsertionEvent extends PipeInsertionEvent
7268
implements TsFileInsertionEvent, ReferenceTrackableEvent {
7369

7470
private static final Logger LOGGER = LoggerFactory.getLogger(PipeTsFileInsertionEvent.class);
75-
private static final String TREE_MODEL_EVENT_TABLE_NAME_PREFIX = PATH_ROOT + PATH_SEPARATOR;
7671

7772
private final TsFileResource resource;
7873
private File tsFile;
@@ -96,6 +91,7 @@ public class PipeTsFileInsertionEvent extends PipeInsertionEvent
9691
protected long flushPointCount = TsFileProcessor.FLUSH_POINT_COUNT_NOT_SET;
9792

9893
protected volatile ProgressIndex overridingProgressIndex;
94+
private Set<String> tableNames;
9995

10096
public PipeTsFileInsertionEvent(
10197
final Boolean isTableModelEvent,
@@ -112,6 +108,7 @@ public PipeTsFileInsertionEvent(
112108
isLoaded,
113109
false,
114110
null,
111+
null,
115112
0,
116113
null,
117114
null,
@@ -130,6 +127,7 @@ public PipeTsFileInsertionEvent(
130127
final boolean isWithMod,
131128
final boolean isLoaded,
132129
final boolean isGeneratedByHistoricalExtractor,
130+
final Set<String> tableNames,
133131
final String pipeName,
134132
final long creationTime,
135133
final PipeTaskMeta pipeTaskMeta,
@@ -170,6 +168,7 @@ public PipeTsFileInsertionEvent(
170168
this.isGeneratedByPipe = resource.isGeneratedByPipe();
171169
this.isGeneratedByPipeConsensus = resource.isGeneratedByPipeConsensus();
172170
this.isGeneratedByHistoricalExtractor = isGeneratedByHistoricalExtractor;
171+
this.tableNames = tableNames;
173172

174173
isClosed = new AtomicBoolean(resource.isClosed());
175174
// Register close listener if TsFile is not closed
@@ -412,6 +411,7 @@ public PipeTsFileInsertionEvent shallowCopySelfAndBindPipeTaskMetaForProgressRep
412411
isWithMod,
413412
isLoaded,
414413
isGeneratedByHistoricalExtractor,
414+
tableNames,
415415
pipeName,
416416
creationTime,
417417
pipeTaskMeta,
@@ -438,23 +438,22 @@ public void throwIfNoPrivilege() {
438438
LOGGER.info("Temporary tsFile {} detected, will skip its transfer.", tsFile);
439439
return;
440440
}
441-
for (final IDeviceID deviceID : getDeviceSet()) {
441+
for (final String table : tableNames) {
442442
if (!tablePattern.matchesDatabase(getTableModelDatabaseName())
443-
|| !tablePattern.matchesTable(deviceID.getTableName())) {
443+
|| !tablePattern.matchesTable(table)) {
444444
continue;
445445
}
446446
if (!Coordinator.getInstance()
447447
.getAccessControl()
448448
.checkCanSelectFromTable4Pipe(
449-
userName,
450-
new QualifiedObjectName(getTableModelDatabaseName(), deviceID.getTableName()))) {
449+
userName, new QualifiedObjectName(getTableModelDatabaseName(), table))) {
451450
if (skipIfNoPrivileges) {
452451
shouldParse4Privilege = true;
453452
} else {
454453
throw new AccessDeniedException(
455454
String.format(
456455
"No privilege for SELECT for user %s at table %s.%s",
457-
userName, tableModelDatabaseName, deviceID.getTableName()));
456+
userName, tableModelDatabaseName, table));
458457
}
459458
}
460459
}
@@ -488,29 +487,14 @@ public boolean mayEventTimeOverlappedWithTimeRange() {
488487

489488
@Override
490489
public boolean mayEventPathsOverlappedWithPattern() {
491-
if (Objects.isNull(resource) || !resource.isClosed()) {
490+
if (Objects.isNull(resource) || !resource.isClosed() || isTableModelEvent()) {
492491
return true;
493492
}
494493

495494
try {
496-
return getDeviceSet().stream()
497-
.anyMatch(
498-
deviceID -> {
499-
// Tree model
500-
if (Boolean.FALSE.equals(getRawIsTableModelEvent())
501-
|| deviceID instanceof PlainDeviceID
502-
|| deviceID.getTableName().startsWith(TREE_MODEL_EVENT_TABLE_NAME_PREFIX)
503-
|| deviceID.getTableName().equals(PATH_ROOT)) {
504-
markAsTreeModelEvent();
505-
return treePattern.mayOverlapWithDevice(deviceID);
506-
}
507-
508-
// Table model
509-
markAsTableModelEvent();
510-
return true;
511-
});
495+
return getDeviceSet().stream().anyMatch(treePattern::mayOverlapWithDevice);
512496
} catch (final Exception e) {
513-
LOGGER.warn(
497+
LOGGER.info(
514498
"Pipe {}: failed to get devices from TsFile {}, extract it anyway",
515499
pipeName,
516500
resource.getTsFilePath(),
@@ -526,9 +510,14 @@ private Set<IDeviceID> getDeviceSet() throws IOException {
526510
PipeTsFileResourceManager.getHardlinkOrCopiedFileInPipeDir(
527511
resource.getTsFile(), pipeName),
528512
false);
529-
return Objects.nonNull(deviceIsAlignedMap)
530-
? deviceIsAlignedMap.keySet()
531-
: resource.getDevices();
513+
if (Objects.nonNull(deviceIsAlignedMap)) {
514+
return deviceIsAlignedMap.keySet();
515+
}
516+
return resource.getDevices();
517+
}
518+
519+
public void setTableNames(final Set<String> tableNames) {
520+
this.tableNames = tableNames;
532521
}
533522

534523
/////////////////////////// PipeInsertionEvent ///////////////////////////
@@ -539,25 +528,6 @@ public boolean isTableModelEvent() {
539528
if (getSourceDatabaseNameFromDataRegion() != null) {
540529
return super.isTableModelEvent();
541530
}
542-
543-
try {
544-
for (final IDeviceID deviceID : getDeviceSet()) {
545-
if (deviceID instanceof PlainDeviceID
546-
|| deviceID.getTableName().startsWith(TREE_MODEL_EVENT_TABLE_NAME_PREFIX)
547-
|| deviceID.getTableName().equals(PATH_ROOT)) {
548-
markAsTreeModelEvent();
549-
} else {
550-
markAsTableModelEvent();
551-
}
552-
break;
553-
}
554-
} catch (final Exception e) {
555-
throw new PipeException(
556-
String.format(
557-
"Pipe %s: failed to judge whether TsFile %s is table model or tree model",
558-
pipeName, resource.getTsFilePath()),
559-
e);
560-
}
561531
}
562532

563533
return getRawIsTableModelEvent();

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/realtime/PipeRealtimeEvent.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.apache.iotdb.commons.pipe.datastructure.pattern.TablePattern;
2525
import org.apache.iotdb.commons.pipe.datastructure.pattern.TreePattern;
2626
import org.apache.iotdb.commons.pipe.event.EnrichedEvent;
27-
import org.apache.iotdb.db.pipe.event.common.PipeInsertionEvent;
2827
import org.apache.iotdb.db.pipe.source.dataregion.realtime.PipeRealtimeDataRegionSource;
2928
import org.apache.iotdb.db.pipe.source.dataregion.realtime.epoch.TsFileEpoch;
3029

@@ -112,18 +111,6 @@ public boolean mayExtractorUseTablets(final PipeRealtimeDataRegionSource extract
112111
return state.equals(TsFileEpoch.State.EMPTY) || state.equals(TsFileEpoch.State.USING_TABLET);
113112
}
114113

115-
public void markAsTableModelEvent() {
116-
if (event instanceof PipeInsertionEvent) {
117-
((PipeInsertionEvent) event).markAsTableModelEvent();
118-
}
119-
}
120-
121-
public void markAsTreeModelEvent() {
122-
if (event instanceof PipeInsertionEvent) {
123-
((PipeInsertionEvent) event).markAsTreeModelEvent();
124-
}
125-
}
126-
127114
@Override
128115
public boolean increaseReferenceCount(final String holderMessage) {
129116
// This method must be overridden, otherwise during the real-time data extraction stage, the

0 commit comments

Comments
 (0)