Slide 19
Slide 19 text
Suddenly, code
>>> # zk is our handle to ZooKeeper
>>> # stat holds metadata about the znode
>>> config, stat = zk.get('/test')
>>> # let's look at the current version
>>> stat.version
1
>>> # try updating the znode with the current version
>>> zk.set('/test', 'foobar', version=stat.version)
>>> # success
>>> zk.get('/test')[0]
'foobar'
>>> # we can also choose to overwrite any value
>>> zk.set('/test', 'baz', version=-1)
>>> zk.get('/test')[0]
'baz'
>>> # let's see what happens if we pass a wrong version
>>> zk.set('/test', 'foobaz', version=9000)
>>> # we get an exception because version must be the
>>> # current version of the znode you're trying to change
kazoo.exceptions.BadVersionError: ((), {})
Saturday, November 10, 12