> I'm aware a znode or perhaps pzxid (for a path of data) could be passed to 
> the second machine.

It's available to the client. See: 
https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java#L810
 

You'd create your own ZooKeeper subclass - "cnxn" is a protected field. So, 
something like:

public class MyZooKeeper extends ZooKeeper {
        ...

        public long getLastZxid() {
                return cnxn.getLastZxid();
        }
}

> But I'm worried about over-using sync() because I imagine it's not free.

TBH - I've never understood the sync() method. I always thought it was useless 
but Alex Shraer wrote some ways that it can be useful. See: 
https://mail-archives.apache.org/mod_mbox/zookeeper-dev/201908.mbox/thread?2 
(search for "Consistency Guarantees").

> Imagine this is some immutable configuration data that is set once then used 
> a lot by many ZK clients thereafter many thousands of times for days on end.

Note: this is how Facebook uses ZooKeeper. It's the backbone of their config 
system. They have 10s of thousands (something like that) of read-only observers 
that sit in front of their main ZK ensemble.

>  Does Curator facilitate this in any way?

This is what the various Cache recipes are for (Scott's TreeCache or the 
upcoming CuratorCache). These recipes take care of pulling down the latest 
versions of ZNodes for you.

-Jordan

> On May 1, 2020, at 12:43 AM, David Smiley <dsmi...@apache.org> wrote:
> 
> Hello,
> 
> I'm trying to come to grips with the ramifications of ZooKeeper's eventual 
> consistency model and what mechanisms exists to help.  
> 
> Imagine two machines that use ZK, one of which stores data in it then tells 
> the other machine to do something that will require it to read what the first 
> machine wrote.
> 
> ZK's docs warn about this:
> https://github.com/apache/zookeeper/blob/master/zookeeper-docs/src/main/resources/markdown/zookeeperProgrammers.md#ch_zkGuarantees
>  
> <https://github.com/apache/zookeeper/blob/master/zookeeper-docs/src/main/resources/markdown/zookeeperProgrammers.md#ch_zkGuarantees>
>  .. and refer to a sync() method to help:
> https://github.com/apache/zookeeper/blob/2e14a29cc6e58d9561e80b737a3168fbb1f752b4/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java#L3057
>  
> <https://github.com/apache/zookeeper/blob/2e14a29cc6e58d9561e80b737a3168fbb1f752b4/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java#L3057>
> 
> But I'm worried about over-using sync() because I imagine it's not free.  For 
> the scenario I have in mind, the vast majority of the time, the second 
> machine will see the latest state because lots of time passes between the 
> write and the read.  Imagine this is some immutable configuration data that 
> is set once then used a lot by many ZK clients thereafter many thousands of 
> times for days on end.
> 
> I'm aware a znode or perhaps pzxid (for a path of data) could be passed to 
> the second machine... but for the system in question, this would be really 
> ugly and I want to consider alternatives.  Besides, the data is organized 
> into a tree that could have arbitrary nesting, so it's not clear to me that 
> there's a single version for this any way.
> 
> Scott Blum told me about how there's an increasing "zxid" for all state 
> change in ZK.  I can see this on ZK's ClientCnxn.getLastZxid().  If I were to 
> pass that zxid to the additional machines (ZK clients) from the first for 
> basically all interactions (not too ugly for the system), how would the 
> receiving machine use this to get in sync?  I'm guessing it could read its 
> own connection zxid and if it's out of date than call sync()?  Does that make 
> sense?  Is there another strategy to be recommended?  Does Curator facilitate 
> this in any way?
> 
> Thanks in advance!  I already searched this list for answers.
> 
> ~ David Smiley
> Apache Lucene/Solr Search Developer
> http://www.linkedin.com/in/davidwsmiley 
> <http://www.linkedin.com/in/davidwsmiley>

Reply via email to