You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by an...@apache.org on 2020/01/05 21:18:36 UTC

[zookeeper] branch branch-3.5 updated: ZOOKEEPER-3644: cherry pick PR 1177 to branch-3.5

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

andor pushed a commit to branch branch-3.5
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/branch-3.5 by this push:
     new a314855  ZOOKEEPER-3644: cherry pick PR 1177 to branch-3.5
a314855 is described below

commit a314855f0733c620dd1c690f05c13fafd9a1a1c4
Author: Michael Han <ha...@apache.org>
AuthorDate: Sun Jan 5 22:18:27 2020 +0100

    ZOOKEEPER-3644: cherry pick PR 1177 to branch-3.5
    
    Author: Michael Han <ha...@apache.org>
    
    Reviewers: eolivelli@apache.org, andor@apache.org
    
    Closes #1182 from hanm/ZOOKEEPER-3644
---
 .../server/persistence/FileTxnSnapLog.java         | 24 ++++++++++++++++++++--
 .../test/EmptiedSnapshotRecoveryTest.java          |  6 ++++--
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
index 47d8799..3939231 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
@@ -82,6 +82,18 @@ public class FileTxnSnapLog {
     }
 
     /**
+     * Finalizing restore of data tree through
+     * a set of operations (replaying transaction logs,
+     * calculating data tree digests, and so on.).
+     */
+    private interface RestoreFinalizer {
+        /**
+         * @return the highest zxid of restored data tree.
+         */
+        long run() throws IOException;
+    }
+
+    /**
      * the constructor which takes the datadir and
      * snapdir.
      * @param dataDir the transaction directory
@@ -212,6 +224,12 @@ public class FileTxnSnapLog {
                         PlayBackListener listener) throws IOException {
         long deserializeResult = snapLog.deserialize(dt, sessions);
         FileTxnLog txnLog = new FileTxnLog(dataDir);
+
+        RestoreFinalizer finalizer = () -> {
+            long highestZxid = fastForwardFromEdits(dt, sessions, listener);
+            return highestZxid;
+        };
+
         if (-1L == deserializeResult) {
             /* this means that we couldn't find any snapshot, so we need to
              * initialize an empty database (reported in ZOOKEEPER-2325) */
@@ -221,7 +239,8 @@ public class FileTxnSnapLog {
                 if (!trustEmptySnapshot) {
                     throw new IOException(EMPTY_SNAPSHOT_WARNING + "Something is broken!");
                 } else {
-                    LOG.warn(EMPTY_SNAPSHOT_WARNING + "This should only be allowed during upgrading.");
+                    LOG.warn("{}This should only be allowed during upgrading.", EMPTY_SNAPSHOT_WARNING);
+                    return finalizer.run();
                 }
             }
             /* TODO: (br33d) we should either put a ConcurrentHashMap on restore()
@@ -230,7 +249,8 @@ public class FileTxnSnapLog {
             /* return a zxid of zero, since we the database is empty */
             return 0;
         }
-        return fastForwardFromEdits(dt, sessions, listener);
+
+        return finalizer.run();
     }
 
     /**
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/EmptiedSnapshotRecoveryTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/EmptiedSnapshotRecoveryTest.java
index 9cb91bb..2ff750e 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/EmptiedSnapshotRecoveryTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/EmptiedSnapshotRecoveryTest.java
@@ -18,8 +18,9 @@
 
 package org.apache.zookeeper.test;
 
-import java.io.IOException;
+import static org.junit.Assert.assertEquals;
 import java.io.File;
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.List;
 
@@ -102,10 +103,11 @@ public class EmptiedSnapshotRecoveryTest extends ZKTestCase implements  Watcher
         zks = new ZooKeeperServer(tmpSnapDir, tmpLogDir, 3000);
         try {
             zks.startdata();
-            zxid = zks.getZKDatabase().loadDataBase();
+            long currentZxid = zks.getZKDatabase().getDataTreeLastProcessedZxid();
             if (!trustEmptySnap) {
                 Assert.fail("Should have gotten exception for corrupted database");
             }
+            assertEquals("zxid mismatch after restoring database", currentZxid, zxid);
         } catch (IOException e) {
             // expected behavior
             if (trustEmptySnap) {