[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-2901?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16372909#comment-16372909
 ] 

ASF GitHub Bot commented on ZOOKEEPER-2901:
-------------------------------------------

Github user Randgalt commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/377#discussion_r169985373
  
    --- Diff: src/java/main/org/apache/zookeeper/server/EphemeralType.java ---
    @@ -37,41 +77,152 @@
         /**
          * TTL node
          */
    -    TTL;
    +    TTL() {
    +        @Override
    +        public long maxValue() {
    +            return EXTENDED_FEATURE_VALUE_MASK;  // 12725 days, about 34 
years
    +        }
    +
    +        @Override
    +        public long toEphemeralOwner(long ttl) {
    +            if ((ttl > TTL.maxValue()) || (ttl <= 0)) {
    +                throw new IllegalArgumentException("ttl must be positive 
and cannot be larger than: " + TTL.maxValue());
    +            }
    +            //noinspection PointlessBitwiseExpression
    +            return EXTENDED_MASK | EXTENDED_BIT_TTL | ttl;  // 
TTL_RESERVED_BIT is actually zero - but it serves to document that the proper 
extended bit needs to be set
    +        }
    +
    +        @Override
    +        public long getValue(long ephemeralOwner) {
    +            return getExtendedFeatureValue(ephemeralOwner);
    +        }
    +    };
    +
    +    /**
    +     * For types that support it, the maximum extended value
    +     *
    +     * @return 0 or max
    +     */
    +    public long maxValue() {
    +        return 0;
    +    }
    +
    +    /**
    +     * For types that support it, convert a value to an extended ephemeral 
owner
    +     *
    +     * @return 0 or extended ephemeral owner
    +     */
    +    public long toEphemeralOwner(long value) {
    +        return 0;
    +    }
    +
    +    /**
    +     * For types that support it, return the extended value from an 
extended ephemeral owner
    +     *
    +     * @return 0 or extended value
    +     */
    +    public long getValue(long ephemeralOwner) {
    +        return 0;
    +    }
     
         public static final long CONTAINER_EPHEMERAL_OWNER = Long.MIN_VALUE;
    -    public static final long MAX_TTL = 0x0fffffffffffffffL;
    -    public static final long TTL_MASK = 0x8000000000000000L;
    +    public static final long MAX_EXTENDED_SERVER_ID = 0xfe;  // 254
    +
    +    private static final long EXTENDED_MASK = 0xff00000000000000L;
    +    private static final long EXTENDED_BIT_TTL = 0x0000;
    +    private static final long RESERVED_BITS_MASK = 0x00ffff0000000000L;
    +    private static final long RESERVED_BITS_SHIFT = 40;
    +
    +    private static final Map<Long, EphemeralType> extendedFeatureMap;
     
    +    static {
    +        Map<Long, EphemeralType> map = new HashMap<>();
    +        map.put(EXTENDED_BIT_TTL, TTL);
    +        extendedFeatureMap = Collections.unmodifiableMap(map);
    +    }
    +
    +    private static final long EXTENDED_FEATURE_VALUE_MASK = 
~(EXTENDED_MASK | RESERVED_BITS_MASK);
    +
    +    // Visible for testing
    +    static final String EXTENDED_TYPES_ENABLED_PROPERTY = 
"zookeeper.extendedTypesEnabled";
    +    static final String TTL_3_5_3_EMULATION_PROPERTY = 
"zookeeper.emulate353TTLNodes";
    +
    +    /**
    +     * Return true if extended ephemeral types are enabled
    +     *
    +     * @return true/false
    +     */
    +    public static boolean extendedEphemeralTypesEnabled() {
    --- End diff --
    
    The way it's implemented now, we can add easily new features in the future. 
Why code ourselves into a corner when we can leave some room? BTW - I'd 
discussed this offline with @phunt 


> Session ID that is negative causes mis-calculation of Ephemeral Type
> --------------------------------------------------------------------
>
>                 Key: ZOOKEEPER-2901
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2901
>             Project: ZooKeeper
>          Issue Type: Bug
>          Components: server
>    Affects Versions: 3.5.3
>         Environment: Running 3.5.3-beta in Docker container
>            Reporter: Mark Johnson
>            Assignee: Jordan Zimmerman
>            Priority: Blocker
>
> In the code that determines the EphemeralType it is looking at the owner 
> (which is the client ID or connection ID):
> EphemeralType.java:
>    public static EphemeralType get(long ephemeralOwner) {
>        if (ephemeralOwner == CONTAINER_EPHEMERAL_OWNER) {
>            return CONTAINER;
>        }
>        if (ephemeralOwner < 0) {
>            return TTL;
>        }
>        return (ephemeralOwner == 0) ? VOID : NORMAL;
>    }
> However my connection ID is:
> header.getClientId(): -720548323429908480
> This causes the code to think this is a TTL Ephemeral node instead of a
> NORMAL Ephemeral node.
> This also explains why this is random - if my client ID is non-negative
> then the node gets added correctly.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to