Current ZookeeperWatcher's watch_callback accepts zk event as parameter but ignores it during processing. Every time a zk event is received, watch_callback does all three things regardless of which zk event:
calling zk.exists on service znode
calling zk.children on service znode
calling zk.get on service znode.
But each zk event always contains single change(e.g. child and data event are mutually exclusive) and performing all three calls above are not necessary. For example below are a list of methods supported on zk event:
node_event? : true for node event and false for session event
node_child? : true if watched znode children have changed.
node_chanaged? : true if watched znode data has changed.
node_created? : true if watched znode was created
node_deleted? : true if watched znode was deleted.
This PR adds a few boolean checks to handle children change and data change separately, and should reduce three zk calls to one in most cases since children change is the most frequent ones.
During watch startup, the three calls will still be executed to read data and set watches in zk.
Test
Added new rspec tests to test nil/child/changed events: bundle exec rspec
Ran ZookeeperWatcher against zookeeper-test and checked event handling with manual zk data change.
Summary
Current ZookeeperWatcher's watch_callback accepts zk event as parameter but ignores it during processing. Every time a zk event is received, watch_callback does all three things regardless of which zk event:
But each zk event always contains single change(e.g. child and data event are mutually exclusive) and performing all three calls above are not necessary. For example below are a list of methods supported on zk event:
This PR adds a few boolean checks to handle children change and data change separately, and should reduce three zk calls to one in most cases since children change is the most frequent ones.
During watch startup, the three calls will still be executed to read data and set watches in zk.
Test
Reviewer
@airbnb/traffic @panchr @austin-zhu @Jason-Jian