Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-4253

The client connects to zookeeper twice and get the same session id

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.4.13
    • None
    • None
    • None

    Description

      App AA connects to ZooKeeper and creates a temporary path such as /brokers/ids/10. Another APP BB also connects to ZooKeeper. At some point AA BB and ZooKeeper are restarted, and BB allocates AA's old session

      before restart:
      AA connect to zookeeper ,and log in zk:
      [2021-03-07 08:47:43,468] INFO [SyncThread:0] Established session 0x10000053ef90000 with negotiated timeout 8000 for client /22.20.0.45:59966 (org.apache.zookeeper.server.ZooKeeperServer)

       

      after restart:

      BB connect to zookeeper ,and log in zk:

      [2021-03-07 08:58:51,351] INFO [SyncThread:0] Established session 0x10000053ef90000 with negotiated timeout 30000 for client /22.20.0.47:39360 (org.apache.zookeeper.server.ZooKeeperServer)

       

      I understand that after a restart, ZooKeeper loads old transaction logs and snapshot files, and old sessions and temporary paths are loaded. If BB obtains the old session 0x10000053ef90000 at this point, the session will not expire and the temporary path will not be deleted, causing AA to be unable to re-register the temporary path

      This is my question. I look forward to your help. Thank you very much!

       

      2021/03/17 14:44

      I have checked the source code of zookeeper, and the generation of session is as follows:

      public static long initializeNextSession(long id) {
       long nextSid = 0;
       nextSid = (Time.currentElapsedTime() << 24) >>> 8;
       nextSid = nextSid | (id <<56);
       return nextSid;
      }

      Id is a fixed value, and the only variable that affects session id is the current time. Obviously zookeeper it takes different time to create session twice, but why get the same session id?

      Attachments

        1. BB.log
          763 kB
          Damon Liu
        2. AA.log
          928 kB
          Damon Liu
        3. zookeeper.log
          992 kB
          Damon Liu

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Damon Damon Liu
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: