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

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


The following commit(s) were added to refs/heads/master by this push:
     new c28c357ffd1 Fix view snapshot recovery (#10371)
c28c357ffd1 is described below

commit c28c357ffd1ffbf438104586ddcf29dfd25ef9ea
Author: Marcos_Zyk <[email protected]>
AuthorDate: Thu Jun 29 14:21:20 2023 +0800

    Fix view snapshot recovery (#10371)
---
 .../impl/mem/snapshot/MemMTreeSnapshotUtil.java    | 37 +++++++++++-----------
 .../iotdb/tsfile/utils/ReadWriteIOUtils.java       | 11 +++++++
 2 files changed, 30 insertions(+), 18 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/mem/snapshot/MemMTreeSnapshotUtil.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/mem/snapshot/MemMTreeSnapshotUtil.java
index 35c9eb3dcd7..cdc6b856eed 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/mem/snapshot/MemMTreeSnapshotUtil.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/mem/snapshot/MemMTreeSnapshotUtil.java
@@ -339,23 +339,21 @@ public class MemMTreeSnapshotUtil {
     public Boolean visitMeasurementMNode(
         AbstractMeasurementMNode<?, ? extends IMNode<?>> node, OutputStream 
outputStream) {
       try {
-        if (node.isMeasurement()) {
-          if (node.isLogicalView()) {
-            ReadWriteIOUtils.write(LOGICAL_VIEW_MNODE_TYPE, outputStream);
-            ReadWriteIOUtils.write(node.getName(), outputStream);
-            node.getSchema().serializeTo(outputStream);
-          } else {
-            ReadWriteIOUtils.write(MEASUREMENT_MNODE_TYPE, outputStream);
-            ReadWriteIOUtils.write(node.getName(), outputStream);
-            node.getSchema().serializeTo(outputStream);
-            ReadWriteIOUtils.write(node.getAlias(), outputStream);
-            ReadWriteIOUtils.write(node.getOffset(), outputStream);
-            ReadWriteIOUtils.write(node.isPreDeleted(), outputStream);
-          }
-          return true;
+        if (node.isLogicalView()) {
+          ReadWriteIOUtils.write(LOGICAL_VIEW_MNODE_TYPE, outputStream);
+          ReadWriteIOUtils.write(node.getName(), outputStream);
+          node.getSchema().serializeTo(outputStream);
+          ReadWriteIOUtils.write(node.getOffset(), outputStream);
+          ReadWriteIOUtils.write(node.isPreDeleted(), outputStream);
+        } else {
+          ReadWriteIOUtils.write(MEASUREMENT_MNODE_TYPE, outputStream);
+          ReadWriteIOUtils.write(node.getName(), outputStream);
+          node.getSchema().serializeTo(outputStream);
+          ReadWriteIOUtils.write(node.getAlias(), outputStream);
+          ReadWriteIOUtils.write(node.getOffset(), outputStream);
+          ReadWriteIOUtils.write(node.isPreDeleted(), outputStream);
         }
-        throw new IllegalArgumentException(
-            "visitMeasurementMNode got unknown node type" + 
node.getMNodeType(false).toString());
+        return true;
       } catch (Exception e) {
         logger.error(SERIALIZE_ERROR_INFO, e);
         return false;
@@ -392,7 +390,7 @@ public class MemMTreeSnapshotUtil {
       IMemMNode node = nodeFactory.createDatabaseDeviceMNode(null, name, 0);
       
node.getAsDeviceMNode().setSchemaTemplateId(ReadWriteIOUtils.readInt(inputStream));
       
node.getAsDeviceMNode().setUseTemplate(ReadWriteIOUtils.readBool(inputStream));
-      
node.getAsDeviceMNode().setAligned(ReadWriteIOUtils.readBool(inputStream));
+      
node.getAsDeviceMNode().setAligned(ReadWriteIOUtils.readBoolObject(inputStream));
       return node;
     }
 
@@ -401,7 +399,7 @@ public class MemMTreeSnapshotUtil {
       IDeviceMNode<IMemMNode> node = nodeFactory.createDeviceMNode(null, name);
       node.setSchemaTemplateId(ReadWriteIOUtils.readInt(inputStream));
       node.setUseTemplate(ReadWriteIOUtils.readBool(inputStream));
-      node.setAligned(ReadWriteIOUtils.readBool(inputStream));
+      node.setAligned(ReadWriteIOUtils.readBoolObject(inputStream));
       return node.getAsMNode();
     }
 
@@ -420,8 +418,11 @@ public class MemMTreeSnapshotUtil {
     public IMemMNode deserializeLogicalViewMNode(InputStream inputStream) 
throws IOException {
       String name = ReadWriteIOUtils.readString(inputStream);
       LogicalViewSchema logicalViewSchema = 
LogicalViewSchema.deserializeFrom(inputStream);
+      long tagOffset = ReadWriteIOUtils.readLong(inputStream);
       IMeasurementMNode<IMemMNode> node =
           nodeFactory.createLogicalViewMNode(null, name, new 
LogicalViewInfo(logicalViewSchema));
+      node.setOffset(tagOffset);
+      node.setPreDeleted(ReadWriteIOUtils.readBool(inputStream));
       return node.getAsMNode();
     }
   }
diff --git 
a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/utils/ReadWriteIOUtils.java
 
b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/utils/ReadWriteIOUtils.java
index cb9bc523512..29be98ca7e3 100644
--- 
a/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/utils/ReadWriteIOUtils.java
+++ 
b/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/utils/ReadWriteIOUtils.java
@@ -106,6 +106,17 @@ public class ReadWriteIOUtils {
     return null;
   }
 
+  /** read a Boolean from byteBuffer. */
+  public static Boolean readBoolObject(InputStream inputStream) throws 
IOException {
+    int flag = inputStream.read();
+    if (flag == 1) {
+      return true;
+    } else if (flag == 0) {
+      return false;
+    }
+    return null;
+  }
+
   /** read a byte from byteBuffer. */
   public static byte readByte(ByteBuffer buffer) {
     return buffer.get();

Reply via email to