zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hanm <...@git.apache.org>
Subject [GitHub] zookeeper pull request #447: [ZOOKEEPER-2926] Fix potential data consistency...
Date Fri, 27 Jul 2018 00:08:49 GMT
Github user hanm commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/447#discussion_r205636796
  
    --- 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 --
    
    Here a similar question as asked in `LeaderSessionTracker`: with this being removed how
would `LearnerSessionTracker` track a local session? The `trackSession` here as commented,
just return false and I don't see any way of adding a local session to `LearnerSessionTracker`.


---

Mime
View raw message