zookeeper-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Damon Liu (Jira)" <j...@apache.org>
Subject [jira] [Commented] (ZOOKEEPER-4253) The client connects to zookeeper twice and get the same session id
Date Mon, 10 May 2021 01:25:00 GMT

    [ https://issues.apache.org/jira/browse/ZOOKEEPER-4253?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17341634#comment-17341634

Damon Liu commented on ZOOKEEPER-4253:

Can someone explain the possible reasons for this?

> The client connects to zookeeper twice and get the same session id
> ------------------------------------------------------------------
>                 Key: ZOOKEEPER-4253
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-4253
>             Project: ZooKeeper
>          Issue Type: Bug
>    Affects Versions: 3.4.13
>            Reporter: Damon Liu
>            Priority: Major
>         Attachments: AA.log, BB.log, zookeeper.log
> 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 {color:#ff0000}0x10000053ef90000{color} with
negotiated timeout 8000 for client /{color:#ff0000}{color}: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 {color:#ff0000}0x10000053ef90000{color} with
negotiated timeout 30000 for client /{color:#ff0000}{color}: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:
> {code:java}
> public static long initializeNextSession(long id) {
>  long nextSid = 0;
>  nextSid = (Time.currentElapsedTime() << 24) >>> 8;
>  nextSid = nextSid | (id <<56);
>  return nextSid;
> }{code}
> 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?

This message was sent by Atlassian Jira

View raw message