Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5E1AE1007C for ; Fri, 14 Jun 2013 16:21:55 +0000 (UTC) Received: (qmail 51692 invoked by uid 500); 14 Jun 2013 16:21:55 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 51668 invoked by uid 500); 14 Jun 2013 16:21:54 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 51642 invoked by uid 99); 14 Jun 2013 16:21:51 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Jun 2013 16:21:51 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id F2FF4816F98; Fri, 14 Jun 2013 16:21:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: brandonwilliams@apache.org To: commits@cassandra.apache.org Date: Fri, 14 Jun 2013 16:21:50 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: Allow GPFS to reconnect to the internal IP. Patch by Chris Burroughs, reviewed by brandonwilliams for CASSANDRA-5630 Updated Branches: refs/heads/trunk 4bdf38b5c -> 47d5f124d Allow GPFS to reconnect to the internal IP. Patch by Chris Burroughs, reviewed by brandonwilliams for CASSANDRA-5630 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/4ef8a8a1 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/4ef8a8a1 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/4ef8a8a1 Branch: refs/heads/trunk Commit: 4ef8a8a19412adcca4b0225756d5940a2cb1427a Parents: f51c962 Author: Brandon Williams Authored: Fri Jun 14 11:19:56 2013 -0500 Committer: Brandon Williams Committed: Fri Jun 14 11:21:17 2013 -0500 ---------------------------------------------------------------------- CHANGES.txt | 1 + conf/cassandra-rackdc.properties | 3 + .../locator/GossipingPropertyFileSnitch.java | 72 +++++++++++++++++++- 3 files changed, 74 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ef8a8a1/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index a063d69..a1fc8ce 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -22,6 +22,7 @@ * Evaluate now() function at execution time (CASSANDRA-5616) * Expose detailed read repair metrics (CASSANDRA-5618) * Correct blob literal + ReversedType parsing (CASSANDRA-5629) + * Allow GPFS to prefer the internal IP like EC2MRS (CASSANDRA-5630) Merged from 1.1: * Remove buggy thrift max message length option (CASSANDRA-5529) * Fix NPE in Pig's widerow mode (CASSANDRA-5488) http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ef8a8a1/conf/cassandra-rackdc.properties ---------------------------------------------------------------------- diff --git a/conf/cassandra-rackdc.properties b/conf/cassandra-rackdc.properties index be2e7d2..f0a0d55 100644 --- a/conf/cassandra-rackdc.properties +++ b/conf/cassandra-rackdc.properties @@ -22,3 +22,6 @@ rack=RAC1 # Add a suffix to a datacenter name. Used by the Ec2Snitch and Ec2MultiRegionSnitch # to append a string to the EC2 region name. #dc_suffix= + +# Uncomment the following line to make this snitch prefer the internal ip when possible, as the Ec2MultiRegionSnitch does. +# prefer_local=true http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ef8a8a1/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java b/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java index e08a27e..071cd09 100644 --- a/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java +++ b/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java @@ -19,6 +19,7 @@ package org.apache.cassandra.locator; import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.Map; import org.apache.cassandra.db.SystemTable; @@ -29,9 +30,14 @@ import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.gms.ApplicationState; import org.apache.cassandra.gms.EndpointState; import org.apache.cassandra.gms.Gossiper; +import org.apache.cassandra.gms.IEndpointStateChangeSubscriber; +import org.apache.cassandra.gms.VersionedValue; +import org.apache.cassandra.net.MessagingService; import org.apache.cassandra.utils.FBUtilities; +import org.apache.cassandra.service.StorageService; -public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch + +public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch implements IEndpointStateChangeSubscriber { private static final Logger logger = LoggerFactory.getLogger(GossipingPropertyFileSnitch.class); @@ -41,6 +47,7 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch private Map> savedEndpoints; private String DEFAULT_DC = "UNKNOWN_DC"; private String DEFAULT_RACK = "UNKNOWN_RACK"; + private boolean preferLocal; public GossipingPropertyFileSnitch() throws ConfigurationException { @@ -51,7 +58,7 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch myDC = myDC.trim(); myRack = myRack.trim(); - + preferLocal = Boolean.parseBoolean(SnitchProperties.get("prefer_local", "false")); try { psnitch = new PropertyFileSnitch(); @@ -118,4 +125,65 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch } return epState.getApplicationState(ApplicationState.RACK).value; } + + // IEndpointStateChangeSubscriber methods + + public void onJoin(InetAddress endpoint, EndpointState epState) + { + if (preferLocal && epState.getApplicationState(ApplicationState.INTERNAL_IP) != null) + reConnect(endpoint, epState.getApplicationState(ApplicationState.INTERNAL_IP)); + } + + public void onChange(InetAddress endpoint, ApplicationState state, VersionedValue value) + { + if (preferLocal && state == ApplicationState.INTERNAL_IP) + reConnect(endpoint, value); + } + + public void onAlive(InetAddress endpoint, EndpointState state) + { + if (preferLocal && state.getApplicationState(ApplicationState.INTERNAL_IP) != null) + reConnect(endpoint, state.getApplicationState(ApplicationState.INTERNAL_IP)); + } + + public void onDead(InetAddress endpoint, EndpointState state) + { + // do nothing + } + + public void onRestart(InetAddress endpoint, EndpointState state) + { + // do nothing + } + + public void onRemove(InetAddress endpoint) + { + // do nothing. + } + + private void reConnect(InetAddress endpoint, VersionedValue versionedValue) + { + if (!getDatacenter(endpoint).equals(myDC)) + return; // do nothing return back... + + try + { + InetAddress remoteIP = InetAddress.getByName(versionedValue.value); + MessagingService.instance().getConnectionPool(endpoint).reset(remoteIP); + logger.debug(String.format("Intiated reconnect to an Internal IP %s for the endpoint %s", remoteIP, endpoint)); + } + catch (UnknownHostException e) + { + logger.error("Error in getting the IP address resolved", e); + } + } + + @Override + public void gossiperStarting() + { + super.gossiperStarting(); + Gossiper.instance.addLocalApplicationState(ApplicationState.INTERNAL_IP, + StorageService.instance.valueFactory.internalIP(FBUtilities.getLocalAddress().getHostAddress())); + Gossiper.instance.register(this); + } }