|
@@ -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.
|
|
* 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;
|
|
long nextSid;
|
|
nextSid = (Time.currentElapsedTime() << 24) >>> 8;
|
|
nextSid = (Time.currentElapsedTime() << 24) >>> 8;
|
|
nextSid = nextSid | (id << 56);
|
|
nextSid = nextSid | (id << 56);
|
|
@@ -103,7 +106,7 @@ public class SessionTrackerImpl extends ZooKeeperCriticalThread implements Sessi
|
|
this.expirer = expirer;
|
|
this.expirer = expirer;
|
|
this.sessionExpiryQueue = new ExpiryQueue<SessionImpl>(tickTime);
|
|
this.sessionExpiryQueue = new ExpiryQueue<SessionImpl>(tickTime);
|
|
this.sessionsWithTimeout = sessionsWithTimeout;
|
|
this.sessionsWithTimeout = sessionsWithTimeout;
|
|
- this.nextSessionId.set(initializeNextSession(serverId));
|
|
|
|
|
|
+ this.nextSessionId.set(initializeNextSessionId(serverId));
|
|
for (Entry<Long, Integer> e : sessionsWithTimeout.entrySet()) {
|
|
for (Entry<Long, Integer> e : sessionsWithTimeout.entrySet()) {
|
|
trackSession(e.getKey(), e.getValue());
|
|
trackSession(e.getKey(), e.getValue());
|
|
}
|
|
}
|