Skip to content

Commit c2c5026

Browse files
authored
[To dev/1.3] Concurrently querying and writing to the memtable may cause the query results out of order
1 parent fe0b45a commit c2c5026

13 files changed

Lines changed: 134 additions & 73 deletions

File tree

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedReadOnlyMemChunk.java‎

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import java.util.ArrayList;
5151
import java.util.List;
5252
import java.util.Map;
53-
import java.util.stream.Collectors;
5453

5554
public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
5655
private final String timeChunkName;
@@ -361,21 +360,7 @@ private TsBlock buildTsBlock() {
361360
}
362361

363362
private void writeValidValuesIntoTsBlock(TsBlockBuilder builder) throws IOException {
364-
List<AlignedTVList> alignedTvLists =
365-
alignedTvListQueryMap.keySet().stream()
366-
.map(x -> (AlignedTVList) x)
367-
.collect(Collectors.toList());
368-
MemPointIterator timeValuePairIterator =
369-
MemPointIteratorFactory.create(
370-
dataTypes,
371-
columnIndexList,
372-
alignedTvLists,
373-
Ordering.ASC,
374-
null,
375-
valueColumnsDeletionList,
376-
floatPrecision,
377-
encodingList,
378-
MAX_NUMBER_OF_POINTS_IN_PAGE);
363+
MemPointIterator timeValuePairIterator = createMemPointIterator(Ordering.ASC, null);
379364

380365
while (timeValuePairIterator.hasNextTimeValuePair()) {
381366
TimeValuePair tvPair = timeValuePairIterator.nextTimeValuePair();
@@ -453,14 +438,17 @@ public MemPointIterator getMemPointIterator() {
453438

454439
@Override
455440
public MemPointIterator createMemPointIterator(Ordering scanOrder, Filter globalTimeFilter) {
456-
List<AlignedTVList> alignedTvLists =
457-
alignedTvListQueryMap.keySet().stream()
458-
.map(x -> (AlignedTVList) x)
459-
.collect(Collectors.toList());
441+
List<AlignedTVList> tvLists = new ArrayList<>(alignedTvListQueryMap.size());
442+
List<Integer> tvListRowCounts = new ArrayList<>(alignedTvListQueryMap.size());
443+
for (Map.Entry<TVList, Integer> entry : alignedTvListQueryMap.entrySet()) {
444+
tvLists.add((AlignedTVList) entry.getKey());
445+
tvListRowCounts.add(entry.getValue());
446+
}
460447
return MemPointIteratorFactory.create(
461448
dataTypes,
462449
columnIndexList,
463-
alignedTvLists,
450+
tvLists,
451+
tvListRowCounts,
464452
scanOrder,
465453
globalTimeFilter,
466454
valueColumnsDeletionList,

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/ReadOnlyMemChunk.java‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,17 +291,7 @@ private TsBlock buildTsBlock() {
291291

292292
// read all data in memory chunk and write to tsblock
293293
private void writeValidValuesIntoTsBlock(TsBlockBuilder builder) throws IOException {
294-
List<TVList> tvLists = new ArrayList<>(tvListQueryMap.keySet());
295-
MemPointIterator timeValuePairIterator =
296-
MemPointIteratorFactory.create(
297-
getDataType(),
298-
tvLists,
299-
Ordering.ASC,
300-
null,
301-
deletionList,
302-
floatPrecision,
303-
encoding,
304-
MAX_NUMBER_OF_POINTS_IN_PAGE);
294+
MemPointIterator timeValuePairIterator = createMemPointIterator(Ordering.ASC, null);
305295

306296
while (timeValuePairIterator.hasNextTimeValuePair()) {
307297
TimeValuePair tvPair = timeValuePairIterator.nextTimeValuePair();
@@ -378,10 +368,16 @@ public MemPointIterator getMemPointIterator() {
378368
}
379369

380370
public MemPointIterator createMemPointIterator(Ordering scanOrder, Filter globalTimeFilter) {
381-
List<TVList> tvLists = new ArrayList<>(tvListQueryMap.keySet());
371+
List<TVList> tvLists = new ArrayList<>(tvListQueryMap.size());
372+
List<Integer> tvListRowCounts = new ArrayList<>(tvListQueryMap.size());
373+
for (Map.Entry<TVList, Integer> entry : tvListQueryMap.entrySet()) {
374+
tvLists.add(entry.getKey());
375+
tvListRowCounts.add(entry.getValue());
376+
}
382377
return MemPointIteratorFactory.create(
383378
dataType,
384379
tvLists,
380+
tvListRowCounts,
385381
scanOrder,
386382
globalTimeFilter,
387383
deletionList,

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,7 @@ public List<List<BitMap>> getBitMaps() {
13341334

13351335
public AlignedTVListIterator iterator(
13361336
Ordering scanOrder,
1337+
int rowCount,
13371338
Filter globalTimeFilter,
13381339
List<TSDataType> dataTypeList,
13391340
List<Integer> columnIndexList,
@@ -1343,6 +1344,7 @@ public AlignedTVListIterator iterator(
13431344
int maxNumberOfPointsInPage) {
13441345
return new AlignedTVListIterator(
13451346
scanOrder,
1347+
rowCount,
13461348
globalTimeFilter,
13471349
dataTypeList,
13481350
columnIndexList,
@@ -1369,14 +1371,15 @@ public class AlignedTVListIterator extends TVListIterator {
13691371

13701372
public AlignedTVListIterator(
13711373
Ordering scanOrder,
1374+
int rowCount,
13721375
Filter globalTimeFilter,
13731376
List<TSDataType> dataTypeList,
13741377
List<Integer> columnIndexList,
13751378
List<List<TimeRange>> valueColumnsDeletionList,
13761379
Integer floatPrecision,
13771380
List<TSEncoding> encodingList,
13781381
int maxNumberOfPointsInPage) {
1379-
super(scanOrder, globalTimeFilter, null, null, null, maxNumberOfPointsInPage);
1382+
super(scanOrder, rowCount, globalTimeFilter, null, null, null, maxNumberOfPointsInPage);
13801383
this.dataTypeList = dataTypeList;
13811384
this.columnIndexList =
13821385
(columnIndexList == null)

0 commit comments

Comments
 (0)