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 


---

Reply via email to