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/09 06:14:16 UTC

[GitHub] [iotdb] qiaojialin commented on a diff in pull request #5807: [IOTDB-3097] PartitionInfo snapshot interface

qiaojialin commented on code in PR #5807:
URL: https://github.com/apache/iotdb/pull/5807#discussion_r867660607


##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/PartitionInfo.java:
##########
@@ -298,15 +321,142 @@ public List<TRegionReplicaSet> getRegionReplicaSets(List<TConsensusGroupId> grou
     return result;
   }
 
-  public void serialize(ByteBuffer buffer) {
-    // TODO: Serialize PartitionInfo
+  public boolean takeSnapshot(File snapshotDir) throws TException, IOException {
+
+    File snapshotFile = new File(snapshotDir, snapshotFileName);
+    if (snapshotFile.exists() && snapshotFile.isFile()) {
+      LOGGER.error(
+          "Failed to take snapshot, because snapshot file [{}] is already exist.",
+          snapshotFile.getAbsolutePath());
+      return false;
+    }
+
+    File tmpFile = new File(snapshotFile.getAbsolutePath() + "-" + UUID.randomUUID());
+
+    lockAllRead();
+    ByteBuffer byteBuffer = ByteBuffer.allocate(bufferSize);
+    try {
+      // first, put nextRegionGroupId

Review Comment:
   ```suggestion
         // put nextRegionGroupId
   ```



##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/PartitionInfo.java:
##########
@@ -298,15 +321,142 @@ public List<TRegionReplicaSet> getRegionReplicaSets(List<TConsensusGroupId> grou
     return result;
   }
 
-  public void serialize(ByteBuffer buffer) {
-    // TODO: Serialize PartitionInfo
+  public boolean takeSnapshot(File snapshotDir) throws TException, IOException {
+
+    File snapshotFile = new File(snapshotDir, snapshotFileName);
+    if (snapshotFile.exists() && snapshotFile.isFile()) {
+      LOGGER.error(
+          "Failed to take snapshot, because snapshot file [{}] is already exist.",
+          snapshotFile.getAbsolutePath());
+      return false;
+    }
+
+    File tmpFile = new File(snapshotFile.getAbsolutePath() + "-" + UUID.randomUUID());
+
+    lockAllRead();
+    ByteBuffer byteBuffer = ByteBuffer.allocate(bufferSize);
+    try {
+      // first, put nextRegionGroupId
+      byteBuffer.putInt(nextRegionGroupId.get());
+      // second, put regionMap

Review Comment:
   ```suggestion
         // put regionMap
   ```



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