mirror of https://github.com/apache/cassandra
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
This commit is contained in:
parent
7a4a7090cb
commit
1a904da729
|
|
@ -47,12 +47,13 @@
|
|||
|
||||
<!--
|
||||
~ EndpointSnitch: Setting this to the class that implements
|
||||
~ AbstractEndpointSnitch, which lets Cassandra know enough
|
||||
~ IEndpointSnitch, which lets Cassandra know enough
|
||||
~ about your network topology to route requests efficiently.
|
||||
~ Out of the box, Cassandra provides org.apache.cassandra.locator.EndpointSnitch,
|
||||
~ and PropertyFileEndpointSnitch is available in contrib/.
|
||||
~ Out of the box, Cassandra provides
|
||||
~ org.apache.cassandra.locator.RackInferringSnitch and
|
||||
~ org.apache.cassandra.locator.PropertyFileSnitch.
|
||||
-->
|
||||
<EndpointSnitch>org.apache.cassandra.locator.EndpointSnitch</EndpointSnitch>
|
||||
<EndpointSnitch>org.apache.cassandra.locator.RackInferringSnitch</EndpointSnitch>
|
||||
|
||||
<!--
|
||||
~ Keyspaces and ColumnFamilies:
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
PropertyFileEndpointSnitch
|
||||
==========================
|
||||
|
||||
Cassandra's RackAwareStrategy can be used to have replication take
|
||||
data-center and/or rack location into account when placing replicas. The
|
||||
ProperyFileEndpointSnitch allows you to make use of RackAwareStrategy by
|
||||
specifying node locations in a standard key/value properties file.
|
||||
|
||||
|
||||
Properties File
|
||||
---------------
|
||||
The EndpointSnitch expects to find a file on the classapth named
|
||||
cassandra-rack.properties in the following format:
|
||||
|
||||
<node IP>\:<port>=<data center name>:<rack name>
|
||||
|
||||
There is also a special directive used to define which information to
|
||||
return for unconfigured nodes:
|
||||
|
||||
default=<data center name>:<rack name>
|
||||
|
||||
See conf/cassandra-rack.properties for an annotated example config.
|
||||
|
||||
|
||||
Installing
|
||||
----------
|
||||
* Run the ant jar target
|
||||
* Copy build/cassandra-propsnitch.jar to your Cassandra lib/
|
||||
directory, or otherwise add it to the CLASSPATH
|
||||
(see http://wiki.apache.org/cassandra/RunningCassandra)
|
||||
* Edit the EndpointSnitch element of storage-conf.xml to use
|
||||
org.apache.cassandra.locator.PropertyFileEndpointSnitch
|
||||
* Create the cassandra-rack.properties in your classpath
|
||||
(e.g. in your Cassandra conf/ directory)
|
||||
* Optionally set ReplicaPlacementStrategy in cassandra.xml to
|
||||
org.apache.cassandra.locator.RackAwareStrategy
|
||||
|
||||
|
||||
Running/Managing
|
||||
----------------
|
||||
This endpointsnitch also registers itself as an MBean which can be
|
||||
used to reload the configuration file in the case the properties file
|
||||
has changed. Additionally, the current rack information can be
|
||||
retrieved.
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<project basedir="." default="build" name="property-snitch">
|
||||
<property environment="env"/>
|
||||
<property name="debuglevel" value="source,lines,vars"/>
|
||||
|
||||
<property name="cassandra.dir" value="../.."/>
|
||||
<property name="cassandra.lib" value="${cassandra.dir}/lib"/>
|
||||
<property name="cassandra.classes" value="${cassandra.dir}/build/classes"/>
|
||||
<property name="build.src" value="${basedir}/src/java"/>
|
||||
<property name="build.dir" value="${basedir}/build"/>
|
||||
<property name="build.classes" value="${build.dir}/classes"/>
|
||||
<property name="javadoc.dir" value="${build.dir}/javadoc"/>
|
||||
<property name="final.name" value="cassandra-propsnitch"/>
|
||||
|
||||
<!--
|
||||
Add all the dependencies.
|
||||
-->
|
||||
<path id="cassandra.classpath">
|
||||
<pathelement location="${build.classes}"/>
|
||||
<pathelement location="${cassandra.classes}"/>
|
||||
<fileset dir="${cassandra.lib}">
|
||||
<include name="**/*.jar" />
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<!--
|
||||
Setup the output directories.
|
||||
-->
|
||||
<target name="init">
|
||||
<mkdir dir="${build.classes}"/>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${build.dir}" />
|
||||
<delete dir="${build.classes}" />
|
||||
</target>
|
||||
|
||||
<!--
|
||||
The build target builds all the .class files
|
||||
-->
|
||||
<target depends="init" name="build">
|
||||
<echo message="${ant.project.name}: ${ant.file}"/>
|
||||
<javac debug="true" debuglevel="${debuglevel}" destdir="${build.classes}">
|
||||
<src path="${build.src}"/>
|
||||
<classpath refid="cassandra.classpath"/>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
The jar target makes cassandra.jar output.
|
||||
-->
|
||||
<target name="jar" depends="build">
|
||||
<mkdir dir="${build.classes}/META-INF"/>
|
||||
<jar jarfile="${build.dir}/${final.name}.jar"
|
||||
basedir="${build.classes}">
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
</project>
|
||||
|
|
@ -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
|
||||
|
|
@ -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.
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
@ -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 <syu@sammyyu.net>
|
||||
*
|
||||
*
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
|
@ -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<InetAddress> 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)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
<DiskAccessMode>mmap</DiskAccessMode>
|
||||
<MemtableThroughputInMB>1</MemtableThroughputInMB>
|
||||
<MemtableOperationsInMillions>0.00002</MemtableOperationsInMillions> <!-- 20 -->
|
||||
<EndpointSnitch>org.apache.cassandra.locator.EndpointSnitch</EndpointSnitch>
|
||||
<EndpointSnitch>org.apache.cassandra.locator.RackInferringSnitch</EndpointSnitch>
|
||||
<Keyspaces>
|
||||
<Keyspace Name = "Keyspace1">
|
||||
<ColumnFamily Name="Standard1" RowsCached="10%" KeysCached="0"/>
|
||||
|
|
@ -58,13 +58,11 @@
|
|||
<ColumnFamily ColumnType="Super" CompareSubcolumnsWith="TimeUUIDType" Name="Super4"/>
|
||||
<ReplicaPlacementStrategy>org.apache.cassandra.locator.RackUnawareStrategy</ReplicaPlacementStrategy>
|
||||
<ReplicationFactor>1</ReplicationFactor>
|
||||
<EndpointSnitch>org.apache.cassandra.locator.EndpointSnitch</EndpointSnitch>
|
||||
</Keyspace>
|
||||
<Keyspace Name = "Keyspace3">
|
||||
<ColumnFamily Name="Standard1"/>
|
||||
<ReplicaPlacementStrategy>org.apache.cassandra.locator.RackUnawareStrategy</ReplicaPlacementStrategy>
|
||||
<ReplicationFactor>5</ReplicationFactor>
|
||||
<EndpointSnitch>org.apache.cassandra.locator.EndpointSnitch</EndpointSnitch>
|
||||
</Keyspace>
|
||||
<Keyspace Name = "Keyspace4">
|
||||
<ColumnFamily Name="Standard1"/>
|
||||
|
|
@ -73,7 +71,6 @@
|
|||
<ColumnFamily ColumnType="Super" CompareSubcolumnsWith="TimeUUIDType" Name="Super4"/>
|
||||
<ReplicaPlacementStrategy>org.apache.cassandra.locator.RackUnawareStrategy</ReplicaPlacementStrategy>
|
||||
<ReplicationFactor>3</ReplicationFactor>
|
||||
<EndpointSnitch>org.apache.cassandra.locator.EndpointSnitch</EndpointSnitch>
|
||||
</Keyspace>
|
||||
</Keyspaces>
|
||||
<Seeds>
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Reference in New Issue