mychaow commented on a change in pull request #1721: URL: https://github.com/apache/incubator-iotdb/pull/1721#discussion_r489903502
########## File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java ########## @@ -1002,48 +1004,57 @@ private void findNodes(MNode node, PartialPath path, List<PartialPath> res, int } public void serializeTo(String snapshotPath) throws IOException { - try (BufferedWriter bw = new BufferedWriter( - new FileWriter(SystemFileFactory.INSTANCE.getFile(snapshotPath)))) { - root.serializeTo(bw); + try (MLogWriter mLogWriter = new MLogWriter(snapshotPath)) { + root.serializeTo(mLogWriter); } } @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning public static MTree deserializeFrom(File mtreeSnapshot) { - try (BufferedReader br = new BufferedReader(new FileReader(mtreeSnapshot))) { - String s; + + try (MLogReader mlogReader = new MLogReader(mtreeSnapshot)) { Deque<MNode> nodeStack = new ArrayDeque<>(); MNode node = null; - while ((s = br.readLine()) != null) { - String[] nodeInfo = s.split(","); - short nodeType = Short.parseShort(nodeInfo[0]); - if (nodeType == MetadataConstant.STORAGE_GROUP_MNODE_TYPE) { - node = StorageGroupMNode.deserializeFrom(nodeInfo); - } else if (nodeType == MetadataConstant.MEASUREMENT_MNODE_TYPE) { - node = MeasurementMNode.deserializeFrom(nodeInfo); - } else { - node = new MNode(null, nodeInfo[1]); - } + while (mlogReader.hasNext()) { + PhysicalPlan plan = null; + try { + plan = mlogReader.next(); + if (plan == null) { + continue; + } + int childrenSize = 0; + if (plan instanceof StorageGroupMNodePlan) { + node = StorageGroupMNode.deserializeFrom((StorageGroupMNodePlan) plan); + childrenSize = ((StorageGroupMNodePlan) plan).getChildSize(); + } else if (plan instanceof MeasurementMNodePlan) { + node = MeasurementMNode.deserializeFrom((MeasurementMNodePlan) plan); + childrenSize = ((MeasurementMNodePlan) plan).getChildSize(); + } else if (plan instanceof MNodePlan) { + node = new MNode(null, ((MNodePlan) plan).getName()); + childrenSize = ((MNodePlan) plan).getChildSize(); + } Review comment: ok, I will do some tests. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org