Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-2016 Automate client-side rebalancing
  3. ZOOKEEPER-2037

ZooKeeper methods to wait on client connection (re)establishment.

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Major
    • Resolution: Won't Fix
    • 3.5.0
    • None
    • java client
    • None

    Description

      When a ZooKeeper object is created and returned, it is not guaranteed that connection to a server is established.

      Usually, a wait/signal pattern is used for the ZK watcher

      latch = new CountDownLatch(1)
      zk = new ZooKeeper(..., new Watcher() {
        override void process(WatchedEvent event) {
          if (event.type = SyncConnected) {
            latch.countDown()
          }
        }
      },...)
      
      latch.await();
      // connection has been established. do something with zk.
      

      There are two disadvantages:
      1. The latch object isn't being garbage-collected. Because the watcher keeps monitoring all kinds of events.
      2. With the introduction of dynamic reconfig, client move to other servers on needed and this latch method doesn't work so well.

      Here I propose to add (both sync and async) wait methods to act as latch for connection establish such that it becomes much easier to manage and work around:

      zk = new ZooKeeper(...)
      zk.waitUntilConnected()
      

      Attachments

        1. ZOOKEEPER-2037.patch
          8 kB
          Hongchao Deng

        Activity

          People

            hdeng Hongchao Deng
            hdeng Hongchao Deng
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: