|
27 | 27 | import org.apache.iotdb.db.pipe.event.common.tsfile.container.TsFileInsertionDataContainer; |
28 | 28 | import org.apache.iotdb.db.pipe.event.common.tsfile.container.query.TsFileInsertionQueryDataContainer; |
29 | 29 | import org.apache.iotdb.db.pipe.event.common.tsfile.container.scan.TsFileInsertionScanDataContainer; |
| 30 | +import org.apache.iotdb.db.pipe.resource.memory.PipeMemoryBlock; |
30 | 31 | import org.apache.iotdb.db.storageengine.dataregion.compaction.utils.CompactionTestFileWriter; |
31 | 32 | import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource; |
32 | 33 | import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResourceStatus; |
|
56 | 57 |
|
57 | 58 | import java.io.File; |
58 | 59 | import java.io.IOException; |
| 60 | +import java.lang.reflect.Field; |
59 | 61 | import java.time.LocalDate; |
60 | 62 | import java.util.ArrayList; |
61 | 63 | import java.util.Arrays; |
@@ -119,6 +121,47 @@ public void testScanContainer() throws Exception { |
119 | 121 | System.out.println(System.currentTimeMillis() - startTime); |
120 | 122 | } |
121 | 123 |
|
| 124 | + @Test |
| 125 | + public void testScanParserResizesChunkMemoryForFirstAlignedValueChunk() throws Exception { |
| 126 | + final long originalPipeMaxReaderChunkSize = |
| 127 | + PipeConfig.getInstance().getPipeMaxReaderChunkSize(); |
| 128 | + CommonDescriptor.getInstance().getConfig().setPipeMaxReaderChunkSize(0); |
| 129 | + |
| 130 | + alignedTsFile = new File("single-aligned-value-chunk.tsfile"); |
| 131 | + final List<MeasurementSchema> schemaList = new ArrayList<>(); |
| 132 | + schemaList.add(new MeasurementSchema("s1", TSDataType.INT64)); |
| 133 | + |
| 134 | + final Tablet tablet = new Tablet("root.sg.d", schemaList, 2); |
| 135 | + tablet.rowSize = 2; |
| 136 | + tablet.addTimestamp(0, 1); |
| 137 | + tablet.addValue("s1", 0, 1L); |
| 138 | + tablet.addTimestamp(1, 2); |
| 139 | + tablet.addValue("s1", 1, 2L); |
| 140 | + |
| 141 | + try { |
| 142 | + try (final TsFileWriter writer = new TsFileWriter(alignedTsFile)) { |
| 143 | + writer.registerAlignedTimeseries(new Path("root.sg.d"), schemaList); |
| 144 | + writer.writeAligned(tablet); |
| 145 | + } |
| 146 | + |
| 147 | + try (final TsFileInsertionScanDataContainer parser = |
| 148 | + new TsFileInsertionScanDataContainer( |
| 149 | + alignedTsFile, |
| 150 | + new PrefixPipePattern("root"), |
| 151 | + Long.MIN_VALUE, |
| 152 | + Long.MAX_VALUE, |
| 153 | + null, |
| 154 | + null, |
| 155 | + false)) { |
| 156 | + Assert.assertTrue(getAllocatedChunkMemory(parser).getMemoryUsageInBytes() > 0); |
| 157 | + } |
| 158 | + } finally { |
| 159 | + CommonDescriptor.getInstance() |
| 160 | + .getConfig() |
| 161 | + .setPipeMaxReaderChunkSize(originalPipeMaxReaderChunkSize); |
| 162 | + } |
| 163 | + } |
| 164 | + |
122 | 165 | public void testToTabletInsertionEvents(final boolean isQuery) throws Exception { |
123 | 166 | // Test empty chunk |
124 | 167 | testMixedTsFileWithEmptyChunk(isQuery); |
@@ -645,4 +688,12 @@ private int getNonNullSize(final Tablet tablet) { |
645 | 688 | } |
646 | 689 | return count; |
647 | 690 | } |
| 691 | + |
| 692 | + private PipeMemoryBlock getAllocatedChunkMemory(final TsFileInsertionScanDataContainer parser) |
| 693 | + throws NoSuchFieldException, IllegalAccessException { |
| 694 | + final Field field = |
| 695 | + TsFileInsertionScanDataContainer.class.getDeclaredField("allocatedMemoryBlockForChunk"); |
| 696 | + field.setAccessible(true); |
| 697 | + return (PipeMemoryBlock) field.get(parser); |
| 698 | + } |
648 | 699 | } |
0 commit comments