zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject zookeeper git commit: ZOOKEEPER-3038: Cleanup some nitpicks in TTL implementation
Date Thu, 10 May 2018 04:14:27 GMT
Repository: zookeeper
Updated Branches:
  refs/heads/branch-3.5 c86349060 -> edb93d496


ZOOKEEPER-3038: Cleanup some nitpicks in TTL implementation

A few nitpicks which needs to be cleaned up:

1. Rename OldEphemeralType --> EphemeralTypeEmulate353
2. Remove unused method: getTTL()
3. Remove unused import from QuorumPeer

Author: Andor Molnar <andor@cloudera.com>

Reviewers: phunt@apache.org

Closes #516 from anmolnar/ZOOKEEPER-3038

Change-Id: Iec537706a35863d53daa593da2b01f6e523ef466
(cherry picked from commit 6e64125f2aafc29253904c43ee44233c907e5fca)
Signed-off-by: Patrick Hunt <phunt@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/edb93d49
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/edb93d49
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/edb93d49

Branch: refs/heads/branch-3.5
Commit: edb93d496105d2e0f4440cd4c533b0c42d79e9fd
Parents: c863490
Author: Andor Molnar <andor@cloudera.com>
Authored: Wed May 9 21:13:16 2018 -0700
Committer: Patrick Hunt <phunt@apache.org>
Committed: Wed May 9 21:13:59 2018 -0700

----------------------------------------------------------------------
 .../apache/zookeeper/server/EphemeralType.java  |  2 +-
 .../server/EphemeralTypeEmulate353.java         | 67 ++++++++++++++++++
 .../zookeeper/server/OldEphemeralType.java      | 74 --------------------
 .../zookeeper/server/quorum/QuorumPeer.java     |  1 -
 .../zookeeper/server/Emulate353TTLTest.java     |  2 +-
 5 files changed, 69 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/edb93d49/src/java/main/org/apache/zookeeper/server/EphemeralType.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/EphemeralType.java b/src/java/main/org/apache/zookeeper/server/EphemeralType.java
index 7861d40..f5d58ae 100644
--- a/src/java/main/org/apache/zookeeper/server/EphemeralType.java
+++ b/src/java/main/org/apache/zookeeper/server/EphemeralType.java
@@ -166,7 +166,7 @@ public enum EphemeralType {
     public static EphemeralType get(long ephemeralOwner) {
         if (extendedEphemeralTypesEnabled()) {
             if (Boolean.getBoolean(TTL_3_5_3_EMULATION_PROPERTY)) {
-                if (OldEphemeralType.get(ephemeralOwner) == OldEphemeralType.TTL) {
+                if (EphemeralTypeEmulate353.get(ephemeralOwner) == EphemeralTypeEmulate353.TTL)
{
                     return TTL;
                 }
             }

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/edb93d49/src/java/main/org/apache/zookeeper/server/EphemeralTypeEmulate353.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/EphemeralTypeEmulate353.java b/src/java/main/org/apache/zookeeper/server/EphemeralTypeEmulate353.java
new file mode 100644
index 0000000..c8f384f
--- /dev/null
+++ b/src/java/main/org/apache/zookeeper/server/EphemeralTypeEmulate353.java
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper.server;
+
+/**
+ * See https://issues.apache.org/jira/browse/ZOOKEEPER-2901
+ *
+ * version 3.5.3 introduced bugs associated with how TTL nodes were implemented. version
3.5.4
+ * fixes the problems but makes TTL nodes created in 3.5.3 invalid. EphemeralTypeEmulate353
is a copy
+ * of the old - bad - implementation that is provided as a workaround. {@link EphemeralType#TTL_3_5_3_EMULATION_PROPERTY}
+ * can be used to emulate support of the badly specified TTL nodes.
+ */
+public enum EphemeralTypeEmulate353 {
+    /**
+     * Not ephemeral
+     */
+    VOID,
+    /**
+     * Standard, pre-3.5.x EPHEMERAL
+     */
+    NORMAL,
+    /**
+     * Container node
+     */
+    CONTAINER,
+    /**
+     * TTL node
+     */
+    TTL;
+
+    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 EphemeralTypeEmulate353 get(long ephemeralOwner) {
+        if (ephemeralOwner == CONTAINER_EPHEMERAL_OWNER) {
+            return CONTAINER;
+        }
+        if (ephemeralOwner < 0) {
+            return TTL;
+        }
+        return (ephemeralOwner == 0) ? VOID : NORMAL;
+    }
+
+    public static long ttlToEphemeralOwner(long ttl) {
+        if ((ttl > MAX_TTL) || (ttl <= 0)) {
+            throw new IllegalArgumentException("ttl must be positive and cannot be larger
than: " + MAX_TTL);
+        }
+        return TTL_MASK | ttl;
+    }
+}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/edb93d49/src/java/main/org/apache/zookeeper/server/OldEphemeralType.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/OldEphemeralType.java b/src/java/main/org/apache/zookeeper/server/OldEphemeralType.java
deleted file mode 100644
index bffec8a..0000000
--- a/src/java/main/org/apache/zookeeper/server/OldEphemeralType.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server;
-
-/**
- * See https://issues.apache.org/jira/browse/ZOOKEEPER-2901
- *
- * version 3.5.3 introduced bugs associated with how TTL nodes were implemented. version
3.5.4
- * fixes the problems but makes TTL nodes created in 3.5.3 invalid. OldEphemeralType is a
copy
- * of the old - bad - implementation that is provided as a workaround. {@link EphemeralType#TTL_3_5_3_EMULATION_PROPERTY}
- * can be used to emulate support of the badly specified TTL nodes.
- */
-public enum OldEphemeralType {
-    /**
-     * Not ephemeral
-     */
-    VOID,
-    /**
-     * Standard, pre-3.5.x EPHEMERAL
-     */
-    NORMAL,
-    /**
-     * Container node
-     */
-    CONTAINER,
-    /**
-     * TTL node
-     */
-    TTL;
-
-    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 OldEphemeralType get(long ephemeralOwner) {
-        if (ephemeralOwner == CONTAINER_EPHEMERAL_OWNER) {
-            return CONTAINER;
-        }
-        if (ephemeralOwner < 0) {
-            return TTL;
-        }
-        return (ephemeralOwner == 0) ? VOID : NORMAL;
-    }
-
-    public static long getTTL(long ephemeralOwner) {
-        if ((ephemeralOwner < 0) && (ephemeralOwner != CONTAINER_EPHEMERAL_OWNER))
{
-            return (ephemeralOwner & MAX_TTL);
-        }
-        return 0;
-    }
-
-    public static long ttlToEphemeralOwner(long ttl) {
-        if ((ttl > MAX_TTL) || (ttl <= 0)) {
-            throw new IllegalArgumentException("ttl must be positive and cannot be larger
than: " + MAX_TTL);
-        }
-        return TTL_MASK | ttl;
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/edb93d49/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java b/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
index da837b3..0ad9235 100644
--- a/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
+++ b/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
@@ -51,7 +51,6 @@ import org.apache.zookeeper.common.AtomicFileWritingIdiom.WriterStatement;
 import org.apache.zookeeper.common.Time;
 import org.apache.zookeeper.jmx.MBeanRegistry;
 import org.apache.zookeeper.jmx.ZKMBeanInfo;
-import org.apache.zookeeper.server.EphemeralType;
 import org.apache.zookeeper.server.ServerCnxnFactory;
 import org.apache.zookeeper.server.ZKDatabase;
 import org.apache.zookeeper.server.ZooKeeperServer;

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/edb93d49/src/java/test/org/apache/zookeeper/server/Emulate353TTLTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/Emulate353TTLTest.java b/src/java/test/org/apache/zookeeper/server/Emulate353TTLTest.java
index 4d7906e..c601a27 100644
--- a/src/java/test/org/apache/zookeeper/server/Emulate353TTLTest.java
+++ b/src/java/test/org/apache/zookeeper/server/Emulate353TTLTest.java
@@ -69,7 +69,7 @@ public class Emulate353TTLTest extends ClientBase {
     public void test353TTL()
             throws KeeperException, InterruptedException {
         DataTree dataTree = serverFactory.zkServer.getZKDatabase().dataTree;
-        long ephemeralOwner = OldEphemeralType.ttlToEphemeralOwner(100);
+        long ephemeralOwner = EphemeralTypeEmulate353.ttlToEphemeralOwner(100);
         dataTree.createNode("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, ephemeralOwner,
                 dataTree.getNode("/").stat.getCversion()+1, 1, 1);
 


Mime
View raw message