This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 1f98174 [IOTDB-1221] Compaction module: chunk metadata lists returned
by the getMeasurementChunkMetadataListMapIterator method are not
lexicographically ordered by the measurement names (#2817)
1f98174 is described below
commit 1f98174ab0b56533a95adadead69c0c0c8ff3805
Author: Steve Yurong Su <[email protected]>
AuthorDate: Fri Mar 12 15:00:29 2021 +0800
[IOTDB-1221] Compaction module: chunk metadata lists returned by the
getMeasurementChunkMetadataListMapIterator method are not lexicographically
ordered by the measurement names (#2817)
* fix the issue
* improve code style
* fix return type
---
.../iotdb/tsfile/read/TsFileSequenceReader.java | 15 ++++-
...easurementChunkMetadataListMapIteratorTest.java | 65 ++++++++++++++++++----
2 files changed, 66 insertions(+), 14 deletions(-)
diff --git
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java
index 256288f..bb4a8f01 100644
---
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java
+++
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java
@@ -63,6 +63,7 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -1254,6 +1255,13 @@ public class TsFileSequenceReader implements
AutoCloseable {
return maxPlanIndex;
}
+ /**
+ * @return An iterator of linked hashmaps ( measurement -> chunk metadata
list ). When traversing
+ * the linked hashmap, you will get chunk metadata lists according to
the lexicographic order
+ * of the measurements. The first measurement of the linked hashmap of
each iteration is
+ * always larger than the last measurement of the linked hashmap of the
previous iteration in
+ * lexicographic order.
+ */
public Iterator<Map<String, List<ChunkMetadata>>>
getMeasurementChunkMetadataListMapIterator(
String device) throws IOException {
readFileMetadata();
@@ -1271,7 +1279,7 @@ public class TsFileSequenceReader implements
AutoCloseable {
}
@Override
- public Map<String, List<ChunkMetadata>> next() {
+ public LinkedHashMap<String, List<ChunkMetadata>> next() {
throw new NoSuchElementException();
}
};
@@ -1289,12 +1297,13 @@ public class TsFileSequenceReader implements
AutoCloseable {
}
@Override
- public Map<String, List<ChunkMetadata>> next() {
+ public LinkedHashMap<String, List<ChunkMetadata>> next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
Pair<Long, Long> startEndPair = queue.remove();
- Map<String, List<ChunkMetadata>> measurementChunkMetadataList = new
HashMap<>();
+ LinkedHashMap<String, List<ChunkMetadata>>
measurementChunkMetadataList =
+ new LinkedHashMap<>();
try {
List<TimeseriesMetadata> timeseriesMetadataList = new ArrayList<>();
ByteBuffer nextBuffer = readData(startEndPair.left,
startEndPair.right);
diff --git
a/tsfile/src/test/java/org/apache/iotdb/tsfile/read/MeasurementChunkMetadataListMapIteratorTest.java
b/tsfile/src/test/java/org/apache/iotdb/tsfile/read/MeasurementChunkMetadataListMapIteratorTest.java
index 3083544..e4a1313 100644
---
a/tsfile/src/test/java/org/apache/iotdb/tsfile/read/MeasurementChunkMetadataListMapIteratorTest.java
+++
b/tsfile/src/test/java/org/apache/iotdb/tsfile/read/MeasurementChunkMetadataListMapIteratorTest.java
@@ -59,45 +59,65 @@ public class MeasurementChunkMetadataListMapIteratorTest {
@Test
public void test0() throws IOException {
- test(1, 1);
+ testCorrectness(1, 1);
+ testSequentiality(1, 1);
}
@Test
public void test1() throws IOException {
- test(1, 10);
+ testCorrectness(1, 10);
+ testSequentiality(1, 10);
}
@Test
public void test2() throws IOException {
- test(2, 1);
+ testCorrectness(2, 1);
+ testSequentiality(2, 1);
}
@Test
public void test3() throws IOException {
- test(2, 2);
+ testCorrectness(2, 2);
+ testSequentiality(2, 2);
}
@Test
public void test4() throws IOException {
- test(2, 100);
+ testCorrectness(2, 100);
+ testSequentiality(2, 100);
}
@Test
public void test5() throws IOException {
- test(50, 2);
+ testCorrectness(50, 2);
+ testSequentiality(50, 2);
}
@Test
public void test6() throws IOException {
- test(50, 50);
+ testCorrectness(50, 50);
+ testSequentiality(50, 50);
}
@Test
public void test7() throws IOException {
- test(50, 100);
+ testCorrectness(50, 100);
+ testSequentiality(50, 100);
}
- public void test(int deviceNum, int measurementNum) throws IOException {
+ @Test
+ public void test8() throws IOException {
+ testCorrectness(33, 733);
+ testSequentiality(33, 733);
+ }
+
+ @Test
+ public void test9() throws IOException {
+ testCorrectness(733, 33);
+ testSequentiality(733, 33);
+ }
+
+ public void testCorrectness(int deviceNum, int measurementNum) throws
IOException {
FileGenerator.generateFile(10000, deviceNum, measurementNum);
try (TsFileSequenceReader fileReader = new
TsFileSequenceReader(FILE_PATH)) {
@@ -130,14 +150,14 @@ public class MeasurementChunkMetadataListMapIteratorTest {
}
}
- check(expected, actual);
+ checkCorrectness(expected, actual);
}
}
FileGenerator.after();
}
- private void check(
+ private void checkCorrectness(
Map<String, List<ChunkMetadata>> expected, Map<String,
List<ChunkMetadata>> actual) {
Assert.assertEquals(expected.keySet(), actual.keySet());
for (String measurement : expected.keySet()) {
@@ -151,4 +171,27 @@ public class MeasurementChunkMetadataListMapIteratorTest {
}
}
}
+
+ public void testSequentiality(int deviceNum, int measurementNum) throws
IOException {
+ FileGenerator.generateFile(10000, deviceNum, measurementNum);
+
+ try (TsFileSequenceReader fileReader = new
TsFileSequenceReader(FILE_PATH)) {
+ for (String device : fileReader.getAllDevices()) {
+ Iterator<Map<String, List<ChunkMetadata>>> iterator =
+ fileReader.getMeasurementChunkMetadataListMapIterator(device);
+
+ String lastMeasurement = null;
+ while (iterator.hasNext()) {
+ for (String measurement : iterator.next().keySet()) {
+ if (lastMeasurement != null) {
+ Assert.assertTrue(lastMeasurement.compareTo(measurement) < 0);
+ }
+ lastMeasurement = measurement;
+ }
+ }
+ }
+ }
+
+ FileGenerator.after();
+ }
}