You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2013/06/20 22:47:20 UTC
[2/3] git commit: cleanup
cleanup
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/7dc2eb95
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/7dc2eb95
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/7dc2eb95
Branch: refs/heads/trunk
Commit: 7dc2eb95c1752eb661b93c72a831ceb783d42ce4
Parents: 998fe96
Author: Jonathan Ellis <jb...@apache.org>
Authored: Thu Jun 20 15:47:06 2013 -0500
Committer: Jonathan Ellis <jb...@apache.org>
Committed: Thu Jun 20 15:47:06 2013 -0500
----------------------------------------------------------------------
.../cassandra/locator/Ec2MultiRegionSnitch.java | 42 +++++++++++---------
1 file changed, 23 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/7dc2eb95/src/java/org/apache/cassandra/locator/Ec2MultiRegionSnitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/Ec2MultiRegionSnitch.java b/src/java/org/apache/cassandra/locator/Ec2MultiRegionSnitch.java
index ea41bc0..9317941 100644
--- a/src/java/org/apache/cassandra/locator/Ec2MultiRegionSnitch.java
+++ b/src/java/org/apache/cassandra/locator/Ec2MultiRegionSnitch.java
@@ -49,35 +49,35 @@ public class Ec2MultiRegionSnitch extends Ec2Snitch implements IEndpointStateCha
{
private static final String PUBLIC_IP_QUERY_URL = "http://169.254.169.254/latest/meta-data/public-ipv4";
private static final String PRIVATE_IP_QUERY_URL = "http://169.254.169.254/latest/meta-data/local-ipv4";
- private final InetAddress public_ip;
- private final String private_ip;
+ private final InetAddress localPublicAddress;
+ private final String localPrivateAddress;
public Ec2MultiRegionSnitch() throws IOException, ConfigurationException
{
super();
- public_ip = InetAddress.getByName(awsApiCall(PUBLIC_IP_QUERY_URL));
- logger.info("EC2Snitch using publicIP as identifier: " + public_ip);
- private_ip = awsApiCall(PRIVATE_IP_QUERY_URL);
+ localPublicAddress = InetAddress.getByName(awsApiCall(PUBLIC_IP_QUERY_URL));
+ logger.info("EC2Snitch using publicIP as identifier: " + localPublicAddress);
+ localPrivateAddress = awsApiCall(PRIVATE_IP_QUERY_URL);
// use the Public IP to broadcast Address to other nodes.
- DatabaseDescriptor.setBroadcastAddress(public_ip);
+ DatabaseDescriptor.setBroadcastAddress(localPublicAddress);
}
public void onJoin(InetAddress endpoint, EndpointState epState)
{
if (epState.getApplicationState(ApplicationState.INTERNAL_IP) != null)
- reConnect(endpoint, epState.getApplicationState(ApplicationState.INTERNAL_IP));
+ reconnect(endpoint, epState.getApplicationState(ApplicationState.INTERNAL_IP));
}
public void onChange(InetAddress endpoint, ApplicationState state, VersionedValue value)
{
if (state == ApplicationState.INTERNAL_IP)
- reConnect(endpoint, value);
+ reconnect(endpoint, value);
}
public void onAlive(InetAddress endpoint, EndpointState state)
{
if (state.getApplicationState(ApplicationState.INTERNAL_IP) != null)
- reConnect(endpoint, state.getApplicationState(ApplicationState.INTERNAL_IP));
+ reconnect(endpoint, state.getApplicationState(ApplicationState.INTERNAL_IP));
}
public void onDead(InetAddress endpoint, EndpointState state)
@@ -95,18 +95,11 @@ public class Ec2MultiRegionSnitch extends Ec2Snitch implements IEndpointStateCha
// do nothing.
}
- private void reConnect(InetAddress endpoint, VersionedValue versionedValue)
+ private void reconnect(InetAddress publicAddress, VersionedValue localAddressValue)
{
try
{
- InetAddress localEc2IP = InetAddress.getByName(versionedValue.value);
- if (getDatacenter(endpoint).equals(getDatacenter(public_ip))
- && MessagingService.instance().getVersion(endpoint) == MessagingService.current_version
- && !MessagingService.instance().getConnectionPool(endpoint).endPoint().equals(localEc2IP))
- {
- MessagingService.instance().getConnectionPool(endpoint).reset(localEc2IP);
- logger.debug(String.format("Intiated reconnect to an Internal IP %s for the %s", localEc2IP, endpoint));
- }
+ reconnect(publicAddress, InetAddress.getByName(localAddressValue.value));
}
catch (UnknownHostException e)
{
@@ -114,11 +107,22 @@ public class Ec2MultiRegionSnitch extends Ec2Snitch implements IEndpointStateCha
}
}
+ private void reconnect(InetAddress publicAddress, InetAddress localAddress)
+ {
+ if (getDatacenter(publicAddress).equals(getDatacenter(localPublicAddress))
+ && MessagingService.instance().getVersion(publicAddress) == MessagingService.current_version
+ && !MessagingService.instance().getConnectionPool(publicAddress).endPoint().equals(localAddress))
+ {
+ MessagingService.instance().getConnectionPool(publicAddress).reset(localAddress);
+ logger.debug(String.format("Intiated reconnect to an Internal IP %s for the %s", localAddress, publicAddress));
+ }
+ }
+
@Override
public void gossiperStarting()
{
super.gossiperStarting();
- Gossiper.instance.addLocalApplicationState(ApplicationState.INTERNAL_IP, StorageService.instance.valueFactory.internalIP(private_ip));
+ Gossiper.instance.addLocalApplicationState(ApplicationState.INTERNAL_IP, StorageService.instance.valueFactory.internalIP(localPrivateAddress));
Gossiper.instance.register(this);
}
}