This is an automated email from the ASF dual-hosted git repository.
jt2594838 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new d365d76af76 Fix Pipe tablet memory lifetime (#19421)
d365d76af76 is described below
commit d365d76af76d1df9e5b49b294cbac3b34f9a37cb
Author: Caideyipi <[email protected]>
AuthorDate: Thu Nov 26 19:45:12 2026 +0800
Fix Pipe tablet memory lifetime (#19421)
---
.../common/tablet/PipeRawTabletInsertionEvent.java | 15 +++-----
.../pipe/event/PipeTsFileInsertionEventTest.java | 45 ++++++++++++++++++++++
2 files changed, 51 insertions(+), 9 deletions(-)
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tablet/PipeRawTabletInsertionEvent.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tablet/PipeRawTabletInsertionEvent.java
index e41b8d39f63..be42443b0b1 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tablet/PipeRawTabletInsertionEvent.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tablet/PipeRawTabletInsertionEvent.java
@@ -38,7 +38,6 @@ import
org.apache.iotdb.db.pipe.event.common.tablet.parser.TabletInsertionEventT
import org.apache.iotdb.db.pipe.event.common.tsfile.PipeTsFileInsertionEvent;
import org.apache.iotdb.db.pipe.metric.overview.PipeDataNodeSinglePipeMetrics;
import org.apache.iotdb.db.pipe.resource.PipeDataNodeResourceManager;
-import org.apache.iotdb.db.pipe.resource.memory.PipeMemoryBlock;
import org.apache.iotdb.db.pipe.resource.memory.PipeMemoryBlockCategory;
import org.apache.iotdb.db.pipe.resource.memory.PipeMemoryWeightUtil;
import org.apache.iotdb.db.pipe.resource.memory.PipeTabletMemoryBlock;
@@ -126,20 +125,18 @@ public class PipeRawTabletInsertionEvent extends
PipeInsertionEvent
inheritSourceEventReportSkippingIfNecessary();
// Allocate empty memory block, will be resized later.
- final PipeMemoryBlock parentMemoryBlock =
+ final boolean hasSourceEventMemoryBlock =
sourceEvent instanceof PipeInsertionEvent
- ? ((PipeInsertionEvent) sourceEvent).getEventMemoryBlock()
- : null;
+ && ((PipeInsertionEvent) sourceEvent).getEventMemoryBlock() !=
null;
this.allocatedMemoryBlock =
PipeDataNodeResourceManager.memory()
.forceAllocateForTabletWithRetry(
PipeRawTabletInsertionEvent.class.getSimpleName(),
0,
- parentMemoryBlock == null
- ? PipeMemoryBlockCategory.EVENT
- : PipeMemoryBlockCategory.TABLET,
- this,
- parentMemoryBlock);
+ hasSourceEventMemoryBlock
+ ? PipeMemoryBlockCategory.TABLET
+ : PipeMemoryBlockCategory.EVENT,
+ this);
this.allocatedMemoryBlock.setAssigner(this);
if (needToReport || sourceTsFileInsertionEvent != null) {
diff --git
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/event/PipeTsFileInsertionEventTest.java
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/event/PipeTsFileInsertionEventTest.java
index c5e262079d5..3e7fa05cc5b 100644
---
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/event/PipeTsFileInsertionEventTest.java
+++
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/event/PipeTsFileInsertionEventTest.java
@@ -34,9 +34,13 @@ import
org.apache.iotdb.commons.queryengine.plan.relational.metadata.QualifiedOb
import org.apache.iotdb.commons.utils.FileUtils;
import org.apache.iotdb.db.auth.AuthorityChecker;
import org.apache.iotdb.db.i18n.DataNodePipeMessages;
+import
org.apache.iotdb.db.pipe.event.common.tablet.PipeRawTabletInsertionEvent;
import
org.apache.iotdb.db.pipe.event.common.tsfile.PipeCompactedTsFileInsertionEvent;
import org.apache.iotdb.db.pipe.event.common.tsfile.PipeTsFileInsertionEvent;
import org.apache.iotdb.db.pipe.resource.PipeDataNodeResourceManager;
+import org.apache.iotdb.db.pipe.resource.memory.PipeMemoryBlock;
+import org.apache.iotdb.db.pipe.resource.memory.PipeMemoryBlockCategory;
+import org.apache.iotdb.db.pipe.resource.memory.PipeMemoryManager;
import org.apache.iotdb.db.pipe.resource.tsfile.PipeTsFileResourceManager;
import
org.apache.iotdb.db.pipe.source.dataregion.realtime.assigner.PipeTsFileEpochProgressIndexKeeper;
import org.apache.iotdb.db.queryengine.plan.relational.security.AccessControl;
@@ -56,10 +60,15 @@ import
org.apache.iotdb.db.storageengine.dataregion.tsfile.timeindex.ITimeIndex;
import org.apache.iotdb.db.utils.constant.TestConstant;
import org.apache.iotdb.pipe.api.exception.PipeException;
+import org.apache.tsfile.common.conf.TSFileConfig;
+import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.IDeviceID;
import org.apache.tsfile.file.metadata.enums.CompressionType;
import org.apache.tsfile.file.metadata.enums.TSEncoding;
import org.apache.tsfile.read.common.TimeRange;
+import org.apache.tsfile.utils.Binary;
+import org.apache.tsfile.write.record.Tablet;
+import org.apache.tsfile.write.schema.MeasurementSchema;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
@@ -79,6 +88,42 @@ import static
org.apache.iotdb.commons.pipe.datastructure.pattern.TreePattern.bu
import static
org.apache.iotdb.db.auth.AuthorityChecker.NO_PERMISSION_PROMOTION;
public class PipeTsFileInsertionEventTest {
+ @Test
+ public void testGeneratedTabletMemoryRemainsAccountedAfterSourceClose() {
+ final PipeMemoryManager memoryManager =
PipeDataNodeResourceManager.memory();
+ final long usedMemoryBefore = memoryManager.getUsedMemorySizeInBytes();
+ final PipeTsFileInsertionEvent sourceEvent =
+ new PipeTsFileInsertionEvent(
+ true, "db1", new TsFileResource(new File("source.tsfile")), false);
+ final Tablet tablet =
+ new Tablet(
+ "root.test.d1",
+ Collections.singletonList(new MeasurementSchema("s1",
TSDataType.TEXT)),
+ 1);
+ tablet.addTimestamp(0, 1);
+ tablet.addValue("s1", 0, new Binary("payload",
TSFileConfig.STRING_CHARSET));
+ final PipeRawTabletInsertionEvent tabletEvent =
+ new PipeRawTabletInsertionEvent(
+ false, "db1", null, "db1", tablet, true, null, 0, null,
sourceEvent, false);
+ final PipeMemoryBlock tabletMemoryBlock =
tabletEvent.getEventMemoryBlock();
+ try {
+ Assert.assertTrue(tabletEvent.increaseReferenceCount("test"));
+ Assert.assertNull(tabletMemoryBlock.getParentBlock());
+ Assert.assertEquals(PipeMemoryBlockCategory.TABLET,
tabletMemoryBlock.getCategory());
+ final long tabletMemorySize = tabletMemoryBlock.getMemoryUsageInBytes();
+ Assert.assertTrue(tabletMemorySize > 0);
+ sourceEvent.close();
+ Assert.assertSame(tablet, tabletEvent.convertToTablet());
+ Assert.assertEquals(tabletMemorySize,
tabletMemoryBlock.getMemoryUsageInBytes());
+ Assert.assertEquals(
+ usedMemoryBefore + tabletMemorySize,
memoryManager.getUsedMemorySizeInBytes());
+ } finally {
+ tabletEvent.clearReferenceCount("test");
+ sourceEvent.close();
+ }
+ Assert.assertEquals(usedMemoryBefore,
memoryManager.getUsedMemorySizeInBytes());
+ }
+
@Test
public void testRealtimeTsFileTimeParsingRemainsUnchanged() {
final TsFileResource resource = new TsFileResource(new
File("1-1-0-0.tsfile"));