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 2020/11/09 04:22:03 UTC

[GitHub] [iotdb] neuyilan commented on a change in pull request #1956: [Distributed] bug fix, remove the persist logs when follower receives a snapshot

neuyilan commented on a change in pull request #1956:
URL: https://github.com/apache/iotdb/pull/1956#discussion_r519545236



##########
File path: cluster/src/main/java/org/apache/iotdb/cluster/log/manage/serializable/SyncLogDequeSerializer.java
##########
@@ -835,6 +834,59 @@ public void close() {
     }
   }
 
+  @Override
+  public void clearAllLogs(long commitIndex) {
+    lock.writeLock().lock();
+    try {
+      // 1. delete
+      forceFlushLogBuffer();
+      closeCurrentFile(meta.getCommitLogIndex());
+      for (int i = 0; i < logDataFileList.size(); i++) {
+        deleteLogDataAndIndexFile(i);
+      }
+      deleteMetaFile();
+
+      logDataFileList.clear();
+      logIndexFileList.clear();
+
+      // 2. init
+      if (!logIndexOffsetList.isEmpty()) {
+        this.firstLogIndex = Math
+            .max(commitIndex + 1, firstLogIndex + logIndexOffsetList.size());
+      } else {
+        this.firstLogIndex = commitIndex + 1;
+      }
+      this.logIndexOffsetList.clear();
+      recoverMetaFile();
+      meta = new LogManagerMeta();
+      createNewLogFile(logDir, firstLogIndex);
+      logger.info("{}, clean all logs success, the new firstLogIndex={}", this, firstLogIndex);
+    } catch (IOException e) {
+      logger.error("clear all logs failed,", e);
+    } finally {
+      lock.writeLock().unlock();
+    }
+  }
+
+  private void deleteMetaFile() {
+    lock.writeLock().lock();
+    try {
+      File tmpMetaFile = SystemFileFactory.INSTANCE.getFile(logDir + "logMeta.tmp");
+      if (tmpMetaFile.exists()) {
+        Files.delete(tmpMetaFile.toPath());
+      }

Review comment:
       got it, thanks




----------------------------------------------------------------
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:
users@infra.apache.org