You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by er...@apache.org on 2022/04/20 11:09:00 UTC

[iotdb] branch bugfix/iotdb-2965 updated (fa51be3e32 -> 9540a5e770)

This is an automated email from the ASF dual-hosted git repository.

ericpai pushed a change to branch bugfix/iotdb-2965
in repository https://gitbox.apache.org/repos/asf/iotdb.git


    omit fa51be3e32 [IOTDB-2965] Skip failed mlog and snapshot items when upgrading happens
     new 9540a5e770 [IOTDB-2965] Skip failed mlog and snapshot items when upgrading happens

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (fa51be3e32)
            \
             N -- N -- N   refs/heads/bugfix/iotdb-2965 (9540a5e770)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../db/metadata/upgrade/MetadataUpgrader.java      | 37 ++++++++++++----------
 .../db/metadata/upgrade/MetadataUpgradeTest.java   |  7 ++++
 2 files changed, 27 insertions(+), 17 deletions(-)


[iotdb] 01/01: [IOTDB-2965] Skip failed mlog and snapshot items when upgrading happens

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ericpai pushed a commit to branch bugfix/iotdb-2965
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 9540a5e77037d9b788168b02222f204715034627
Author: ericpai <er...@hotmail.com>
AuthorDate: Wed Apr 20 16:47:44 2022 +0800

    [IOTDB-2965] Skip failed mlog and snapshot items when upgrading happens
---
 .../db/metadata/upgrade/MetadataUpgrader.java      | 41 +++++++++++-----------
 .../db/metadata/upgrade/MetadataUpgradeTest.java   |  7 ++++
 2 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/upgrade/MetadataUpgrader.java b/server/src/main/java/org/apache/iotdb/db/metadata/upgrade/MetadataUpgrader.java
index d573353d61..0c6a10216a 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/upgrade/MetadataUpgrader.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/upgrade/MetadataUpgrader.java
@@ -109,12 +109,12 @@ public class MetadataUpgrader {
    *   <li>Try set storage group based on the recovered StorageGroupMNodes and create timeseries
    *       based on the recovered MeasurementMNode
    *   <li>Redo the mlog
-   *   <li>delete the files of version, the order is:
+   *   <li>rename and backup the files in the same directory, the order is:
    *       <ol>
-   *         <li>mlog
-   *         <li>snapshot
-   *         <li>tag file
-   *         <li>tmp snapshot
+   *         <li>mlog.bin to mlog.bin.bak
+   *         <li>mtree-1.snapshot.bin to mtree-1.snapshot.bin.bak
+   *         <li>tlog.txt to tlog.txt.bak
+   *         <li>mtree-1.snapshot.bin.tmp to mtree-1.snapshot.bin.tmp.bak
    *       </ol>
    * </ol>
    */
@@ -164,29 +164,32 @@ public class MetadataUpgrader {
       }
       return false;
     } else {
-      deleteFile(tagFile);
-      deleteFile(snapshotTmpFile);
-      deleteFile(snapshotFile);
-      deleteFile(mlogFile);
+      clearOldFiles();
       return true;
     }
   }
 
   public void clearOldFiles() throws IOException {
-    deleteFile(mlogFile);
-    deleteFile(snapshotFile);
-    deleteFile(tagFile);
-    deleteFile(snapshotTmpFile);
+    backupFile(mlogFile);
+    backupFile(snapshotFile);
+    backupFile(tagFile);
+    backupFile(snapshotTmpFile);
   }
 
-  private void deleteFile(File file) throws IOException {
+  private void backupFile(File file) throws IOException {
     if (!file.exists()) {
       return;
     }
-
-    if (!file.delete()) {
+    File backupFile = new File(file.getAbsolutePath() + ".bak");
+    if (backupFile.exists()) {
+      throw new IOException(
+          "The backup file "
+              + backupFile.getAbsolutePath()
+              + " has already existed, please remove it first");
+    }
+    if (!file.renameTo(backupFile)) {
       String errorMessage =
-          String.format("Cannot delete file %s during metadata upgrade", file.getName());
+          String.format("Cannot backup file %s during metadata upgrade", file.getName());
       logger.error(errorMessage);
       throw new IOException(errorMessage);
     }
@@ -231,8 +234,6 @@ public class MetadataUpgrader {
           }
         } catch (MetadataException e) {
           logger.error("Error occurred during recovering metadata from snapshot", e);
-          e.printStackTrace();
-          throw new IOException(e);
         }
       }
     }
@@ -331,8 +332,6 @@ public class MetadataUpgrader {
           }
         } catch (MetadataException e) {
           logger.error("Error occurred during redo mlog: ", e);
-          e.printStackTrace();
-          throw new IOException(e);
         }
       }
     }
diff --git a/server/src/test/java/org/apache/iotdb/db/metadata/upgrade/MetadataUpgradeTest.java b/server/src/test/java/org/apache/iotdb/db/metadata/upgrade/MetadataUpgradeTest.java
index 208419a65e..7bff1f29fa 100644
--- a/server/src/test/java/org/apache/iotdb/db/metadata/upgrade/MetadataUpgradeTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/metadata/upgrade/MetadataUpgradeTest.java
@@ -127,6 +127,13 @@ public class MetadataUpgradeTest {
     Assert.assertEquals(
         "root.test.sg3.d3",
         new ArrayList<>(schemaProcessor.getPathsUsingTemplate("template")).get(0));
+    Assert.assertTrue(
+        new File(schemaDirPath + File.separator + MetadataConstant.METADATA_LOG + ".bak").exists());
+    Assert.assertTrue(
+        new File(schemaDirPath + File.separator + MetadataConstant.TAG_LOG + ".bak").exists());
+    Assert.assertTrue(
+        new File(schemaDirPath + File.separator + MetadataConstant.MTREE_SNAPSHOT + ".bak")
+            .exists());
   }
 
   private void prepareMLog() throws Exception {