You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by yu...@apache.org on 2020/07/28 15:19:04 UTC

[incubator-iotdb] branch kyy updated: ignore tail in bytebuffer

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

yuyuankang pushed a commit to branch kyy
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/kyy by this push:
     new c38060c  ignore tail in bytebuffer
c38060c is described below

commit c38060c107ba163ef54bedaec83309388ff9ba38
Author: Ring-k <yu...@hotmail.com>
AuthorDate: Tue Jul 28 23:18:37 2020 +0800

    ignore tail in bytebuffer
---
 .../log/manage/serializable/SyncLogDequeSerializer.java       | 11 ++++++++---
 .../java/org/apache/iotdb/tsfile/utils/ReadWriteIOUtils.java  |  7 +++++++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/log/manage/serializable/SyncLogDequeSerializer.java b/cluster/src/main/java/org/apache/iotdb/cluster/log/manage/serializable/SyncLogDequeSerializer.java
index 4ef9787..d770e3d 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/log/manage/serializable/SyncLogDequeSerializer.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/log/manage/serializable/SyncLogDequeSerializer.java
@@ -198,13 +198,18 @@ public class SyncLogDequeSerializer implements StableEntryManager {
   private void putLogs(List<Log> entries) {
     for (Log log : entries) {
       logBuffer.mark();
+      ByteBuffer logData = log.serialize();
       try {
-        logBuffer.put(log.serialize());
+        int size = logData.capacity() + Integer.BYTES;
+        logSizeDeque.addLast(size);
+        logBuffer.putInt(logData.capacity());
+        logBuffer.put(logData);
       } catch (BufferOverflowException e) {
         logger.info("Raft log buffer overflow!");
         logBuffer.reset();
         flushLogBuffer();
-        logBuffer.put(log.serialize());
+        logBuffer.putInt(logData.capacity());
+        logBuffer.put(logData);
       }
       bufferedLogNum++;
     }
@@ -222,7 +227,7 @@ public class SyncLogDequeSerializer implements StableEntryManager {
       // write into disk
       try {
         checkStream();
-        ReadWriteIOUtils.writeWithoutSize(logBuffer, currentLogOutputStream);
+        ReadWriteIOUtils.writeWithoutSize(logBuffer, 0, logBuffer.position(), currentLogOutputStream);
       } catch (IOException e) {
         logger.error("Error in logs serialization: ", e);
         return;
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/utils/ReadWriteIOUtils.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/utils/ReadWriteIOUtils.java
index e11f871..0ab9228 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/utils/ReadWriteIOUtils.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/utils/ReadWriteIOUtils.java
@@ -370,6 +370,13 @@ public class ReadWriteIOUtils {
     return bytes.length;
   }
 
+  public static int writeWithoutSize(ByteBuffer byteBuffer, int offset, int len,
+      OutputStream outputStream) throws IOException {
+    byte[] bytes = byteBuffer.array();
+    outputStream.write(bytes, 0, len);
+    return len;
+  }
+
   /**
    * write byteBuffer.capacity and byteBuffer.array to byteBuffer.
    */