Copilot commented on code in PR #16959:
URL: https://github.com/apache/iotdb/pull/16959#discussion_r2650070302
##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/fragment/FragmentInstanceExecutionTest.java:
##########
@@ -157,6 +174,72 @@ public void testTVListOwnerTransfer() throws
InterruptedException {
}
}
+ @Test
+ public void testTVListCloneForQuery() {
+ IoTDBDescriptor.getInstance().getConfig().setDataNodeId(1);
+
+ ExecutorService instanceNotificationExecutor =
+ IoTDBThreadPoolFactory.newFixedThreadPool(1,
"test-instance-notification");
+
+ try {
+ String deviceId = "d1";
+ String measurementId = "s1";
+ IMemTable memTable = createMemTable(deviceId, measurementId);
+ assertEquals(1, memTable.getMemTableMap().size());
+ IWritableMemChunkGroup memChunkGroup =
memTable.getMemTableMap().values().iterator().next();
+ assertEquals(1, memChunkGroup.getMemChunkMap().size());
+ IWritableMemChunk memChunk =
memChunkGroup.getMemChunkMap().values().iterator().next();
+ TVList tvList = memChunk.getWorkingTVList();
+ assertFalse(tvList.isSorted());
+
+ // FragmentInstance Context
+ FragmentInstanceId id1 = new FragmentInstanceId(new
PlanFragmentId(MOCK_QUERY_ID, 1), "1");
+ FragmentInstanceStateMachine stateMachine1 =
+ new FragmentInstanceStateMachine(id1, instanceNotificationExecutor);
+ FragmentInstanceContext fragmentInstanceContext1 =
+ createFragmentInstanceContext(id1, stateMachine1);
+
+ FragmentInstanceId id2 = new FragmentInstanceId(new
PlanFragmentId(MOCK_QUERY_ID, 2), "2");
+ FragmentInstanceStateMachine stateMachine2 =
+ new FragmentInstanceStateMachine(id2, instanceNotificationExecutor);
+ FragmentInstanceContext fragmentInstanceContext2 =
+ createFragmentInstanceContext(id2, stateMachine2);
+
+ // query on memtable
+ MeasurementPath fullPath =
+ new MeasurementPath(
+ deviceId,
+ measurementId,
+ new MeasurementSchema(
+ measurementId,
+ TSDataType.INT32,
+ TSEncoding.RLE,
+ CompressionType.UNCOMPRESSED,
+ Collections.emptyMap()));
+ ReadOnlyMemChunk readOnlyMemChunk1 =
+ memTable.query(fragmentInstanceContext1, fullPath, Long.MIN_VALUE,
null, null);
+ ReadOnlyMemChunk readOnlyMemChunk2 =
+ memTable.query(fragmentInstanceContext2, fullPath, Long.MIN_VALUE,
null, null);
Review Comment:
The test creates two ReadOnlyMemChunk instances (readOnlyMemChunk1 and
readOnlyMemChunk2) but only uses readOnlyMemChunk1. The unused variable
readOnlyMemChunk2 should either be used in the test logic or removed to improve
code clarity.
```suggestion
```
##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/fragment/FragmentInstanceExecutionTest.java:
##########
@@ -201,4 +284,20 @@ private TVList buildTVList() {
}
return tvList;
}
+
+ private IMemTable createMemTable(String deviceId, String measurementId)
+ throws IllegalPathException {
+ IMemTable memTable = new PrimitiveMemTable("root.test", "1");
+
+ int rows = 100;
+ for (int i = 0; i < 100; i++) {
Review Comment:
The variable `rows` is declared with the value 100, but it's not actually
used in the loop logic. The loop iterates from 0 to 99, and the timestamp is
calculated as `rows - i - 1`, but this could be simplified to just use the
literal 100 or properly use the `rows` variable in the loop condition.
```suggestion
for (int i = 0; i < rows; i++) {
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java:
##########
@@ -319,6 +321,13 @@ protected void set(int index, long timestamp, int
valueIndex) {
int offset = i * ARRAY_SIZE;
Arrays.setAll(indices.get(i), j -> offset + j);
}
+ // Reserve memory for indices if the TVList is owned by a query
+ if (ownerQuery != null) {
+ long indicesBytes = indices.size() * PrimitiveArrayManager.ARRAY_SIZE
* 4L;
Review Comment:
Potential overflow in [int multiplication](1) before it is converted to long
by use in a numeric context.
```suggestion
long indicesBytes =
(long) indices.size() * PrimitiveArrayManager.ARRAY_SIZE *
Integer.BYTES;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]