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

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

commit 957fa4c50237f7f96bfd5bc532ae43d48a8f12ac
Author: HTHou <[email protected]>
AuthorDate: Tue May 30 10:27:53 2023 +0800

    [To rel/1.1][IOTDB-5905] Fix aligned timeseries data point lost after 
flushed in some scenario
---
 .../db/it/aligned/IoTDBInsertAlignedValuesIT.java  | 31 ++++++++++++++++++++++
 .../engine/memtable/AlignedWritableMemChunk.java   | 19 +++++++------
 2 files changed, 40 insertions(+), 10 deletions(-)

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()];
         }

Reply via email to