samperson1997 commented on a change in pull request #1384: URL: https://github.com/apache/incubator-iotdb/pull/1384#discussion_r442064151
########## File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java ########## @@ -899,6 +914,70 @@ private void findNodes(MNode node, String path, List<String> res, int targetLeve } } + public int getSnapshotLineNumber() { + return snapshotLineNumber; + } + + public void serializeTo(String snapshotPath, int lineNumber) throws IOException { + try (BufferedWriter bw = new BufferedWriter( + new FileWriter(SystemFileFactory.INSTANCE.getFile(snapshotPath)))) { + bw.write(String.valueOf(lineNumber)); + bw.newLine(); + root.serializeTo(bw); + } + } + + public static MTree deserializeFrom(String mtreeSnapshotPath) throws IOException { + File mtreeSnapshot = SystemFileFactory.INSTANCE.getFile(mtreeSnapshotPath); + if (!mtreeSnapshot.exists()) { + return new MTree(); + } + + try (BufferedReader br = new BufferedReader(new FileReader(mtreeSnapshot))) { + int snapshotLineNumber = Integer.parseInt(br.readLine()); + String s; + 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]); + } + + int childrenSize = Integer.parseInt(nodeInfo[nodeInfo.length - 1]); + if (childrenSize == 0) { + nodeStack.push(node); + } else { + Map<String, MNode> childrenMap = new TreeMap<>(); Review comment: Fixed ---------------------------------------------------------------- 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