bonifaido / rust-zookeeper

Pure Rust library for Apache ZooKeeper built on MIO
MIT License
204 stars 46 forks source link

Locking example #65

Open Jasperav opened 4 years ago

Jasperav commented 4 years ago

https://zookeeper.apache.org/doc/r3.1.2/recipes.html section 'Locks' gives an example on how to do locking. I see an open issue also has something to do with locking: https://github.com/bonifaido/rust-zookeeper/issues/17.

I can write some rust code that does do the locking, covered in https://zookeeper.apache.org/doc/r3.1.2/recipes.html. I don't know how this can be tested though. I see there is a cluster test in Kotlin. A cluster needs to be online to do the actual testing I believe.

Jasperav commented 4 years ago

I am also curious: is the sync api available? From https://zookeeper.apache.org/doc/r3.1.2/zookeeperProgrammers.html:

Simultaneously Conistent Cross-Client Views ZooKeeper does not guarantee that at every instance in time, two different clients will have identical views of ZooKeeper data. Due to factors like network delays, one client may perform an update before another client gets notified of the change. Consider the scenario of two clients, A and B. If client A sets the value of a znode /a from 0 to 1, then tells client B to read /a, client B may read the old value of 0, depending on which server it is connected to. If it is important that Client A and Client B read the same value, Client B should should call the sync() method from the ZooKeeper API method before it performs its read.

bonifaido commented 4 years ago

Hi @Jasperav, please go ahead with the implementation, PRs are always welcome. ;)

The Kotlin code creates a proper ZooKeeper server which can be controlled from the Rust test code. But probably we should change it to a Docker container instead.