You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/05/06 14:31:36 UTC

[GitHub] [iotdb] CRZbulabula commented on a diff in pull request #5816: [IOTDB-3098] ClusterSchemaInfo snapshot interface

CRZbulabula commented on code in PR #5816:
URL: https://github.com/apache/iotdb/pull/5816#discussion_r866886909


##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/ClusterSchemaInfo.java:
##########
@@ -330,12 +338,42 @@ public List<TConsensusGroupId> getRegionGroupIds(String storageGroup, TConsensus
     return result;
   }
 
-  public void serialize(ByteBuffer buffer) {
-    // TODO: Serialize ClusterSchemaInfo
+  @Override
+  public boolean takeSnapshot(File snapshotFile) throws IOException {
+
+    File tmpFile = new File(snapshotFile.getAbsolutePath() + "-" + UUID.randomUUID());
+    ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
+
+    storageGroupReadWriteLock.readLock().lock();
+    try {
+      try (FileOutputStream fileOutputStream = new FileOutputStream(tmpFile);
+          FileChannel fileChannel = fileOutputStream.getChannel()) {
+        mTree.serialize(buffer);
+        fileChannel.write(buffer);
+      }
+      return tmpFile.renameTo(snapshotFile);
+    } finally {
+      buffer.clear();
+      tmpFile.delete();
+      storageGroupReadWriteLock.readLock().unlock();
+    }
   }
 
-  public void deserialize(ByteBuffer buffer) {
-    // TODO: Deserialize ClusterSchemaInfo
+  @Override
+  public void loadSnapshot(File snapshotFile) throws IOException {

Review Comment:
   Don't forget to add test for loadSnapshot~



##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/ClusterSchemaInfo.java:
##########
@@ -330,12 +338,42 @@ public List<TConsensusGroupId> getRegionGroupIds(String storageGroup, TConsensus
     return result;
   }
 
-  public void serialize(ByteBuffer buffer) {
-    // TODO: Serialize ClusterSchemaInfo
+  @Override
+  public boolean takeSnapshot(File snapshotFile) throws IOException {

Review Comment:
   Don't forget to add test for takeSnapshot~



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org