|
@@ -85,9 +85,19 @@ public class FileTxnSnapLog {
|
|
* restored.
|
|
* restored.
|
|
*/
|
|
*/
|
|
public interface PlayBackListener {
|
|
public interface PlayBackListener {
|
|
-
|
|
|
|
void onTxnLoaded(TxnHeader hdr, Record rec);
|
|
void onTxnLoaded(TxnHeader hdr, Record rec);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 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;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -241,6 +251,23 @@ public class FileTxnSnapLog {
|
|
trustEmptyDB = autoCreateDB;
|
|
trustEmptyDB = autoCreateDB;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ RestoreFinalizer finalizer = () -> {
|
|
|
|
+ long highestZxid = fastForwardFromEdits(dt, sessions, listener);
|
|
|
|
+ // The snapshotZxidDigest will reset after replaying the txn of the
|
|
|
|
+ // zxid in the snapshotZxidDigest, if it's not reset to null after
|
|
|
|
+ // restoring, it means either there are not enough txns to cover that
|
|
|
|
+ // zxid or that txn is missing
|
|
|
|
+ DataTree.ZxidDigest snapshotZxidDigest = dt.getDigestFromLoadedSnapshot();
|
|
|
|
+ if (snapshotZxidDigest != null) {
|
|
|
|
+ LOG.warn(
|
|
|
|
+ "Highest txn zxid 0x{} is not covering the snapshot digest zxid 0x{}, "
|
|
|
|
+ + "which might lead to inconsistent state",
|
|
|
|
+ Long.toHexString(highestZxid),
|
|
|
|
+ Long.toHexString(snapshotZxidDigest.getZxid()));
|
|
|
|
+ }
|
|
|
|
+ return highestZxid;
|
|
|
|
+ };
|
|
|
|
+
|
|
if (-1L == deserializeResult) {
|
|
if (-1L == deserializeResult) {
|
|
/* this means that we couldn't find any snapshot, so we need to
|
|
/* this means that we couldn't find any snapshot, so we need to
|
|
* initialize an empty database (reported in ZOOKEEPER-2325) */
|
|
* initialize an empty database (reported in ZOOKEEPER-2325) */
|
|
@@ -251,6 +278,7 @@ public class FileTxnSnapLog {
|
|
throw new IOException(EMPTY_SNAPSHOT_WARNING + "Something is broken!");
|
|
throw new IOException(EMPTY_SNAPSHOT_WARNING + "Something is broken!");
|
|
} else {
|
|
} else {
|
|
LOG.warn("{}This should only be allowed during upgrading.", EMPTY_SNAPSHOT_WARNING);
|
|
LOG.warn("{}This should only be allowed during upgrading.", EMPTY_SNAPSHOT_WARNING);
|
|
|
|
+ return finalizer.run();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -269,20 +297,7 @@ public class FileTxnSnapLog {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- long highestZxid = fastForwardFromEdits(dt, sessions, listener);
|
|
|
|
- // The snapshotZxidDigest will reset after replaying the txn of the
|
|
|
|
- // zxid in the snapshotZxidDigest, if it's not reset to null after
|
|
|
|
- // restoring, it means either there are not enough txns to cover that
|
|
|
|
- // zxid or that txn is missing
|
|
|
|
- DataTree.ZxidDigest snapshotZxidDigest = dt.getDigestFromLoadedSnapshot();
|
|
|
|
- if (snapshotZxidDigest != null) {
|
|
|
|
- LOG.warn(
|
|
|
|
- "Highest txn zxid 0x{} is not covering the snapshot digest zxid 0x{}, "
|
|
|
|
- + "which might lead to inconsistent state",
|
|
|
|
- Long.toHexString(highestZxid),
|
|
|
|
- Long.toHexString(snapshotZxidDigest.getZxid()));
|
|
|
|
- }
|
|
|
|
- return highestZxid;
|
|
|
|
|
|
+ return finalizer.run();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|