I'm talking at Codemania in Auckland on March 30th 2012 about all things Cassandra.
znodes which act like directories and files. Uses ”/” as the path separator.znodes may have data and children.znodes have a version number for their local (?) state.znode are atomic with respect to the version of data.znodes can be protected by an ACL.znodes are deleted when the session that created them ends.znode that is triggered when it changes. Is this for the local data or local data and children ?Proposals are missing a snapshot is sent.zxid and sent to all servers, a server ack’s when it is on persistent store. Messages in the proposal are then delivered.zxid has two parts: the epoch and a counter. Implemented as a 64 bit int, high 32 bits are the epoch, low 32 are the count.PROPOSE to all followers for a new proposal. * Followers commit to non-volatile storage and then ACK * Leader sends COMMIT to all followers once a QUOURM have ACK‘d.bin/zkServer.sh start-foreground conf/zoo_sample.cfgbin/zkCli.sh -server 127.0.0.1:2181 and work through the examples in the doc.zc-zookeeper-static is a wrapper around the C libs, it’s pretty low level. e.g. you get an int handle and pass that into methods, not OO. zc.zk ads an OO wrapper and some other stuff I cannot work out.zc-zookeeper-static package and do not have any docs. Check to docs on zookeeper for the function help. For example zc.zk.ZooKeeper.get has no docs and a crap (*arg, **kwargs) param list, look at zookeeper.get.import zc.zk
zk = zc.zk.ZooKeeper('127.0.0.1:2181')
znodeIn [6]: zk.get_children("/")
Out[6]: ['consumers', 'brokers', 'zookeeper', 'zk_test']
# some stuff from kafka there.
znode# Get a zc.zk.Properties for the path
# **NOTE:** This is heavy weight, for single reads use get_properties()
In [55]: p = zk.properties("/zookeeper")
In [56]: p.data
Out[56]: {}
In [58]: p.values()
Out[58]: []
# simple get_properties()
In [64]: zk.get_properties("/zk_test")
Out[64]: {'string_value': 'foo'}
#zv.zk assume node data is json
In [49]: zk.set("/zk_test", "foo")
Out[49]: 0
In [51]: p = zk.properties("/zk_test")
In [53]: p.values()
Out[53]: ['foo']
In [54]: p.data
Out[54]: {'string_value': 'foo'}
In [59]: zk.print_tree("/zookeeper")
/zookeeper
/quota
znode operations# create an ephemeral node
# must have an ACL this is an open one
In [78]: acl = [{"perms" : zookeeper.PERM_ALL, "scheme" : "world", "id" : "anyone"}]
# Parent path must exist
In [85]: zk.create( "/fake/ephemeral", "some data", acl, zookeeper.EPHEMERAL)
...
NoNodeException: no node
In [84]: zk.create( "/zk_test/ephemeral", "some data", acl, zookeeper.EPHEMERAL)
Out[84]: '/zk_test/ephemeral'
# node now listed (locally) on the connection
In [86]: zk.ephemeral
Out[86]:
{'/zk_test/ephemeral': {'acl': [{'id': 'anyone',
'perms': 31,
'scheme': 'world'}],
'data': 'some data',
'flags': 1}}
# View from the cluster
In [88]: zk.get_properties("/zk_test/ephemeral")
Out[88]: {'string_value': 'some data'}
In [89]: p = zk.properties("/zk_test/ephemeral")
In [91]: p.meta_data
Out[91]:
{'aversion': 0,
'ctime': 1326337991257L,
'cversion': 0,
'czxid': 1950L,
'dataLength': 9,
'ephemeralOwner': 86922380708675587L,
'mtime': 1326337991257L,
'mzxid': 1950L,
'numChildren': 0,
'pzxid': 1950L,
'version': 0}
In [8]: children = zk.children("/zk_test")
In [9]: def my_callback(node):
...: print "Called with node: ", str(node)
...:
In [11]: children(my_callback)
Called with node: zc.zk.Children(0, /zk_test)
Out[11]: zc.zk.Children(0, /zk_test)
In [14]: acl = [{"perms" : zookeeper.PERM_ALL, "scheme" : "world", "id" : "anyone"}]
In [15]: zk.create( "/zk_test/ephemeral", "some data", acl, zookeeper.EPHEMERAL)
Out[15]: '/zk_test/ephemeral'
Called with node: zc.zk.Children(0, /zk_test)