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

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


The following commit(s) were added to refs/heads/serialize-physicalplan by this 
push:
     new 5938242  fix some issues accoring to reviews
5938242 is described below

commit 5938242986c7f843b38cbb8cd9dc30691b84b385
Author: lta <[email protected]>
AuthorDate: Thu Mar 28 13:47:29 2019 +0800

    fix some issues accoring to reviews
---
 .../iotdb/db/qp/logical/sys/AuthorOperator.java    |  3 +-
 .../iotdb/db/qp/logical/sys/MetadataOperator.java  |  3 +-
 .../iotdb/db/writelog/transfer/CodecInstances.java | 50 ++++++++--------------
 3 files changed, 22 insertions(+), 34 deletions(-)

diff --git 
a/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/AuthorOperator.java 
b/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/AuthorOperator.java
index b2bb858..7f33541 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/AuthorOperator.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/AuthorOperator.java
@@ -19,7 +19,6 @@
 package org.apache.iotdb.db.qp.logical.sys;
 
 import org.apache.iotdb.db.qp.logical.RootOperator;
-import org.apache.iotdb.db.qp.logical.sys.MetadataOperator.NamespaceType;
 import org.apache.iotdb.tsfile.read.common.Path;
 
 /**
@@ -204,7 +203,7 @@ public class AuthorOperator extends RootOperator {
           return 15;
         case LIST_ROLE_USERS:
           return 16;
-          default:
+        default:
           return -1;
       }
     }
diff --git 
a/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/MetadataOperator.java 
b/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/MetadataOperator.java
index 057e011..a0e81b0 100644
--- 
a/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/MetadataOperator.java
+++ 
b/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/MetadataOperator.java
@@ -144,8 +144,9 @@ public class MetadataOperator extends RootOperator {
         case DELETE_PATH:
           return 1;
         case SET_FILE_LEVEL:
+          return 2;
         default:
-          return 0;
+          return -1;
       }
     }
   }
diff --git 
a/iotdb/src/main/java/org/apache/iotdb/db/writelog/transfer/CodecInstances.java 
b/iotdb/src/main/java/org/apache/iotdb/db/writelog/transfer/CodecInstances.java
index c3851d1..2b700e1 100644
--- 
a/iotdb/src/main/java/org/apache/iotdb/db/writelog/transfer/CodecInstances.java
+++ 
b/iotdb/src/main/java/org/apache/iotdb/db/writelog/transfer/CodecInstances.java
@@ -84,6 +84,19 @@ public class CodecInstances {
       return null;
     return ReadWriteIOUtils.readStringWithoutLength(buffer, valueLen);
   }
+
+  /**
+   * Check if ByteBuffer is initialized and put type
+   */
+  static void checkBufferAndPutType(ThreadLocal<ByteBuffer> localBuffer, int 
type) {
+    if (localBuffer.get() == null) {
+      localBuffer.set(ByteBuffer.allocate(config.getMaxLogEntrySize()));
+    }
+
+    ByteBuffer buffer = localBuffer.get();
+    buffer.clear();
+    buffer.put((byte) type);
+  }
   
   static final Codec<DeletePlan> deletePlanCodec = new Codec<DeletePlan>() {
     ThreadLocal<ByteBuffer> localBuffer = new ThreadLocal<>();
@@ -122,13 +135,8 @@ public class CodecInstances {
     @Override
     public byte[] encode(UpdatePlan updatePlan) {
       int type = SystemLogOperator.UPDATE;
-      if (localBuffer.get() == null) {
-        localBuffer.set(ByteBuffer.allocate(config.getMaxLogEntrySize()));
-      }
-
+      checkBufferAndPutType(localBuffer, type);
       ByteBuffer buffer = localBuffer.get();
-      buffer.clear();
-      buffer.put((byte) type);
       buffer.putInt(updatePlan.getIntervals().size());
       for (Pair<Long, Long> pair : updatePlan.getIntervals()) {
         buffer.putLong(pair.left);
@@ -167,12 +175,8 @@ public class CodecInstances {
     @Override
     public byte[] encode(InsertPlan plan) {
       int type = SystemLogOperator.INSERT;
-      if (localBuffer.get() == null) {
-        localBuffer.set(ByteBuffer.allocate(config.getMaxLogEntrySize()));
-      }
+      checkBufferAndPutType(localBuffer, type);
       ByteBuffer buffer = localBuffer.get();
-      buffer.clear();
-      buffer.put((byte) type);
       buffer.put((byte) plan.getInsertType());
       buffer.putLong(plan.getTime());
 
@@ -227,12 +231,8 @@ public class CodecInstances {
     @Override
     public byte[] encode(MetadataPlan plan) {
       int type = SystemLogOperator.METADATA;
-      if (localBuffer.get() == null) {
-        localBuffer.set(ByteBuffer.allocate(config.getMaxLogEntrySize()));
-      }
+      checkBufferAndPutType(localBuffer, type);
       ByteBuffer buffer = localBuffer.get();
-      buffer.clear();
-      buffer.put((byte) type);
 
       MetadataOperator.NamespaceType namespaceType = plan.getNamespaceType();
       if (namespaceType != null) {
@@ -350,12 +350,8 @@ public class CodecInstances {
     @Override
     public byte[] encode(AuthorPlan plan) {
       int type = SystemLogOperator.AUTHOR;
-      if (localBuffer.get() == null) {
-        localBuffer.set(ByteBuffer.allocate(config.getMaxLogEntrySize()));
-      }
+      checkBufferAndPutType(localBuffer, type);
       ByteBuffer buffer = localBuffer.get();
-      buffer.clear();
-      buffer.put((byte) type);
 
       int authorType = plan.getAuthorType().serialize();
       buffer.put((byte) authorType);
@@ -416,12 +412,8 @@ public class CodecInstances {
     @Override
     public byte[] encode(LoadDataPlan plan) {
       int type = SystemLogOperator.LOADDATA;
-      if (localBuffer.get() == null) {
-        localBuffer.set(ByteBuffer.allocate(config.getMaxLogEntrySize()));
-      }
+      checkBufferAndPutType(localBuffer, type);
       ByteBuffer buffer = localBuffer.get();
-      buffer.clear();
-      buffer.put((byte) type);
 
       putString(buffer, plan.getInputFilePath());
       putString(buffer, plan.getMeasureType());
@@ -447,12 +439,8 @@ public class CodecInstances {
     @Override
     public byte[] encode(PropertyPlan plan) {
       int type = SystemLogOperator.PROPERTY;
-      if (localBuffer.get() == null) {
-        localBuffer.set(ByteBuffer.allocate(config.getMaxLogEntrySize()));
-      }
+      checkBufferAndPutType(localBuffer, type);
       ByteBuffer buffer = localBuffer.get();
-      buffer.clear();
-      buffer.put((byte) type);
 
       int propertyType = plan.getPropertyType().serialize();
       buffer.put((byte) propertyType);

Reply via email to