You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by nk...@apache.org on 2019/09/20 08:02:19 UTC
[zookeeper] branch master updated: ZOOKEEPER-3506: correct the
javaDoc of the SessionTrackerImpl#initializeNextSessionId
This is an automated email from the ASF dual-hosted git repository.
nkalmar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git
The following commit(s) were added to refs/heads/master by this push:
new 2c1034f ZOOKEEPER-3506: correct the javaDoc of the SessionTrackerImpl#initializeNextSessionId
2c1034f is described below
commit 2c1034f8fe4e6e437f7c71478153f41180970542
Author: maoling <ma...@sina.com>
AuthorDate: Fri Sep 20 10:02:12 2019 +0200
ZOOKEEPER-3506: correct the javaDoc of the SessionTrackerImpl#initializeNextSessionId
- A analyst of this method
suppose that current timestamp:1566197268432(10110110010101000101000011011111111010000), myid=1
```
00000000 00000000 00000001 01101100 10101000 10100001 10111111 11010000
<<24
01101100 10101000 10100001 10111111 11010000 00000000 00000000 00000000
>>>8
00000000 01101100 10101000 10100001 10111111 11010000 00000000 00000000
|
00000001 00000000 00000000 00000000 00000000 00000000 00000000 00000000(id << 56)
=
00000001 01101100 10101000 10100001 10111111 11010000 00000000 00000000
```
- more details in the [ZOOKEEPER-3506](https://issues.apache.org/jira/browse/ZOOKEEPER-3506)
Author: maoling <ma...@sina.com>
Reviewers: Allan Lyu <fa...@apache.org>, Enrico Olivelli <eo...@apache.org>, Norbert Kalmar <nk...@apache.org>
Closes #1057 from maoling/ZOOKEEPER-3506
---
.../java/org/apache/zookeeper/server/SessionTrackerImpl.java | 9 ++++++---
.../apache/zookeeper/server/quorum/LearnerSessionTracker.java | 2 +-
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/SessionTrackerImpl.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/SessionTrackerImpl.java
index 755512e..153cffc 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/SessionTrackerImpl.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/SessionTrackerImpl.java
@@ -83,10 +83,13 @@ public class SessionTrackerImpl extends ZooKeeperCriticalThread implements Sessi
}
/**
- * Generates an initial sessionId. High order byte is serverId, next 5
+ * Generates an initial sessionId. High order 1 byte is serverId, next
* 5 bytes are from timestamp, and low order 2 bytes are 0s.
+ * Use ">>> 8", not ">> 8" to make sure that the high order 1 byte is entirely up to the server Id(@see ZOOKEEPER-1622).
+ * @param id server Id
+ * @return the Session Id
*/
- public static long initializeNextSession(long id) {
+ public static long initializeNextSessionId(long id) {
long nextSid;
nextSid = (Time.currentElapsedTime() << 24) >>> 8;
nextSid = nextSid | (id << 56);
@@ -103,7 +106,7 @@ public class SessionTrackerImpl extends ZooKeeperCriticalThread implements Sessi
this.expirer = expirer;
this.sessionExpiryQueue = new ExpiryQueue<SessionImpl>(tickTime);
this.sessionsWithTimeout = sessionsWithTimeout;
- this.nextSessionId.set(initializeNextSession(serverId));
+ this.nextSessionId.set(initializeNextSessionId(serverId));
for (Entry<Long, Integer> e : sessionsWithTimeout.entrySet()) {
trackSession(e.getKey(), e.getValue());
}
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LearnerSessionTracker.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LearnerSessionTracker.java
index a2f5590..e557083 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LearnerSessionTracker.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LearnerSessionTracker.java
@@ -65,7 +65,7 @@ public class LearnerSessionTracker extends UpgradeableSessionTracker {
this.touchTable.set(new ConcurrentHashMap<Long, Integer>());
this.globalSessionsWithTimeouts = sessionsWithTimeouts;
this.serverId = id;
- nextSessionId.set(SessionTrackerImpl.initializeNextSession(serverId));
+ nextSessionId.set(SessionTrackerImpl.initializeNextSessionId(serverId));
this.localSessionsEnabled = localSessionsEnabled;
if (this.localSessionsEnabled) {