You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by zy...@apache.org on 2023/03/09 02:20:23 UTC
[iotdb] 02/02: [To rel/1.1][IOTDB-5240] Fix ConfigMTree snapshot deserialization while using template (#9248)
This is an automated email from the ASF dual-hosted git repository.
zyk pushed a commit to branch rc/1.1.0
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit c9008d7c49ff41ba37fcb2d7af74a05dd6f8a591
Author: Marcos_Zyk <38...@users.noreply.github.com>
AuthorDate: Thu Mar 9 10:04:21 2023 +0800
[To rel/1.1][IOTDB-5240] Fix ConfigMTree snapshot deserialization while using template (#9248)
---
.../iotdb/db/metadata/mtree/ConfigMTree.java | 37 ++++++++++++++--------
.../iotdb/db/metadata/mtree/ConfigMTreeTest.java | 3 ++
2 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/ConfigMTree.java b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/ConfigMTree.java
index 8c2649018c..1f08e42efb 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/ConfigMTree.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/ConfigMTree.java
@@ -636,19 +636,23 @@ public class ConfigMTree {
public void deserialize(InputStream inputStream) throws IOException {
byte type = ReadWriteIOUtils.readByte(inputStream);
- if (type != STORAGE_GROUP_MNODE_TYPE) {
- logger.error("Wrong node type. Cannot deserialize MTreeAboveSG from given buffer");
- return;
- }
- StorageGroupMNode storageGroupMNode = deserializeStorageGroupMNode(inputStream);
+ String name = null;
+ int childNum = 0;
+ Stack<Pair<InternalMNode, Boolean>> stack = new Stack<>();
+ StorageGroupMNode storageGroupMNode;
InternalMNode internalMNode;
- Stack<InternalMNode> stack = new Stack<>();
- stack.push(storageGroupMNode);
-
- String name = storageGroupMNode.getName();
- int childNum = 0;
+ if (type == STORAGE_GROUP_MNODE_TYPE) {
+ storageGroupMNode = deserializeStorageGroupMNode(inputStream);
+ name = storageGroupMNode.getName();
+ stack.push(new Pair<>(storageGroupMNode, true));
+ } else {
+ internalMNode = deserializeInternalMNode(inputStream);
+ childNum = ReadWriteIOUtils.readInt(inputStream);
+ name = internalMNode.getName();
+ stack.push(new Pair<>(internalMNode, false));
+ }
while (!PATH_ROOT.equals(name)) {
type = ReadWriteIOUtils.readByte(inputStream);
@@ -656,17 +660,22 @@ public class ConfigMTree {
case INTERNAL_MNODE_TYPE:
internalMNode = deserializeInternalMNode(inputStream);
childNum = ReadWriteIOUtils.readInt(inputStream);
+ boolean hasDB = false;
while (childNum > 0) {
- internalMNode.addChild(stack.pop());
+ hasDB = stack.peek().right;
+ internalMNode.addChild(stack.pop().left);
childNum--;
}
- stack.push(internalMNode);
+ stack.push(new Pair<>(internalMNode, hasDB));
name = internalMNode.getName();
break;
case STORAGE_GROUP_MNODE_TYPE:
storageGroupMNode = deserializeStorageGroupMNode(inputStream);
childNum = 0;
- stack.push(storageGroupMNode);
+ while (!stack.isEmpty() && !stack.peek().right) {
+ storageGroupMNode.addChild(stack.pop().left);
+ }
+ stack.push(new Pair<>(storageGroupMNode, true));
name = storageGroupMNode.getName();
break;
default:
@@ -674,7 +683,7 @@ public class ConfigMTree {
return;
}
}
- this.root = stack.peek();
+ this.root = stack.peek().left;
}
private InternalMNode deserializeInternalMNode(InputStream inputStream) throws IOException {
diff --git a/server/src/test/java/org/apache/iotdb/db/metadata/mtree/ConfigMTreeTest.java b/server/src/test/java/org/apache/iotdb/db/metadata/mtree/ConfigMTreeTest.java
index ee4a8a3689..53bb7e3432 100644
--- a/server/src/test/java/org/apache/iotdb/db/metadata/mtree/ConfigMTreeTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/metadata/mtree/ConfigMTreeTest.java
@@ -261,6 +261,7 @@ public class ConfigMTreeTest {
storageGroupMNode.setDataReplicationFactor(i);
storageGroupMNode.setSchemaReplicationFactor(i);
storageGroupMNode.setTimePartitionInterval(i);
+ root.getNodeWithAutoCreate(pathList[i].concatNode("a")).setSchemaTemplateId(i);
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@@ -277,6 +278,8 @@ public class ConfigMTreeTest {
Assert.assertEquals(i, storageGroupSchema.getSchemaReplicationFactor());
Assert.assertEquals(i, storageGroupSchema.getDataReplicationFactor());
Assert.assertEquals(i, storageGroupSchema.getTimePartitionInterval());
+ Assert.assertEquals(
+ i, newTree.getNodeWithAutoCreate(pathList[i].concatNode("a")).getSchemaTemplateId());
}
Assert.assertEquals(