Github user eribeiro commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/632#discussion_r224206365
  
    --- Diff: 
zookeeper-server/src/main/java/org/apache/zookeeper/server/DataTree.java ---
    @@ -1521,4 +1566,179 @@ public boolean removeWatch(String path, WatcherType 
type, Watcher watcher) {
         public ReferenceCountedACLCache getReferenceCountedAclCache() {
             return aclCache;
         }
    +
    +    /**
    +     * Add the digest to the historical list, and update the latest zxid 
digest.
    +     */
    +    private void logZxidDigest(long zxid, long digest) {
    +        ZxidDigest zxidDigest = new ZxidDigest(zxid, 
DigestCalculator.DIGEST_VERSION, digest);
    +        lastProcessedZxidDigest = zxidDigest;
    +        if (zxidDigest.zxid % DIGEST_LOG_INTERVAL == 0) {
    +            synchronized (digestLog) {
    +                digestLog.add(zxidDigest);
    +                if (digestLog.size() > DIGEST_LOG_LIMIT) {
    +                    digestLog.poll();
    +                }
    +            }
    +        }
    +    }
    +
    +    /**
    +     * Serializing the digest to snapshot, this is done after the data 
tree 
    +     * is being serialized, so when we replay the txns and it hits this 
zxid 
    +     * we know we should be in a non-fuzzy state, and have the same 
digest. 
    +     *
    +     * @param oa the output stream to write to 
    +     * @return true if the digest is serialized successfully
    +     */
    +    public boolean serializeZxidDigest(OutputArchive oa) throws 
IOException {
    +        if (!DigestCalculator.digestEnabled()) {
    +            return false;
    +        }
    +
    +        ZxidDigest zxidDigest = lastProcessedZxidDigest;
    +        if (zxidDigest == null) {
    +            // write an empty digest
    +            zxidDigest = new ZxidDigest();
    +        }
    +        zxidDigest.serialize(oa);
    +        return true;
    +    }
    +
    +    /**
    +     * Deserializing the zxid digest from the input stream and update the 
    +     * digestFromLoadedSnapshot.
    +     *
    +     * @param ia the input stream to read from
    +     * @return the true if it deserialized successfully
    +     */
    +    public boolean deserializeZxidDigest(InputArchive ia) throws 
IOException {
    +        if (!DigestCalculator.digestEnabled()) {
    +            return false;
    +        }
    +
    +        try  {
    +            ZxidDigest zxidDigest = new ZxidDigest();
    +            zxidDigest.deserialize(ia);
    +            if (zxidDigest.zxid > 0) {
    +                digestFromLoadedSnapshot = zxidDigest;
    +            }
    +            return true;
    --- End diff --
    
    nit: put the `return true;` as the last line in the method. Therefore, this 
is the default behavior, and it return false early in case of failure (line 
1617 and 1630).


---

Reply via email to