You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ee...@apache.org on 2009/09/15 20:21:43 UTC
svn commit: r815436 - in /incubator/cassandra/branches/cassandra-0.4/contrib:
endpointsnitch_example/ property_snitch/ property_snitch/conf/
property_snitch/src/ property_snitch/src/java/
property_snitch/src/java/org/ property_snitch/src/java/org/apach...
Author: eevans
Date: Tue Sep 15 18:21:42 2009
New Revision: 815436
URL: http://svn.apache.org/viewvc?rev=815436&view=rev
Log:
refactor sample code as contrib module
- renamed classes
- added licensing information
- reworked readme
Patch by Sammy Yu and eevans; reviewed by eevans for CASSANDRA-422
Added:
incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/
incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/README.txt (with props)
incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/build.xml (with props)
incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/conf/
incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/conf/rack.properties (with props)
incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/
incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/
incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/
incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/
incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/cassandra/
incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/cassandra/locator/
incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitch.java (with props)
incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitchMBean.java (with props)
Removed:
incubator/cassandra/branches/cassandra-0.4/contrib/endpointsnitch_example/CustomEndPointSnitch.java
incubator/cassandra/branches/cassandra-0.4/contrib/endpointsnitch_example/CustomEndPointSnitchMBean.java
Added: incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/README.txt
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/README.txt?rev=815436&view=auto
==============================================================================
--- incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/README.txt (added)
+++ incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/README.txt Tue Sep 15 18:21:42 2009
@@ -0,0 +1,41 @@
+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 standard properties file at
+/etc/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/rack.properties for an annotated example config.
+
+
+Installing
+----------
+ * Run the ant jar target
+ * Add build/cassandra-propsnitch.jar to the CLASSPATH
+ * Edit storage-conf.xml and set ReplicaPlacementStrategy to
+ org.apache.cassandra.locator.RackAwareStrategy
+ * Edit the EndPointSnitch element of storage-conf.xml to use
+ org.apache.cassandra.locator.PropertyFileEndPointSnitch
+ * Create the file /etc/cassandra/rack.properties
+
+
+Running/Managing
+----------------
+This endpointsnitch also registers itself as an MBean which can be used to
+reload the configuration file in the case the rack.properties file has
+changed. Additionally, the current rack information can be retrieved as
+well.
Propchange: incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/README.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/build.xml
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/build.xml?rev=815436&view=auto
==============================================================================
--- incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/build.xml (added)
+++ incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/build.xml Tue Sep 15 18:21:42 2009
@@ -0,0 +1,77 @@
+<?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>
Propchange: incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/build.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/conf/rack.properties
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/conf/rack.properties?rev=815436&view=auto
==============================================================================
--- incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/conf/rack.properties (added)
+++ incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/conf/rack.properties Tue Sep 15 18:21:42 2009
@@ -0,0 +1,23 @@
+
+# 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
Propchange: incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/conf/rack.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitch.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitch.java?rev=815436&view=auto
==============================================================================
--- incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitch.java (added)
+++ incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitch.java Tue Sep 15 18:21:42 2009
@@ -0,0 +1,180 @@
+/**
+ * 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.
+ */
+
+package src.java.org.apache.cassandra.locator;
+
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.net.UnknownHostException;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.cassandra.locator.EndPointSnitch;
+import org.apache.cassandra.net.EndPoint;
+import org.apache.cassandra.utils.LogUtil;
+import org.apache.log4j.Logger;
+
+/**
+ * PropertyFileEndPointSnitch
+ *
+ * PropertyFileEndPointSnitch is used by Digg to determine if two IP's are in the same
+ * datacenter or on the same rack.
+ *
+ * @author Sammy Yu <sy...@sammyyu.net>
+ *
+ */
+public class PropertyFileEndPointSnitch extends EndPointSnitch implements PropertyFileEndPointSnitchMBean {
+ /**
+ * A list of properties with keys being host:port and values being datacenter:rack
+ */
+ private Properties hostProperties = new Properties();
+
+ /**
+ * The default rack property file to be read.
+ */
+ private static String DEFAULT_RACK_PROPERTY_FILE = "/etc/cassandra/rack.properties";
+
+ /**
+ * Whether to use the parent for detection of same node
+ */
+ private boolean runInBaseMode = false;
+
+ /**
+ * Reference to the logger.
+ */
+ private static Logger logger_ = Logger.getLogger(PropertyFileEndPointSnitch.class);
+
+ public PropertyFileEndPointSnitch() throws IOException {
+ reloadConfiguration();
+ try
+ {
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ mbs.registerMBean(this, new ObjectName(MBEAN_OBJECT_NAME));
+ }
+ catch (Exception e)
+ {
+ logger_.error(LogUtil.throwableToString(e));
+ }
+ }
+
+ /**
+ * Get the raw information about an end point
+ *
+ * @param endPoint endPoint to process
+ *
+ * @return a array of string with the first index being the data center and the second being the rack
+ */
+ public String[] getEndPointInfo(EndPoint endPoint) {
+ String key = endPoint.toString();
+ String value = hostProperties.getProperty(key);
+ if (value == null)
+ {
+ logger_.error("Could not find end point information for " + key + ", will use default.");
+ value = hostProperties.getProperty("default");
+ }
+ StringTokenizer st = new StringTokenizer(value, ":");
+ if (st.countTokens() < 2)
+ {
+ logger_.error("Value for " + key + " is invalid: " + value);
+ return new String [] {"default", "default"};
+ }
+ return new String[] {st.nextToken(), st.nextToken()};
+ }
+
+ /**
+ * Return the data center for which an endpoint resides in
+ *
+ * @param endPoint the endPoint to process
+ * @return string of data center
+ */
+ public String getDataCenterForEndPoint(EndPoint endPoint) {
+ return getEndPointInfo(endPoint)[0];
+ }
+
+ /**
+ * Return the rack for which an endpoint resides in
+ *
+ * @param endPoint the endPoint to process
+ *
+ * @return string of rack
+ */
+ public String getRackForEndPoint(EndPoint endPoint) {
+ return getEndPointInfo(endPoint)[1];
+ }
+
+ @Override
+ public boolean isInSameDataCenter(EndPoint host, EndPoint host2)
+ throws UnknownHostException {
+ if (runInBaseMode)
+ {
+ return super.isInSameDataCenter(host, host2);
+ }
+ return getDataCenterForEndPoint(host).equals(getDataCenterForEndPoint(host2));
+ }
+
+ @Override
+ public boolean isOnSameRack(EndPoint host, EndPoint host2)
+ throws UnknownHostException {
+ if (runInBaseMode)
+ {
+ return super.isOnSameRack(host, host2);
+ }
+ if (!isInSameDataCenter(host, host2))
+ {
+ return false;
+ }
+ return getRackForEndPoint(host).equals(getRackForEndPoint(host2));
+ }
+
+ @Override
+ public String displayConfiguration() {
+ StringBuffer configurationString = new StringBuffer("Current rack configuration\n=================\n");
+ for (Object key: hostProperties.keySet()) {
+ String endpoint = (String) key;
+ String value = hostProperties.getProperty(endpoint);
+ configurationString.append(endpoint + "=" + value + "\n");
+ }
+ return configurationString.toString();
+ }
+
+ @Override
+ public void reloadConfiguration() throws IOException {
+ String rackPropertyFilename = System.getProperty("rackFile", DEFAULT_RACK_PROPERTY_FILE);
+ try
+ {
+ Properties localHostProperties = new Properties();
+ localHostProperties.load(new FileReader(rackPropertyFilename));
+ hostProperties = localHostProperties;
+ runInBaseMode = false;
+ }
+ catch (FileNotFoundException fnfe) {
+ logger_.error("Could not find " + rackPropertyFilename + ", using default EndPointSnitch", fnfe);
+ runInBaseMode = true;
+ }
+ catch (IOException ioe) {
+ logger_.error("Could not process " + rackPropertyFilename, ioe);
+ throw ioe;
+ }
+ }
+
+}
Propchange: incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitch.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitchMBean.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitchMBean.java?rev=815436&view=auto
==============================================================================
--- incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitchMBean.java (added)
+++ incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitchMBean.java Tue Sep 15 18:21:42 2009
@@ -0,0 +1,47 @@
+/**
+ * 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.
+ */
+
+package src.java.org.apache.cassandra.locator;
+
+import java.io.IOException;
+
+/**
+ * PropertyFileEndPointSnitchMBean
+ *
+ * PropertyFileEndPointSnitchMBean is the management interface for Digg's EndpointSnitch MBean
+ *
+ * @author Sammy Yu <sy...@sammyyu.net>
+ *
+ */
+public interface PropertyFileEndPointSnitchMBean {
+ /**
+ * 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 IOException;
+
+ /**
+ * Display the current configuration
+ */
+ public String displayConfiguration();
+
+}
Propchange: incubator/cassandra/branches/cassandra-0.4/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitchMBean.java
------------------------------------------------------------------------------
svn:eol-style = native