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/08/08 01:58:36 UTC

[GitHub] [iotdb] THUMarkLau commented on a diff in pull request #6782: [IOTDB-3771] Fix cannot take snapshot when the data dir and snapshot dir is on different disk

THUMarkLau commented on code in PR #6782:
URL: https://github.com/apache/iotdb/pull/6782#discussion_r939766140


##########
server/src/main/java/org/apache/iotdb/db/engine/snapshot/SnapshotLogger.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.engine.snapshot;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+
+public class SnapshotLogger implements AutoCloseable {
+  public static final String SNAPSHOT_LOG_NAME = "snapshot.log";
+  public static final String SPLIT_CHAR = "#";
+
+  private File logFile;
+  private BufferedOutputStream os;
+
+  public SnapshotLogger(File logFile) throws FileNotFoundException {
+    this.logFile = logFile;
+    os = new BufferedOutputStream(new FileOutputStream(logFile));
+  }
+
+  @Override
+  public void close() throws Exception {
+    os.close();
+  }
+
+  public void logFile(String sourceFile, String linkFile) throws IOException {
+    os.write(sourceFile.getBytes(StandardCharsets.UTF_8));
+    os.write(SPLIT_CHAR.getBytes(StandardCharsets.UTF_8));
+    os.write(linkFile.getBytes(StandardCharsets.UTF_8));
+    os.write("\n".getBytes(StandardCharsets.UTF_8));
+    os.flush();
+  }
+
+  public void logSnapshotType(SnapshotType type) throws IOException {
+    os.write(String.valueOf(type).getBytes(StandardCharsets.UTF_8));
+    os.write("\n".getBytes(StandardCharsets.UTF_8));
+    os.flush();
+  }
+
+  public void cleanUpWhenFailed() throws IOException {
+    os.close();
+    Files.delete(logFile.toPath());
+  }
+
+  public static enum SnapshotType {
+    LOCAL_DISK,
+    REMOTE_DISK

Review Comment:
   It is logged when taking snapshot in different disk.



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