Review Board 1.7.22


ZOOKEEPER-1147: Add support for local sessions

Review Request #8935 - Created Jan. 12, 2013 and updated

Thawan Kooburat
trunk
ZOOKEEPER-1147
Reviewers
zookeeper
mahadev, phunt
zookeeper
See ZOOKEEPER-1147 for high level description 

Implementation notes:

- Local sessions don’t get persisted on disk.  Existing SessionTrackerImpl is used by the leader to track global sessions.  Each participant (including the leader) also has a local session tracker (which is another instance of SessionTrackerImpl) to track its local session in memory. 

- Each participant intercepts a request before it enters the pipeline. In order to do 2 things
 o Update local session to global session when it saw create ephemeral node request. Update is done by issuing a create session rquest before issuing the create request
 o Add local session flag to a request. So that the pipeline know that this type of request don’t need to send to the leader and wait for commit

- PrepRequestProcessor (on the leader) now explicitly validate global session on create ephemeral node request.  For other type of request, there is no need for session validation because the leader doesn’t know about local sessions on other machine, so the request has to go through.  The correctness is preserve as long a no ephemeral node is created after session is already expired

- Observer/FollowerRequestProcessor has logic to validate session. However, I believe this logic is in correct since the request is already send downstream to the CommitProcessor. The observer and the follower have no other option but to send the request to leader. 
unit tests.  For our internal branch, we haven't run into bugs related to local session for quite a while so it is quite stable. We enabled local session by default in all our deployment.

Diff revision 1

This is not the most recent revision of the diff. The latest diff is revision 6. See what's changed.

1 2 3 4 5 6
1 2 3 4 5 6

  1. /src/java/main/org/apache/zookeeper/KeeperException.java: Loading...
  2. /src/java/main/org/apache/zookeeper/cli/CreateCommand.java: Loading...
  3. /src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java: Loading...
  4. /src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java: Loading...
  5. /src/java/main/org/apache/zookeeper/server/Request.java: Loading...
  6. /src/java/main/org/apache/zookeeper/server/SessionTracker.java: Loading...
  7. /src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java: Loading...
  8. /src/java/main/org/apache/zookeeper/server/TraceFormatter.java: Loading...
  9. /src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java: Loading...
  10. /src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java: Loading...
  11. /src/java/main/org/apache/zookeeper/server/quorum/FollowerRequestProcessor.java: Loading...
  12. /src/java/main/org/apache/zookeeper/server/quorum/LeaderSessionTracker.java: Loading...
  13. /src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java: Loading...
  14. /src/java/main/org/apache/zookeeper/server/quorum/Learner.java: Loading...
  15. /src/java/main/org/apache/zookeeper/server/quorum/LearnerHandler.java: Loading...
  16. /src/java/main/org/apache/zookeeper/server/quorum/LearnerSessionTracker.java: Loading...
  17. /src/java/main/org/apache/zookeeper/server/quorum/LearnerZooKeeperServer.java: Loading...
  18. /src/java/main/org/apache/zookeeper/server/quorum/LocalSessionTracker.java: Loading...
  19. /src/java/main/org/apache/zookeeper/server/quorum/ObserverRequestProcessor.java: Loading...
  20. /src/java/main/org/apache/zookeeper/server/quorum/ProposalRequestProcessor.java: Loading...
This diff has been split across 2 pages: 1 2 >
/src/java/main/org/apache/zookeeper/KeeperException.java
Revision 1427034 New Change
[20] 128 lines
[+20] [+] public static KeeperException create(Code code) {
129
                return new InvalidCallbackException();
129
                return new InvalidCallbackException();
130
            case SESSIONMOVED:
130
            case SESSIONMOVED:
131
                return new SessionMovedException();
131
                return new SessionMovedException();
132
            case NOTREADONLY:
132
            case NOTREADONLY:
133
                return new NotReadOnlyException();
133
                return new NotReadOnlyException();
134
            	
134
            case EPHEMERALONLOCALSESSION:

    
   
135
                return new EphemeralOnLocalSessionException();

    
   
136

   
135
            case OK:
137
            case OK:
136
            default:
138
            default:
137
                throw new IllegalArgumentException("Invalid exception code");
139
                throw new IllegalArgumentException("Invalid exception code");
138
        }
140
        }
139
    }
141
    }
[+20] [20] 171 lines
[+20] [+] public void setCode(int code) {
311
        UNIMPLEMENTED (Unimplemented),
313
        UNIMPLEMENTED (Unimplemented),
312
        /** Operation timeout */
314
        /** Operation timeout */
313
        OPERATIONTIMEOUT (OperationTimeout),
315
        OPERATIONTIMEOUT (OperationTimeout),
314
        /** Invalid arguments */
316
        /** Invalid arguments */
315
        BADARGUMENTS (BadArguments),
317
        BADARGUMENTS (BadArguments),
316
        
318

   
317
        /** API errors.
319
        /** API errors.
318
         * This is never thrown by the server, it shouldn't be used other than
320
         * This is never thrown by the server, it shouldn't be used other than
319
         * to indicate a range. Specifically error codes greater than this
321
         * to indicate a range. Specifically error codes greater than this
320
         * value are API errors (while values less than this indicate a
322
         * value are API errors (while values less than this indicate a
321
         * {@link #SYSTEMERROR}).
323
         * {@link #SYSTEMERROR}).
[+20] [20] 21 lines
[+20] public void setCode(int code) {
343
        /** Client authentication failed */
345
        /** Client authentication failed */
344
        AUTHFAILED (AuthFailed),
346
        AUTHFAILED (AuthFailed),
345
        /** Session moved to another server, so operation is ignored */
347
        /** Session moved to another server, so operation is ignored */
346
        SESSIONMOVED (-118),
348
        SESSIONMOVED (-118),
347
        /** State-changing request is passed to read-only server */
349
        /** State-changing request is passed to read-only server */
348
        NOTREADONLY (-119);
350
        NOTREADONLY (-119),

    
   
351
        /** Attempt to create ephemeral node on a local session */

    
   
352
        EPHEMERALONLOCALSESSION (-120),

    
   
353
        /** Unknown session (internal server use only) */

    
   
354
        UNKNOWNSESSION (-122);
349

    
   
355

   
350
        private static final Map<Integer,Code> lookup
356
        private static final Map<Integer,Code> lookup
351
            = new HashMap<Integer,Code>();
357
            = new HashMap<Integer,Code>();
352

    
   
358

   
353
        static {
359
        static {
[+20] [20] 66 lines
[+20] [+] static String getCodeMessage(Code code) {
420
                return "Invalid callback";
426
                return "Invalid callback";
421
            case SESSIONMOVED:
427
            case SESSIONMOVED:
422
                return "Session moved";
428
                return "Session moved";
423
            case NOTREADONLY:
429
            case NOTREADONLY:
424
                return "Not a read-only call";
430
                return "Not a read-only call";

    
   
431
            case EPHEMERALONLOCALSESSION:

    
   
432
                return "Ephemeral node on local session";
425
            default:
433
            default:
426
                return "Unknown error " + code;
434
                return "Unknown error " + code;
427
        }
435
        }
428
    }
436
    }
429

    
   
437

   
[+20] [20] 50 lines
[+20] [+] public String getMessage() {
480

    
   
488

   
481
    /**
489
    /**
482
     * If this exception was thrown by a multi-request then the (partial) results
490
     * If this exception was thrown by a multi-request then the (partial) results
483
     * and error codes can be retrieved using this getter.
491
     * and error codes can be retrieved using this getter.
484
     * @return A copy of the list of results from the operations in the multi-request.
492
     * @return A copy of the list of results from the operations in the multi-request.
485
     * 
493
     *
486
     * @since 3.4.0
494
     * @since 3.4.0
487
     *
495
     *
488
     */
496
     */
489
    public List<OpResult> getResults() {
497
    public List<OpResult> getResults() {
490
        return results != null ? new ArrayList<OpResult>(results) : null;
498
        return results != null ? new ArrayList<OpResult>(results) : null;
[+20] [20] 170 lines
[+20] [+] public static class RuntimeInconsistencyException extends KeeperException {
661
    public static class SessionExpiredException extends KeeperException {
669
    public static class SessionExpiredException extends KeeperException {
662
        public SessionExpiredException() {
670
        public SessionExpiredException() {
663
            super(Code.SESSIONEXPIRED);
671
            super(Code.SESSIONEXPIRED);
664
        }
672
        }
665
    }
673
    }
666
    
674

   

    
   
675
    /**

    
   
676
     * @see Code#UNKNOWNSESSION

    
   
677
     */

    
   
678
    public static class UnknownSessionException extends KeeperException {

    
   
679
        public UnknownSessionException() {

    
   
680
            super(Code.UNKNOWNSESSION);

    
   
681
        }

    
   
682
    }

    
   
683

   
667
    /**
684
    /**
668
     * @see Code#SESSIONMOVED
685
     * @see Code#SESSIONMOVED
669
     */
686
     */
670
    public static class SessionMovedException extends KeeperException {
687
    public static class SessionMovedException extends KeeperException {
671
        public SessionMovedException() {
688
        public SessionMovedException() {
[+20] [20] 9 lines
[+20] [+] public static class NotReadOnlyException extends KeeperException {
681
            super(Code.NOTREADONLY);
698
            super(Code.NOTREADONLY);
682
        }
699
        }
683
    }
700
    }
684

    
   
701

   
685
    /**
702
    /**

    
   
703
     * @see Code#EPHEMERALONLOCALSESSION

    
   
704
     */

    
   
705
    public static class EphemeralOnLocalSessionException extends KeeperException {

    
   
706
        public EphemeralOnLocalSessionException() {

    
   
707
            super(Code.EPHEMERALONLOCALSESSION);

    
   
708
        }

    
   
709
    }

    
   
710

   

    
   
711
    /**
686
     * @see Code#SYSTEMERROR
712
     * @see Code#SYSTEMERROR
687
     */
713
     */
688
    public static class SystemErrorException extends KeeperException {
714
    public static class SystemErrorException extends KeeperException {
689
        public SystemErrorException() {
715
        public SystemErrorException() {
690
            super(Code.SYSTEMERROR);
716
            super(Code.SYSTEMERROR);
[+20] [20] 12 lines
/src/java/main/org/apache/zookeeper/cli/CreateCommand.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/Request.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/SessionTracker.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/TraceFormatter.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/FollowerRequestProcessor.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/LeaderSessionTracker.java
New File
 
/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/Learner.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/LearnerHandler.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/LearnerSessionTracker.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/LearnerZooKeeperServer.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/LocalSessionTracker.java
New File
 
/src/java/main/org/apache/zookeeper/server/quorum/ObserverRequestProcessor.java
Revision 1427034 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/ProposalRequestProcessor.java
Revision 1427034 New Change
 
  1. /src/java/main/org/apache/zookeeper/KeeperException.java: Loading...
  2. /src/java/main/org/apache/zookeeper/cli/CreateCommand.java: Loading...
  3. /src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java: Loading...
  4. /src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java: Loading...
  5. /src/java/main/org/apache/zookeeper/server/Request.java: Loading...
  6. /src/java/main/org/apache/zookeeper/server/SessionTracker.java: Loading...
  7. /src/java/main/org/apache/zookeeper/server/SessionTrackerImpl.java: Loading...
  8. /src/java/main/org/apache/zookeeper/server/TraceFormatter.java: Loading...
  9. /src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java: Loading...
  10. /src/java/main/org/apache/zookeeper/server/quorum/CommitProcessor.java: Loading...
  11. /src/java/main/org/apache/zookeeper/server/quorum/FollowerRequestProcessor.java: Loading...
  12. /src/java/main/org/apache/zookeeper/server/quorum/LeaderSessionTracker.java: Loading...
  13. /src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java: Loading...
  14. /src/java/main/org/apache/zookeeper/server/quorum/Learner.java: Loading...
  15. /src/java/main/org/apache/zookeeper/server/quorum/LearnerHandler.java: Loading...
  16. /src/java/main/org/apache/zookeeper/server/quorum/LearnerSessionTracker.java: Loading...
  17. /src/java/main/org/apache/zookeeper/server/quorum/LearnerZooKeeperServer.java: Loading...
  18. /src/java/main/org/apache/zookeeper/server/quorum/LocalSessionTracker.java: Loading...
  19. /src/java/main/org/apache/zookeeper/server/quorum/ObserverRequestProcessor.java: Loading...
  20. /src/java/main/org/apache/zookeeper/server/quorum/ProposalRequestProcessor.java: Loading...
This diff has been split across 2 pages: 1 2 >