Skip to content

Commit

Permalink
Revert "Support for configurable Dynomite port (#202)"
Browse files Browse the repository at this point in the history
This reverts commit c6fd51d.
  • Loading branch information
shailesh33 committed Feb 9, 2018
1 parent c6fd51d commit 555c1a9
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ArchaiusConnectionPoolConfiguration extends ConnectionPoolConfigura

private static final String DynoPrefix = "dyno.";

private final DynamicIntProperty port;
//private final DynamicIntProperty port;
private final DynamicIntProperty maxConnsPerHost;
private final DynamicIntProperty maxTimeoutWhenExhausted;
private final DynamicIntProperty maxFailoverCount;
Expand All @@ -60,10 +60,8 @@ public class ArchaiusConnectionPoolConfiguration extends ConnectionPoolConfigura
public ArchaiusConnectionPoolConfiguration(String name) {
super(name);

String propertyPrefix = DynoPrefix + name;

port = DynamicPropertyFactory.getInstance().getIntProperty(propertyPrefix + ".connection.port", super.getPort());

String propertyPrefix = DynoPrefix + name;

maxConnsPerHost = DynamicPropertyFactory.getInstance().getIntProperty(propertyPrefix + ".connection.maxConnsPerHost", super.getMaxConnsPerHost());
maxTimeoutWhenExhausted = DynamicPropertyFactory.getInstance().getIntProperty(propertyPrefix + ".connection.maxTimeoutWhenExhausted", super.getMaxTimeoutWhenExhausted());
maxFailoverCount = DynamicPropertyFactory.getInstance().getIntProperty(propertyPrefix + ".connection.maxFailoverCount", super.getMaxFailoverCount());
Expand Down Expand Up @@ -91,10 +89,6 @@ public String getName() {
return super.getName();
}

@Override
public int getPort() {
return super.getPort();
}

@Override
public int getMaxConnsPerHost() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,20 @@ public class EurekaHostsSupplier implements HostSupplier {
// The Dynomite cluster name for discovering nodes
private final String applicationName;
private final EurekaClient discoveryClient;
private final int dynomitePort;

@Deprecated
public EurekaHostsSupplier(String applicationName, DiscoveryClient dClient, int dynomitePort) {
public EurekaHostsSupplier(String applicationName, DiscoveryClient dClient) {
this.applicationName = applicationName.toUpperCase();
this.discoveryClient = dClient;
this.dynomitePort = dynomitePort;
}
}

public EurekaHostsSupplier(String applicationName, EurekaClient dClient, int dynomitePort) {
public EurekaHostsSupplier(String applicationName, EurekaClient dClient) {
this.applicationName = applicationName.toUpperCase();
this.discoveryClient = dClient;
this.dynomitePort = dynomitePort;
this.discoveryClient = dClient;
}

public static EurekaHostsSupplier newInstance(String applicationName, EurekaHostsSupplier hostsSupplier) {
return new EurekaHostsSupplier(applicationName, hostsSupplier.getDiscoveryClient());
}

@Override
Expand Down Expand Up @@ -114,7 +115,7 @@ public Host apply(InstanceInfo info) {
if(rack == null) {
Logger.error("Rack wasn't found for host:" + info.getHostName() + " there may be issues matching it up to the token map");
}
Host host = new Host(info.getHostName(), info.getIPAddr(), dynomitePort, rack, status);
Host host = new Host(info.getHostName(), info.getIPAddr(), rack, status);
return host;
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ enum CompressionStrategy {
*/
String getName();

/**
* @return Data port to be used when no port is specified to a list of seeds or when
* doing a ring describe since the ring describe does not include a host
*/
int getPort();

/**
* Returns the maximum number of connections to allocate to each Dynomite host. Note that at startup exactly this
* number of connections will be established prior to serving requests.
Expand Down
21 changes: 10 additions & 11 deletions dyno-core/src/main/java/com/netflix/dyno/connectionpool/Host.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*/
public class Host implements Comparable<Host> {

public static final int DEFAULT_PORT = 8102;
public static final Host NO_HOST = new Host("UNKNOWN", "UNKNOWN", 0, "UNKNOWN");

private final String hostname;
Expand All @@ -52,6 +53,10 @@ public Host(String hostname, int port, String rack) {
this(hostname, null, port, rack, ConfigUtils.getDataCenterFromRack(rack), Status.Down, null);
}

public Host(String hostname, String rack, Status status) {
this(hostname, null, DEFAULT_PORT, rack, ConfigUtils.getDataCenterFromRack(rack), status, null);
}

public Host(String hostname, int port, String rack, Status status) {
this(hostname, null, port, rack, ConfigUtils.getDataCenterFromRack(rack), status, null);
}
Expand All @@ -64,12 +69,12 @@ public Host(String hostname, String ipAddress, int port, String rack) {
this(hostname, ipAddress, port, rack, ConfigUtils.getDataCenterFromRack(rack), Status.Down, null);
}

public Host(String hostname, String ipAddress, int port, String rack, Status status) {
this(hostname, ipAddress, port, rack, ConfigUtils.getDataCenterFromRack(rack), status, null);
public Host(String hostname, String ipAddress, String rack, Status status) {
this(hostname, ipAddress, DEFAULT_PORT, rack, ConfigUtils.getDataCenterFromRack(rack), status, null);
}

public Host(String hostname, String ipAddress, int port, String rack, Status status, String hashtag) {
this(hostname, ipAddress, port, rack, ConfigUtils.getDataCenterFromRack(rack), status, hashtag);
public Host(String hostname, String ipAddress, String rack, Status status, String hashtag) {
this(hostname, ipAddress, DEFAULT_PORT, rack, ConfigUtils.getDataCenterFromRack(rack), status, hashtag);
}

public Host(String hostname, String ipAddress, int port, String rack, String datacenter, Status status) {
Expand Down Expand Up @@ -153,7 +158,6 @@ public int hashCode() {
int result = 1;
result = prime * result + ((hostname == null) ? 0 : hostname.hashCode());
result = prime * result + ((rack == null) ? 0 : rack.hashCode());
result = prime * result + port;

return result;
}
Expand All @@ -174,7 +178,6 @@ public boolean equals(Object obj) {

equals &= (hostname != null) ? hostname.equals(other.hostname) : other.hostname == null;
equals &= (rack != null) ? rack.equals(other.rack) : other.rack == null;
equals &= (port == other.port);

return equals;
}
Expand All @@ -185,11 +188,7 @@ public int compareTo(Host o) {
if (compared != 0) {
return compared;
}
compared = this.rack.compareTo(o.rack);
if (compared != 0) {
return compared;
}
return Integer.compare(this.port, o.port);
return this.rack.compareTo(o.rack);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@

public class ConnectionPoolConfigurationImpl implements ConnectionPoolConfiguration {

// DEFAULTS
public static final int DEFAULT_DYNOMITE_PORT = 8102;
// DEFAULTS
private static final int DEFAULT_MAX_CONNS_PER_HOST = 3;
private static final int DEFAULT_MAX_TIMEOUT_WHEN_EXHAUSTED = 800;
private static final int DEFAULT_MAX_FAILOVER_COUNT = 3;
Expand All @@ -57,7 +56,6 @@ public class ConnectionPoolConfigurationImpl implements ConnectionPoolConfigurat
private HashPartitioner hashPartitioner;
private String hashtag;
private final String name;
private int port = DEFAULT_DYNOMITE_PORT;
private int maxConnsPerHost = DEFAULT_MAX_CONNS_PER_HOST;
private int maxTimeoutWhenExhausted = DEFAULT_MAX_TIMEOUT_WHEN_EXHAUSTED;
private int maxFailoverCount = DEFAULT_MAX_FAILOVER_COUNT;
Expand Down Expand Up @@ -115,7 +113,6 @@ public ConnectionPoolConfigurationImpl(ConnectionPoolConfigurationImpl config) {
this.localDataCenter = config.getLocalDataCenter();
this.localRack = config.getLocalRack();
this.localZoneAffinity = config.localZoneAffinity;
this.port = config.getPort();
this.maxConnsPerHost = config.getMaxConnsPerHost();
this.maxFailoverCount = config.getMaxFailoverCount();
this.maxTimeoutWhenExhausted = config.getMaxTimeoutWhenExhausted();
Expand All @@ -136,10 +133,6 @@ public String getName() {
return name;
}

@Override
public int getPort() {
return port;
}

@Override
public int getMaxConnsPerHost() {
Expand Down Expand Up @@ -254,7 +247,6 @@ public String toString() {
", tokenSupplier=" + tokenSupplier +
", hostConnectionPoolFactory=" + hostConnectionPoolFactory +
", name='" + name + '\'' +
", port=" + port +
", maxConnsPerHost=" + maxConnsPerHost +
", maxTimeoutWhenExhausted=" + maxTimeoutWhenExhausted +
", maxFailoverCount=" + maxFailoverCount +
Expand Down Expand Up @@ -282,11 +274,6 @@ public String toString() {
}

// ALL SETTERS
public ConnectionPoolConfigurationImpl setPort(int port) {
this.port = port;
return this;
}

public ConnectionPoolConfigurationImpl setMaxConnsPerHost(int maxConnsPerHost) {
this.maxConnsPerHost = maxConnsPerHost;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,28 @@ public abstract class AbstractTokenMapSupplier implements TokenMapSupplier {
private static final Logger Logger = LoggerFactory.getLogger(AbstractTokenMapSupplier.class);
private final String localZone;
private final String localDatacenter;
private final int dynomitePort;
private int unsuppliedPort = -1;

public AbstractTokenMapSupplier(String localRack, int dynomitePort) {
this(localRack, ConfigUtils.getDataCenter(), dynomitePort);
public AbstractTokenMapSupplier(String localRack) {
this.localZone = localRack;
localDatacenter = ConfigUtils.getDataCenter();
}

public AbstractTokenMapSupplier(int dynomitePort) {
this(ConfigUtils.getLocalZone(), ConfigUtils.getDataCenter(), dynomitePort);
public AbstractTokenMapSupplier(String localRack, int port) {
this.localZone = localRack;
localDatacenter = ConfigUtils.getDataCenter();
unsuppliedPort = port;
}

public AbstractTokenMapSupplier(String localRack, String localDatacenter, int dynomitePort) {
this.localZone = localRack;
this.localDatacenter = localDatacenter;
this.dynomitePort = dynomitePort;
public AbstractTokenMapSupplier() {
localZone = ConfigUtils.getLocalZone();
localDatacenter = ConfigUtils.getDataCenter();
}

public AbstractTokenMapSupplier(int port) {
localZone = ConfigUtils.getLocalZone();
localDatacenter = ConfigUtils.getDataCenter();
unsuppliedPort = port;
}

public abstract String getTopologyJsonPayload(Set<Host> activeHosts);
Expand Down Expand Up @@ -220,7 +228,7 @@ List<HostToken> parseTokenListFromJson(String json) {
String datacenter = (String) jItem.get("dc");
String portStr = (String) jItem.get("port");
String hashtag = (String) jItem.get("hashtag");
int port = dynomitePort;
int port = Host.DEFAULT_PORT;
if (portStr != null) {
port = Integer.valueOf(portStr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@ public class HttpEndpointBasedTokenMapSupplier extends AbstractTokenMapSupplier
private static final String DefaultServerUrl = "http://{hostname}:{port}/REST/v1/admin/cluster_describe";
private static final Integer NUM_RETRIES_PER_NODE = 2;
private static final Integer NUM_RETRIER_ACROSS_NODES = 2;
private static final Integer defaultHttpPort = 8080;
private static final Integer defaultPort = 8080;

private final String serverUrl;

public HttpEndpointBasedTokenMapSupplier(int dynomitePort) {
this(DefaultServerUrl, defaultHttpPort, dynomitePort);
public HttpEndpointBasedTokenMapSupplier() {
this(DefaultServerUrl, defaultPort);
}

public HttpEndpointBasedTokenMapSupplier(int httpPort, int dynomitePort) {
this(DefaultServerUrl, httpPort, dynomitePort);
public HttpEndpointBasedTokenMapSupplier(int port) {
this(DefaultServerUrl, port);
}

public HttpEndpointBasedTokenMapSupplier(String url, int httpPort, int dynomitePort) {
super(dynomitePort);
public HttpEndpointBasedTokenMapSupplier(String url, int port) {
super(port);

/**
* If no port is passed means -1 then we will substitute to defaultPort
* else the passed one.
*/
url = url.replace("{port}", (httpPort > -1) ? Integer.toString(httpPort) : Integer.toString(defaultHttpPort));
url = url.replace("{port}", (port > -1) ? Integer.toString(port) : Integer.toString(defaultPort));
serverUrl = url;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;

import com.netflix.dyno.connectionpool.ConnectionPool;
import org.apache.log4j.BasicConfigurator;
import org.junit.AfterClass;
import org.junit.Assert;
Expand Down Expand Up @@ -67,7 +66,7 @@ public void testConnectionPoolRecycle() throws Exception {
ConnectionPoolHealthTracker<Integer> tracker = new ConnectionPoolHealthTracker<Integer>(config, threadPool, 1000, -1);
tracker.start();

Host h1 = new Host("h1", ConnectionPoolConfigurationImpl.DEFAULT_DYNOMITE_PORT,"r1", Status.Up);
Host h1 = new Host("h1", "r1", Status.Up);
AtomicBoolean poolStatus = new AtomicBoolean(false);
HostConnectionPool<Integer> hostPool = getMockConnectionPool(h1, poolStatus);

Expand Down Expand Up @@ -95,7 +94,7 @@ public void testBadConnectionPoolKeepsReconnecting() throws Exception {
ConnectionPoolHealthTracker<Integer> tracker = new ConnectionPoolHealthTracker<Integer>(config, threadPool, 1000, -1);
tracker.start();

Host h1 = new Host("h1", ConnectionPoolConfigurationImpl.DEFAULT_DYNOMITE_PORT,"r1", Status.Up);
Host h1 = new Host("h1", "r1", Status.Up);
AtomicBoolean poolStatus = new AtomicBoolean(false);
HostConnectionPool<Integer> hostPool = getMockConnectionPool(h1, poolStatus, true);

Expand Down
Loading

0 comments on commit 555c1a9

Please sign in to comment.