Github user lvfangmin commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/447#discussion_r205923291
--- Diff:
src/java/main/org/apache/zookeeper/server/quorum/LearnerSessionTracker.java ---
@@ -101,33 +100,44 @@ public boolean isGlobalSession(long sessionId) {
return globalSessionsWithTimeouts.containsKey(sessionId);
}
- public boolean addGlobalSession(long sessionId, int sessionTimeout) {
+ public boolean trackSession(long sessionId, int sessionTimeout) {
+ // Learner doesn't track global session, do nothing here
+ return false;
+ }
+
+ /**
+ * Synchronized on this to avoid race condition of adding a local
session
+ * after committed global session, which may cause the same session
being
+ * tracked on this server and leader.
+ */
+ public synchronized boolean commitSession(
+ long sessionId, int sessionTimeout) {
boolean added =
globalSessionsWithTimeouts.put(sessionId, sessionTimeout) ==
null;
- if (localSessionsEnabled && added) {
+
+ if (added) {
// Only do extra logging so we know what kind of session this
is
// if we're supporting both kinds of sessions
- LOG.info("Adding global session 0x" +
Long.toHexString(sessionId));
+ LOG.info("Committing global session 0x" +
Long.toHexString(sessionId));
}
- touchTable.get().put(sessionId, sessionTimeout);
- return added;
- }
- public boolean addSession(long sessionId, int sessionTimeout) {
--- End diff --
Explained in the previous comment, createSession will add and track it.
---