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/08/03 08:31:48 UTC

[iotdb] branch iotdb_6098 created (now 9f78734ed94)

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

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


      at 9f78734ed94 [IOTDB-6098] Fix a possible flush error when using aligned timeseries

This branch includes the following new commits:

     new 9f78734ed94 [IOTDB-6098] Fix a possible flush error when using aligned timeseries

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[iotdb] 01/01: [IOTDB-6098] Fix a possible flush error when using aligned timeseries

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9f78734ed94016724f9e5b79b2ede9f3c57b1d9c
Author: HTHou <hh...@outlook.com>
AuthorDate: Thu Aug 3 16:31:32 2023 +0800

    [IOTDB-6098] Fix a possible flush error when using aligned timeseries
---
 .../db/it/aligned/IoTDBInsertAlignedValues2IT.java | 12 +++++
 .../iotdb/tsfile/write/page/TimePageWriter.java    |  4 +-
 .../tsfile/write/writer/TimeChunkWriterTest.java   | 55 ++++++++++++++++++++++
 3 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValues2IT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValues2IT.java
index 85a0e952394..331bd1cf3ff 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValues2IT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValues2IT.java
@@ -113,4 +113,16 @@ public class IoTDBInsertAlignedValues2IT {
       }
     }
   }
+
+  @Test
+  public void testInsertAlignedWithEmptyPage2() throws SQLException {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("insert into root.sg.d1(time, s1,s2) aligned values(1,'aa','bb')");
+      statement.execute("insert into root.sg.d1(time, s1,s2) aligned values(1,'aa','bb')");
+      statement.execute("insert into root.sg.d1(time, s1,s2) aligned values(1,'aa','bb')");
+      statement.execute("flush");
+      statement.execute("insert into root.sg.d1(time, s1,s2) aligned values(1,'aa','bb')");
+    }
+  }
 }
diff --git a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/write/page/TimePageWriter.java b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/write/page/TimePageWriter.java
index a865feeb629..ccaaf72c27d 100644
--- a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/write/page/TimePageWriter.java
+++ b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/write/page/TimePageWriter.java
@@ -71,7 +71,9 @@ public class TimePageWriter {
     for (int i = arrayOffset; i < batchSize + arrayOffset; i++) {
       timeEncoder.encode(timestamps[i], timeOut);
     }
-    statistics.update(timestamps, batchSize, arrayOffset);
+    if (batchSize != 0) {
+      statistics.update(timestamps, batchSize, arrayOffset);
+    }
   }
 
   /** flush all data remained in encoders. */
diff --git a/iotdb-core/tsfile/src/test/java/org/apache/iotdb/tsfile/write/writer/TimeChunkWriterTest.java b/iotdb-core/tsfile/src/test/java/org/apache/iotdb/tsfile/write/writer/TimeChunkWriterTest.java
index 8978c2e25cc..e2457b44652 100644
--- a/iotdb-core/tsfile/src/test/java/org/apache/iotdb/tsfile/write/writer/TimeChunkWriterTest.java
+++ b/iotdb-core/tsfile/src/test/java/org/apache/iotdb/tsfile/write/writer/TimeChunkWriterTest.java
@@ -107,4 +107,59 @@ public class TimeChunkWriterTest {
       fail();
     }
   }
+
+  @Test
+  public void testWrite3() {
+    Encoder timeEncoder = new PlainEncoder(TSDataType.INT64, 0);
+    TimeChunkWriter chunkWriter =
+        new TimeChunkWriter("c1", CompressionType.UNCOMPRESSED, TSEncoding.PLAIN, timeEncoder);
+    long[] times = new long[10];
+    for (int i = 0; i < 10; i++) {
+      times[i] = i + 1;
+    }
+    chunkWriter.write(times, 10, 0);
+    chunkWriter.sealCurrentPage();
+    for (int i = 0; i < 10; i++) {
+      times[i] = i + 11;
+    }
+    chunkWriter.write(times, 10, 0);
+    chunkWriter.sealCurrentPage();
+    assertEquals(2, chunkWriter.getNumOfPages());
+    // two pages with statistics size: (82 + 17) * 2 + chunk header size: 9
+    assertEquals(207L, chunkWriter.getCurrentChunkSize());
+
+    try {
+      TestTsFileOutput testTsFileOutput = new TestTsFileOutput();
+      TsFileIOWriter writer = new TsFileIOWriter(testTsFileOutput, true);
+      chunkWriter.writeAllPagesOfChunkToTsFile(writer);
+      PublicBAOS publicBAOS = testTsFileOutput.publicBAOS;
+      ByteBuffer buffer = ByteBuffer.wrap(publicBAOS.getBuf(), 0, publicBAOS.size());
+      assertEquals(MetaMarker.TIME_CHUNK_HEADER, ReadWriteIOUtils.readByte(buffer));
+      assertEquals("c1", ReadWriteIOUtils.readVarIntString(buffer));
+      assertEquals(198, ReadWriteForEncodingUtils.readUnsignedVarInt(buffer));
+      assertEquals(TSDataType.VECTOR.serialize(), ReadWriteIOUtils.readByte(buffer));
+      assertEquals(CompressionType.UNCOMPRESSED.serialize(), ReadWriteIOUtils.readByte(buffer));
+      assertEquals(TSEncoding.PLAIN.serialize(), ReadWriteIOUtils.readByte(buffer));
+      assertEquals(198, buffer.remaining());
+    } catch (IOException e) {
+      e.printStackTrace();
+      fail();
+    }
+  }
+
+  @Test
+  public void testWriteEmptyPage() {
+    Encoder timeEncoder = new PlainEncoder(TSDataType.INT64, 0);
+    TimeChunkWriter chunkWriter =
+        new TimeChunkWriter("c1", CompressionType.UNCOMPRESSED, TSEncoding.PLAIN, timeEncoder);
+    long[] times = new long[10];
+    for (int i = 0; i < 10; i++) {
+      times[i] = i + 1;
+    }
+    chunkWriter.write(times, 10, 0);
+    chunkWriter.sealCurrentPage();
+    chunkWriter.write(times, 0, 0);
+    chunkWriter.sealCurrentPage();
+    assertEquals(1, chunkWriter.getNumOfPages());
+  }
 }