zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eribeiro <...@git.apache.org>
Subject [GitHub] zookeeper pull request #632: [ZOOKEEPER-3150] Add tree digest check and veri...
Date Mon, 15 Oct 2018 00:27:05 GMT
Github user eribeiro commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/632#discussion_r225016598
  
    --- 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 --
    
    Good point.


---

Mime
View raw message