diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/container/scan/TsFileInsertionScanDataContainer.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/container/scan/TsFileInsertionScanDataContainer.java index 7322a29604f0..17d11c7ee7a1 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/container/scan/TsFileInsertionScanDataContainer.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/container/scan/TsFileInsertionScanDataContainer.java @@ -160,6 +160,9 @@ public TsFileInsertionScanDataContainer( tsFileSequenceReader.position((long) TSFileConfig.MAGIC_STRING.getBytes().length + 1); prepareData(); + if (Objects.isNull(chunkReader)) { + close(); + } } catch (final Exception e) { close(); throw e; @@ -390,7 +393,7 @@ private void prepareData() throws IOException { } while (Objects.nonNull(chunkReader) && !chunkReader.hasNextSatisfiedPage()); if (Objects.isNull(chunkReader)) { - close(); + // Let the caller release the last tablet's memory before closing the parser. break; } diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/event/TsFileInsertionDataContainerTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/event/TsFileInsertionDataContainerTest.java index ba7d03d74e2b..2a2812dd3957 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/event/TsFileInsertionDataContainerTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/event/TsFileInsertionDataContainerTest.java @@ -172,6 +172,16 @@ public void testScanContainerReleasesTabletMemoryAfterRawTabletGenerated() throw null, null, false)) { + replaceAllocatedTabletMemory( + container, + new PipeMemoryBlock(0) { + @Override + public void close() { + Assert.assertEquals(0, getMemoryUsageInBytes()); + super.close(); + } + }); + final Iterator iterator = container.toTabletInsertionEvents().iterator();