From 1a904da729b5b64f23b9c3285e4a3fa8468fe9ab Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Mon, 19 Apr 2010 20:10:56 +0000 Subject: [PATCH] rename snitches to emphasize that RackAware is adding extra functionality that is not needed for simpler replication strategies. patch by Erick Tryzelaar; reviewed by jbellis for CASSANDRA-994 git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@935725 13f79535-47bb-0310-9956-ffa450edef68 --- conf/cassandra.xml | 9 ++- contrib/property_snitch/README.txt | 44 ----------- contrib/property_snitch/build.xml | 77 ------------------- .../conf/cassandra-rack.properties | 23 ------ ...itch.java => AbstractRackAwareSnitch.java} | 10 +-- .../locator/DatacenterEndpointSnitch.java | 2 +- .../cassandra/locator/PropertyFileSnitch.java | 12 +-- .../locator/PropertyFileSnitchMBean.java | 16 ++-- .../cassandra/locator/RackAwareStrategy.java | 10 +-- ...ntSnitch.java => RackInferringSnitch.java} | 10 +-- test/conf/cassandra.xml | 5 +- .../locator/RackAwareStrategyTest.java | 6 +- 12 files changed, 39 insertions(+), 185 deletions(-) delete mode 100644 contrib/property_snitch/README.txt delete mode 100644 contrib/property_snitch/build.xml delete mode 100644 contrib/property_snitch/conf/cassandra-rack.properties rename src/java/org/apache/cassandra/locator/{AbstractEndpointSnitch.java => AbstractRackAwareSnitch.java} (97%) rename contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndpointSnitch.java => src/java/org/apache/cassandra/locator/PropertyFileSnitch.java (93%) rename contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndpointSnitchMBean.java => src/java/org/apache/cassandra/locator/PropertyFileSnitchMBean.java (86%) rename src/java/org/apache/cassandra/locator/{EndpointSnitch.java => RackInferringSnitch.java} (88%) diff --git a/conf/cassandra.xml b/conf/cassandra.xml index d654cdcb1e..eccfbf94f6 100644 --- a/conf/cassandra.xml +++ b/conf/cassandra.xml @@ -47,12 +47,13 @@ - org.apache.cassandra.locator.EndpointSnitch + org.apache.cassandra.locator.RackInferringSnitch - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/contrib/property_snitch/conf/cassandra-rack.properties b/contrib/property_snitch/conf/cassandra-rack.properties deleted file mode 100644 index 5ebb0537af..0000000000 --- a/contrib/property_snitch/conf/cassandra-rack.properties +++ /dev/null @@ -1,23 +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 -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# 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. - -#Cassandra Node IP:Port=Data Center:Rack -192.168.1.200\:7000=dc1:r1 -192.168.2.300\:7000=dc2:rA - -#default for unknown nodes -default=dc1:r1 diff --git a/src/java/org/apache/cassandra/locator/AbstractEndpointSnitch.java b/src/java/org/apache/cassandra/locator/AbstractRackAwareSnitch.java similarity index 97% rename from src/java/org/apache/cassandra/locator/AbstractEndpointSnitch.java rename to src/java/org/apache/cassandra/locator/AbstractRackAwareSnitch.java index 03c71f7d1c..03dd0dd4f0 100644 --- a/src/java/org/apache/cassandra/locator/AbstractEndpointSnitch.java +++ b/src/java/org/apache/cassandra/locator/AbstractRackAwareSnitch.java @@ -1,6 +1,6 @@ package org.apache.cassandra.locator; /* - * + * * 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 @@ -8,16 +8,16 @@ package org.apache.cassandra.locator; * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * 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. - * + * */ @@ -30,7 +30,7 @@ import java.util.*; * requests more efficiently (with "sortByProximity"). Of the abstract methods, isOnSameRack * and isInSameDataCenter are always required; getLocation is only used by DatacenterShardStrategy. */ -public abstract class AbstractEndpointSnitch implements IEndpointSnitch +public abstract class AbstractRackAwareSnitch implements IEndpointSnitch { /** * Determines if 2 nodes are in the same rack in the data center. diff --git a/src/java/org/apache/cassandra/locator/DatacenterEndpointSnitch.java b/src/java/org/apache/cassandra/locator/DatacenterEndpointSnitch.java index 2615f6e9c8..1ab6217b9f 100644 --- a/src/java/org/apache/cassandra/locator/DatacenterEndpointSnitch.java +++ b/src/java/org/apache/cassandra/locator/DatacenterEndpointSnitch.java @@ -41,7 +41,7 @@ import org.xml.sax.SAXException; * Endpoints and also get details from the same. */ -public class DatacenterEndpointSnitch extends AbstractEndpointSnitch +public class DatacenterEndpointSnitch extends AbstractRackAwareSnitch { /** * This Map will contain the information of the Endpoints and its Location diff --git a/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndpointSnitch.java b/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java similarity index 93% rename from contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndpointSnitch.java rename to src/java/org/apache/cassandra/locator/PropertyFileSnitch.java index bc3f7cc7a1..af8f2f0978 100644 --- a/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndpointSnitch.java +++ b/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java @@ -36,13 +36,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * PropertyFileEndpointSnitch + * PropertyFileSnitch * - * PropertyFileEndpointSnitch is used by Digg to determine if two IP's are in the same + * PropertyFileSnitch is used by Digg to determine if two IP's are in the same * datacenter or on the same rack. * */ -public class PropertyFileEndpointSnitch extends EndpointSnitch implements PropertyFileEndpointSnitchMBean { +public class PropertyFileSnitch extends RackInferringSnitch implements PropertyFileSnitchMBean { /** * A list of properties with keys being host:port and values being datacenter:rack */ @@ -61,9 +61,9 @@ public class PropertyFileEndpointSnitch extends EndpointSnitch implements Proper /** * Reference to the logger. */ - private static Logger logger_ = LoggerFactory.getLogger(PropertyFileEndpointSnitch.class); + private static Logger logger_ = LoggerFactory.getLogger(PropertyFileSnitch.class); - public PropertyFileEndpointSnitch() throws ConfigurationException + public PropertyFileSnitch() throws ConfigurationException { reloadConfiguration(); try @@ -158,7 +158,7 @@ public class PropertyFileEndpointSnitch extends EndpointSnitch implements Proper public void reloadConfiguration() throws ConfigurationException { - ClassLoader loader = PropertyFileEndpointSnitch.class.getClassLoader(); + ClassLoader loader = PropertyFileSnitch.class.getClassLoader(); URL scpurl = loader.getResource(RACK_PROPERTY_FILENAME); if (scpurl == null) throw new ConfigurationException("unable to locate " + RACK_PROPERTY_FILENAME); diff --git a/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndpointSnitchMBean.java b/src/java/org/apache/cassandra/locator/PropertyFileSnitchMBean.java similarity index 86% rename from contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndpointSnitchMBean.java rename to src/java/org/apache/cassandra/locator/PropertyFileSnitchMBean.java index 2d11314301..a512645f89 100644 --- a/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndpointSnitchMBean.java +++ b/src/java/org/apache/cassandra/locator/PropertyFileSnitchMBean.java @@ -23,24 +23,24 @@ import java.io.IOException; import org.apache.cassandra.config.ConfigurationException; /** - * PropertyFileEndpointSnitchMBean - * - * PropertyFileEndpointSnitchMBean is the management interface for Digg's EndpointSnitch MBean - * + * PropertyFileSnitchMBean + * + * PropertyFileSnitchMBean is the management interface for Digg's EndpointSnitch MBean + * * @author Sammy Yu - * + * */ -public interface PropertyFileEndpointSnitchMBean { +public interface PropertyFileSnitchMBean { /** * The object name of the mbean. */ public static String MBEAN_OBJECT_NAME = "org.apache.cassandra.locator:type=EndpointSnitch"; - + /** * Reload the rack configuration */ public void reloadConfiguration() throws ConfigurationException; - + /** * Display the current configuration */ diff --git a/src/java/org/apache/cassandra/locator/RackAwareStrategy.java b/src/java/org/apache/cassandra/locator/RackAwareStrategy.java index 77285f673b..991b1ab3bc 100644 --- a/src/java/org/apache/cassandra/locator/RackAwareStrategy.java +++ b/src/java/org/apache/cassandra/locator/RackAwareStrategy.java @@ -39,8 +39,8 @@ public class RackAwareStrategy extends AbstractReplicationStrategy public RackAwareStrategy(TokenMetadata tokenMetadata, IEndpointSnitch snitch) { super(tokenMetadata, snitch); - if (!(snitch instanceof EndpointSnitch)) - throw new IllegalArgumentException(("RackAwareStrategy requires EndpointSnitch.")); + if (!(snitch instanceof AbstractRackAwareSnitch)) + throw new IllegalArgumentException(("RackAwareStrategy requires AbstractRackAwareSnitch.")); } public ArrayList getNaturalEndpoints(Token token, TokenMetadata metadata, String table) @@ -64,7 +64,7 @@ public class RackAwareStrategy extends AbstractReplicationStrategy { // First try to find one in a different data center Token t = iter.next(); - if (!((EndpointSnitch)snitch_).isInSameDataCenter(metadata.getEndpoint(primaryToken), metadata.getEndpoint(t))) + if (!((AbstractRackAwareSnitch)snitch_).isInSameDataCenter(metadata.getEndpoint(primaryToken), metadata.getEndpoint(t))) { // If we have already found something in a diff datacenter no need to find another if (!bDataCenter) @@ -75,8 +75,8 @@ public class RackAwareStrategy extends AbstractReplicationStrategy continue; } // Now try to find one on a different rack - if (!((EndpointSnitch)snitch_).isOnSameRack(metadata.getEndpoint(primaryToken), metadata.getEndpoint(t)) && - ((EndpointSnitch)snitch_).isInSameDataCenter(metadata.getEndpoint(primaryToken), metadata.getEndpoint(t))) + if (!((AbstractRackAwareSnitch)snitch_).isOnSameRack(metadata.getEndpoint(primaryToken), metadata.getEndpoint(t)) && + ((AbstractRackAwareSnitch)snitch_).isInSameDataCenter(metadata.getEndpoint(primaryToken), metadata.getEndpoint(t))) { // If we have already found something in a diff rack no need to find another if (!bOtherRack) diff --git a/src/java/org/apache/cassandra/locator/EndpointSnitch.java b/src/java/org/apache/cassandra/locator/RackInferringSnitch.java similarity index 88% rename from src/java/org/apache/cassandra/locator/EndpointSnitch.java rename to src/java/org/apache/cassandra/locator/RackInferringSnitch.java index 15ae9e4881..ad2167d320 100644 --- a/src/java/org/apache/cassandra/locator/EndpointSnitch.java +++ b/src/java/org/apache/cassandra/locator/RackInferringSnitch.java @@ -26,14 +26,14 @@ import java.util.*; * A simple endpoint snitch implementation that assumes rack and dc information is encoded * in the ip address. */ -public class EndpointSnitch extends AbstractEndpointSnitch +public class RackInferringSnitch extends AbstractRackAwareSnitch { public boolean isOnSameRack(InetAddress host, InetAddress host2) throws UnknownHostException { /* - * Look at the IP Address of the two hosts. Compare + * Look at the IP Address of the two hosts. Compare * the 3rd octet. If they are the same then the hosts - * are in the same rack else different racks. + * are in the same rack else different racks. */ byte[] ip = host.getAddress(); byte[] ip2 = host2.getAddress(); @@ -44,9 +44,9 @@ public class EndpointSnitch extends AbstractEndpointSnitch public boolean isInSameDataCenter(InetAddress host, InetAddress host2) throws UnknownHostException { /* - * Look at the IP Address of the two hosts. Compare + * Look at the IP Address of the two hosts. Compare * the 2nd octet. If they are the same then the hosts - * are in the same datacenter else different datacenter. + * are in the same datacenter else different datacenter. */ byte[] ip = host.getAddress(); byte[] ip2 = host2.getAddress(); diff --git a/test/conf/cassandra.xml b/test/conf/cassandra.xml index 6d64d5aef4..d6c094b2ec 100644 --- a/test/conf/cassandra.xml +++ b/test/conf/cassandra.xml @@ -37,7 +37,7 @@ mmap 1 0.00002 - org.apache.cassandra.locator.EndpointSnitch + org.apache.cassandra.locator.RackInferringSnitch @@ -58,13 +58,11 @@ org.apache.cassandra.locator.RackUnawareStrategy 1 - org.apache.cassandra.locator.EndpointSnitch org.apache.cassandra.locator.RackUnawareStrategy 5 - org.apache.cassandra.locator.EndpointSnitch @@ -73,7 +71,6 @@ org.apache.cassandra.locator.RackUnawareStrategy 3 - org.apache.cassandra.locator.EndpointSnitch diff --git a/test/unit/org/apache/cassandra/locator/RackAwareStrategyTest.java b/test/unit/org/apache/cassandra/locator/RackAwareStrategyTest.java index 7da0a90b62..28c360c434 100644 --- a/test/unit/org/apache/cassandra/locator/RackAwareStrategyTest.java +++ b/test/unit/org/apache/cassandra/locator/RackAwareStrategyTest.java @@ -58,7 +58,7 @@ public class RackAwareStrategyTest @Test public void testBigIntegerEndpointsA() throws UnknownHostException { - EndpointSnitch endpointSnitch = new EndpointSnitch(); + RackInferringSnitch endpointSnitch = new RackInferringSnitch(); AbstractReplicationStrategy strategy = new RackAwareStrategy(tmd, endpointSnitch); addEndpoint("0", "5", "254.0.0.1"); @@ -83,7 +83,7 @@ public class RackAwareStrategyTest @Test public void testBigIntegerEndpointsB() throws UnknownHostException { - EndpointSnitch endpointSnitch = new EndpointSnitch(); + RackInferringSnitch endpointSnitch = new RackInferringSnitch(); AbstractReplicationStrategy strategy = new RackAwareStrategy(tmd, endpointSnitch); addEndpoint("0", "5", "254.0.0.1"); @@ -109,7 +109,7 @@ public class RackAwareStrategyTest @Test public void testBigIntegerEndpointsC() throws UnknownHostException { - EndpointSnitch endpointSnitch = new EndpointSnitch(); + RackInferringSnitch endpointSnitch = new RackInferringSnitch(); AbstractReplicationStrategy strategy = new RackAwareStrategy(tmd, endpointSnitch); addEndpoint("0", "5", "254.0.0.1");