lvfangmin commented on a change in pull request #1059: [ZOOKEEPER-3512] Real
time data consistency check during broadcast time
URL: https://github.com/apache/zookeeper/pull/1059#discussion_r332662098
##########
File path:
zookeeper-server/src/main/java/org/apache/zookeeper/server/DataTree.java
##########
@@ -1668,8 +1702,56 @@ public void compareSnapshotDigests(long zxid) {
}
digestFromLoadedSnapshot = null;
} else if (digestFromLoadedSnapshot.zxid != 0 && zxid >
digestFromLoadedSnapshot.zxid) {
- LOG.error("Watching for zxid 0x{} during snapshot recovery, but it
wasn't found.",
- Long.toHexString(digestFromLoadedSnapshot.zxid));
+ RATE_LOGGER.rateLimitLog("The txn 0x{} of snapshot digest does not
"
+ + "exist.",
Long.toHexString(digestFromLoadedSnapshot.zxid));
+ }
+ }
+
+ /**
+ * Compares the digest of the tree with the digest present in transaction
digest.
+ * If there is any error, logs and alerts the watchers.
+ *
+ * @param header transaction header being applied
+ * @param txn transaction
+ * @param digest transaction digest
+ *
+ * @return false if digest in the txn doesn't match what we have now in
+ * the data tree
+ */
+ public boolean compareDigest(TxnHeader header, Record txn, TxnDigest
digest) {
+ long zxid = header.getZxid();
+
+ if (!DigestCalculator.digestEnabled() || digest == null) {
+ return true;
+ }
+ // do not compare digest if we're still in fuzzy state
+ if (digestFromLoadedSnapshot != null) {
+ return true;
+ }
+ // do not compare digest if there is digest version change
+ if (DigestCalculator.DIGEST_VERSION != digest.getVersion()) {
+ RATE_LOGGER.rateLimitLog("Digest version not the same on zxid.",
+ String.valueOf(zxid));
+ return true;
+ }
+
+ long logDigest = digest.getTreeDigest();
+ long actualDigest = getTreeDigest();
+ if (logDigest != actualDigest) {
+ reportDigestMismatch(zxid);
+ LOG.debug("Digest in log: {}, actual tree: {}", logDigest,
actualDigest);
+ if (firstMismatchTxn) {
+ LOG.error("First digest mismatch on txn: {}, {}, "
+ + "expected digest is {}, actual digest is {}, ",
+ header, txn, digest, actualDigest);
+ firstMismatchTxn = false;
+ }
+ return false;
+ } else {
+ RATE_LOGGER.flush();
Review comment:
To make sure we have a log summary up to the time when the digest matches
again.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services