This is an automated email from the ASF dual-hosted git repository.
Caideyipi pushed a commit to branch dev/1.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/dev/1.3 by this push:
new 0ce224ef184 [To dev/1.3] Fix the AlignedTVListIterator / memtable read
index problem (#18159)
0ce224ef184 is described below
commit 0ce224ef18457eb9ae35a63b91a0731336655893
Author: Caideyipi <[email protected]>
AuthorDate: Wed Aug 19 10:40:48 2026 +0800
[To dev/1.3] Fix the AlignedTVListIterator / memtable read index problem
(#18159)
* Fix the AlignedTVListIterator / memtable read index problem
(cherry picked from commit 344536f2b005e057dadfc5b895fd3c615cfb4491)
* Update AlignedTVList.java
(cherry picked from commit 3f845e18c7206192f2204e28ff83a35170625dc8)
---
.../db/utils/datastructure/AlignedTVList.java | 31 ++++++++++----------
.../memtable/AlignedTVListIteratorTest.java | 34 ++++++++++++++++++++++
2 files changed, 49 insertions(+), 16 deletions(-)
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
index a3cb492c9a1..0b03aebaefc 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
@@ -2131,8 +2131,7 @@ public abstract class AlignedTVList extends TVList {
while (index < rows && !findValidRow) {
// all columns values are deleted
int convertedScanOrderValueIndex =
getValueIndex(getScanOrderIndex(index));
- if ((allValueColDeletedMap != null
- && allValueColDeletedMap.isMarked(convertedScanOrderValueIndex))) {
+ if (isAllValueColumnsDeleted(convertedScanOrderValueIndex)) {
index++;
continue;
}
@@ -2165,9 +2164,7 @@ public abstract class AlignedTVList extends TVList {
while (index + 1 < rows
&& getTime(getScanOrderIndex(index + 1)) ==
getTime(getScanOrderIndex(index))) {
index++;
- // skip all-Null rows if allValueColDeletedMap exists
- if (allValueColDeletedMap == null
- ||
!allValueColDeletedMap.isMarked(getValueIndex(getScanOrderIndex(index)))) {
+ if
(!isAllValueColumnsDeleted(getValueIndex(getScanOrderIndex(index)))) {
for (int columnIndex = 0; columnIndex < dataTypeList.size();
columnIndex++) {
if (!scanOrder.isAscending() && selectedIndices[columnIndex] !=
-1) {
// non -1 value means it already set the latest point index
@@ -2333,8 +2330,7 @@ public abstract class AlignedTVList extends TVList {
break;
}
// skip invalid row
- if ((allValueColDeletedMap != null
- &&
allValueColDeletedMap.isMarked(getValueIndex(getScanOrderIndex(index))))
+ if (isAllValueColumnsDeleted(getValueIndex(getScanOrderIndex(index)))
|| !isTimeSatisfied(time)) {
timeInvalidInfo =
timeInvalidInfo == null
@@ -2345,9 +2341,7 @@ public abstract class AlignedTVList extends TVList {
}
int nextRowIndex = index + 1;
while (nextRowIndex < rows
- && ((allValueColDeletedMap != null
- && allValueColDeletedMap.isMarked(
- getValueIndex(getScanOrderIndex(nextRowIndex))))
+ &&
(isAllValueColumnsDeleted(getValueIndex(getScanOrderIndex(nextRowIndex)))
||
!isTimeSatisfied(getTime(getScanOrderIndex(nextRowIndex))))) {
timeInvalidInfo =
timeInvalidInfo == null
@@ -2602,14 +2596,12 @@ public abstract class AlignedTVList extends TVList {
break;
}
// skip empty row
- if (allValueColDeletedMap != null &&
allValueColDeletedMap.isMarked(getValueIndex(index))) {
+ if (isAllValueColumnsDeleted(getValueIndex(index))) {
continue;
}
int nextRowIndex = index + 1;
- while (nextRowIndex < rows
- && (allValueColDeletedMap != null
- &&
allValueColDeletedMap.isMarked(getValueIndex(nextRowIndex)))) {
+ while (nextRowIndex < rows &&
isAllValueColumnsDeleted(getValueIndex(nextRowIndex))) {
nextRowIndex++;
}
long time = getTime(index);
@@ -2639,8 +2631,7 @@ public abstract class AlignedTVList extends TVList {
}
for (int sortedRowIndex = startIndex; sortedRowIndex < index;
sortedRowIndex++) {
// skip empty row
- if (allValueColDeletedMap != null
- &&
allValueColDeletedMap.isMarked(getValueIndex(sortedRowIndex))) {
+ if (isAllValueColumnsDeleted(getValueIndex(sortedRowIndex))) {
continue;
}
long time = getTime(sortedRowIndex);
@@ -2721,6 +2712,14 @@ public abstract class AlignedTVList extends TVList {
return selectedIndices;
}
+ private boolean isAllValueColumnsDeleted(int valueIndex) {
+ // A sorted row-count snapshot can point to value indices appended after
the snapshot.
+ return allValueColDeletedMap != null
+ && valueIndex >= 0
+ && valueIndex < allValueColDeletedMap.getSize()
+ && allValueColDeletedMap.isMarked(valueIndex);
+ }
+
public int getSelectedIndex(int column) {
return selectedIndices[column];
}
diff --git
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedTVListIteratorTest.java
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedTVListIteratorTest.java
index a3d1e95d954..d5a8b49f726 100644
---
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedTVListIteratorTest.java
+++
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedTVListIteratorTest.java
@@ -166,6 +166,40 @@ public class AlignedTVListIteratorTest {
tvListMap = buildAlignedSingleTvListMap(Collections.singletonList(new
TimeRange(1, 10)));
}
+ @Test
+ public void testIteratorWithStaleRowCountAfterSort() {
+ AlignedTVList tvList =
+ AlignedTVList.newAlignedList(
+ Arrays.asList(TSDataType.INT32, TSDataType.INT32,
TSDataType.INT32));
+ for (int i = 100; i < 110; i++) {
+ tvList.putAlignedValue(i, new Object[] {i, i, i});
+ }
+ int staleRowCount = tvList.rowCount();
+ for (int i = 1; i <= 2; i++) {
+ tvList.putAlignedValue(i, new Object[] {i, i, i});
+ }
+ tvList.delete(1, 2);
+ tvList.sort();
+
+ AlignedTVList.AlignedTVListIterator iterator =
+ tvList.iterator(
+ Ordering.ASC,
+ staleRowCount,
+ null,
+ Arrays.asList(TSDataType.INT32, TSDataType.INT32,
TSDataType.INT32),
+ Arrays.asList(0, 1, 2),
+ null,
+ null,
+ null,
+ 100);
+ int count = 0;
+ while (iterator.hasNextTimeValuePair()) {
+ iterator.nextTimeValuePair();
+ count++;
+ }
+ Assert.assertEquals(staleRowCount - 2, count);
+ }
+
@Test
public void testAlignedWithDeletionsInTVList() throws IOException {
Map<TVList, Integer> tvListMap =