2

I was wondering if there is a way in the kazoo library for zookeeper to create the chroot path in the connection string if the path doesn't already exist? Does anyone have experience with this? I've read the docs, but I haven't really found anything to deal with this.

What I'm doing now is connecting to the zookeeper server, making sure the path exists, disconnecting, and then reconnecting with the path, but that doesn't seem very efficient.

connection1 = '127.0.0.102:2181,127.0.0.213:2181,127.0.0.134:2181'
connection2 = '127.0.0.102:2181,127.0.0.213:2181,127.0.0.134:2181/pathtoroot'
zk = KazooClient(hosts=connection1, timeout=2.0)
zk.start()
zk.ensure_path(pathtoroot)
zk.stop()
zk = KazooClient(hosts=connection2, timeout=2.0)
zk.start()

Thank you!

Juliuszc
  • 377
  • 2
  • 4
  • 16

1 Answers1

3

I figured out a way to do it without reconnecting. You have to connect without a chroot and then manually set it after making sure the path exists.

connection1 = '127.0.0.102:2181,127.0.0.213:2181,127.0.0.134:2181'
zk = KazooClient(hosts=connection1, timeout=2.0)
zk.start()
zk.ensure_path(pathtoroot)
zk.chroot = pathtoroot
Juliuszc
  • 377
  • 2
  • 4
  • 16