Skip to content

Commit

Permalink
ZOOKEEPER-3038: Cleanup some nitpicks in TTL implementation
Browse files Browse the repository at this point in the history
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 <[email protected]>

Reviewers: [email protected]

Closes apache#516 from anmolnar/ZOOKEEPER-3038

Change-Id: Iec537706a35863d53daa593da2b01f6e523ef466
  • Loading branch information
anmolnar authored and Fangmin Lyu committed Jun 17, 2018
1 parent 2833a4e commit ddb0963
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static boolean extendedEphemeralTypesEnabled() {
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
* 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
* 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 OldEphemeralType {
public enum EphemeralTypeEmulate353 {
/**
* Not ephemeral
*/
Expand All @@ -48,7 +48,7 @@ public enum OldEphemeralType {
public static final long MAX_TTL = 0x0fffffffffffffffL;
public static final long TTL_MASK = 0x8000000000000000L;

public static OldEphemeralType get(long ephemeralOwner) {
public static EphemeralTypeEmulate353 get(long ephemeralOwner) {
if (ephemeralOwner == CONTAINER_EPHEMERAL_OWNER) {
return CONTAINER;
}
Expand All @@ -58,13 +58,6 @@ public static OldEphemeralType get(long ephemeralOwner) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testCreate()
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);

Expand Down

0 comments on commit ddb0963

Please sign in to comment.