Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,6 @@
final long chunkSize = timeChunkSize + valueChunkSize;
if (chunkSize + chunkHeader.getDataSize()
> allocatedMemoryBlockForChunk.getMemoryUsageInBytes()) {
if (valueChunkList.size() == 1
&& chunkSize > allocatedMemoryBlockForChunk.getMemoryUsageInBytes()) {
PipeDataNodeResourceManager.memory()
.forceResize(allocatedMemoryBlockForChunk, chunkSize);
}
needReturn = recordAlignedChunk(valueChunkList, marker);
}
}
Expand All @@ -577,9 +572,11 @@
firstChunkHeader4NextSequentialValueChunks = chunkHeader;
return;
}
resizeChunkMemoryBlockIfFirstValueChunkExceedsLimit(valueChunkList, chunkHeader);

Check warning on line 575 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/parser/scan/TsFileInsertionEventScanParser.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'if' child has incorrect indentation level 14, expected level should be 12.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ37FOt_KvkQ6ozvOu0J&open=AZ37FOt_KvkQ6ozvOu0J&pullRequest=17597
} else {
chunkHeader = firstChunkHeader4NextSequentialValueChunks;
firstChunkHeader4NextSequentialValueChunks = null;
resizeChunkMemoryBlockIfFirstValueChunkExceedsLimit(valueChunkList, chunkHeader);

Check warning on line 579 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/parser/scan/TsFileInsertionEventScanParser.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'else' child has incorrect indentation level 14, expected level should be 12.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ37FOt_KvkQ6ozvOu0K&open=AZ37FOt_KvkQ6ozvOu0K&pullRequest=17597
}

Chunk chunk =
Expand Down Expand Up @@ -720,6 +717,20 @@
return false;
}

private void resizeChunkMemoryBlockIfFirstValueChunkExceedsLimit(
final List<Chunk> valueChunkList, final ChunkHeader valueChunkHeader) {
if (!valueChunkList.isEmpty() || lastIndex < 0) {
return;
}

final long chunkSize =
PipeMemoryWeightUtil.calculateChunkRamBytesUsed(timeChunkList.get(lastIndex))
+ valueChunkHeader.getDataSize();
if (chunkSize > allocatedMemoryBlockForChunk.getMemoryUsageInBytes()) {
PipeDataNodeResourceManager.memory().forceResize(allocatedMemoryBlockForChunk, chunkSize);
}
}

@Override
public void close() {
super.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.iotdb.db.pipe.event.common.tsfile.parser.TsFileInsertionEventParser;
import org.apache.iotdb.db.pipe.event.common.tsfile.parser.query.TsFileInsertionEventQueryParser;
import org.apache.iotdb.db.pipe.event.common.tsfile.parser.scan.TsFileInsertionEventScanParser;
import org.apache.iotdb.db.pipe.resource.memory.PipeMemoryBlock;
import org.apache.iotdb.db.storageengine.dataregion.compaction.utils.CompactionTestFileWriter;
import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResourceStatus;
Expand Down Expand Up @@ -57,6 +58,7 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -120,6 +122,46 @@ public void testScanParser() throws Exception {
System.out.println(System.currentTimeMillis() - startTime);
}

@Test
public void testScanParserResizesChunkMemoryForFirstAlignedValueChunk() throws Exception {
final long originalPipeMaxReaderChunkSize =
PipeConfig.getInstance().getPipeMaxReaderChunkSize();
CommonDescriptor.getInstance().getConfig().setPipeMaxReaderChunkSize(0);

alignedTsFile = new File("single-aligned-value-chunk.tsfile");
final List<IMeasurementSchema> schemaList = new ArrayList<>();
schemaList.add(new MeasurementSchema("s1", TSDataType.INT64));

final Tablet tablet = new Tablet("root.sg.d", schemaList, 2);
tablet.addTimestamp(0, 1);
tablet.addValue("s1", 0, 1L);
tablet.addTimestamp(1, 2);
tablet.addValue("s1", 1, 2L);

try {
try (final TsFileWriter writer = new TsFileWriter(alignedTsFile)) {
writer.registerAlignedTimeseries(new PartialPath("root.sg.d"), schemaList);
writer.writeAligned(tablet);
}

try (final TsFileInsertionEventScanParser parser =
new TsFileInsertionEventScanParser(
alignedTsFile,
new PrefixTreePattern("root"),
Long.MIN_VALUE,
Long.MAX_VALUE,
null,
null,
false)) {
Assert.assertTrue(getAllocatedChunkMemory(parser).getMemoryUsageInBytes() > 0);
}
} finally {
CommonDescriptor.getInstance()
.getConfig()
.setPipeMaxReaderChunkSize(originalPipeMaxReaderChunkSize);
}
}

public void testToTabletInsertionEvents(final boolean isQuery) throws Exception {
// Test empty chunk
testMixedTsFileWithEmptyChunk(isQuery);
Expand Down Expand Up @@ -666,4 +708,12 @@ private int getNonNullSize(final Tablet tablet) {
}
return count;
}

private PipeMemoryBlock getAllocatedChunkMemory(final TsFileInsertionEventScanParser parser)
throws NoSuchFieldException, IllegalAccessException {
final Field field =
TsFileInsertionEventScanParser.class.getDeclaredField("allocatedMemoryBlockForChunk");
field.setAccessible(true);
return (PipeMemoryBlock) field.get(parser);
}
}
Loading