optimistic locking - can ZooKeeper get znode data and znode data version (stat) in one single operation? -
i developing application use zookeeper datastore. 1 of methods in application, need use optimistic concurrent control. example, need implement method znode data, , use znode data version optimistic concurrent control check. understand, 1 can't znode data , znode data version in 1 single operation. if there high contention update znode data, method not work since znode data might changed after getting znode data. asking - is there way can znode data , znode data version (or znode stat) in 1 single operation without locking attempt in between?
in java, can can achieve want easily:
stat stat = new stat(); byte[] data = zk.getdata("/path", null, stat));
this read data , version information (in stat
object) in single operation. when write data, pass version number got when read it:
zk.setdata("/path", data, stat.getversion());
if there version mismatch, method throw keeperexception.badversionexception
, gives optimistic lock.
Comments
Post a Comment