You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2023/05/29 10:49:25 UTC

[iotdb] 01/01: [IOTDB-5905] Fix aligned timeseries data point lost after flushed in some scenario

This is an automated email from the ASF dual-hosted git repository.

haonan pushed a commit to branch fix_aligned_flush_issue
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 67cf3cc3337320b8c023f95bb2fa2a13001778b0
Author: HTHou <hh...@outlook.com>
AuthorDate: Mon May 29 18:49:05 2023 +0800

    [IOTDB-5905] Fix aligned timeseries data point lost after flushed in some scenario
---
 integration-test/pom.xml                           |  4 +++
 .../db/it/aligned/IoTDBInsertAlignedValuesIT.java  | 31 ++++++++++++++++++++++
 .../engine/memtable/AlignedWritableMemChunk.java   | 19 +++++++------
 3 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/integration-test/pom.xml b/integration-test/pom.xml
index 57be4a9abfb..4b09df50498 100644
--- a/integration-test/pom.xml
+++ b/integration-test/pom.xml
@@ -143,6 +143,10 @@
                     <groupId>io.dropwizard.metrics</groupId>
                     <artifactId>metrics-core</artifactId>
                 </exclusion>
+                <exclusion>
+                    <groupId>org.apache.logging.log4j</groupId>
+                    <artifactId>log4j-slf4j-impl</artifactId>
+                </exclusion>
             </exclusions>
         </dependency>
         <dependency>
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValuesIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValuesIT.java
index cfd70558ab0..d8f7ba8b6fe 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValuesIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValuesIT.java
@@ -217,6 +217,37 @@ public class IoTDBInsertAlignedValuesIT {
     }
   }
 
+  @Test
+  public void testInsertAlignedValuesWithSameTimestamp() throws SQLException {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.addBatch("insert into root.sg.d1(time,s2) aligned values(1,2)");
+      statement.addBatch("insert into root.sg.d1(time,s1) aligned values(1,2)");
+      statement.executeBatch();
+
+      try (ResultSet resultSet = statement.executeQuery("select s1, s2 from root.sg.d1")) {
+
+        assertTrue(resultSet.next());
+        assertEquals(1, resultSet.getLong(1));
+        assertEquals(2.0F, resultSet.getObject(2));
+        assertEquals(2.0F, resultSet.getObject(3));
+
+        assertFalse(resultSet.next());
+      }
+
+      statement.execute("flush");
+      try (ResultSet resultSet = statement.executeQuery("select s1, s2 from root.sg.d1")) {
+
+        assertTrue(resultSet.next());
+        assertEquals(1, resultSet.getLong(1));
+        assertEquals(2.0F, resultSet.getObject(2));
+        assertEquals(2.0F, resultSet.getObject(3));
+
+        assertFalse(resultSet.next());
+      }
+    }
+  }
+
   @Test
   public void testInsertWithWrongMeasurementNum1() throws SQLException {
     try (Connection connection = EnvFactory.getEnv().getConnection();
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/memtable/AlignedWritableMemChunk.java b/server/src/main/java/org/apache/iotdb/db/engine/memtable/AlignedWritableMemChunk.java
index dabd3b472db..0bc71c3995d 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/memtable/AlignedWritableMemChunk.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/memtable/AlignedWritableMemChunk.java
@@ -315,17 +315,16 @@ public class AlignedWritableMemChunk implements IWritableMemChunk {
     int range = 0;
     for (int sortedRowIndex = 0; sortedRowIndex < list.rowCount(); sortedRowIndex++) {
       long time = list.getTime(sortedRowIndex);
+      if (range == 0) {
+        pageRange.add(sortedRowIndex);
+      }
+      range++;
+      if (range == maxNumberOfPointsInPage) {
+        pageRange.add(sortedRowIndex);
+        range = 0;
+      }
 
-      if (sortedRowIndex == list.rowCount() - 1 || time != list.getTime(sortedRowIndex + 1)) {
-        if (range == 0) {
-          pageRange.add(sortedRowIndex);
-        }
-        range++;
-        if (range == maxNumberOfPointsInPage) {
-          pageRange.add(sortedRowIndex);
-          range = 0;
-        }
-      } else {
+      if (sortedRowIndex != list.rowCount() - 1 && time == list.getTime(sortedRowIndex + 1)) {
         if (Objects.isNull(timeDuplicateInfo)) {
           timeDuplicateInfo = new boolean[list.rowCount()];
         }