cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1022690 - in /cassandra/trunk: CHANGES.txt NEWS.txt conf/cassandra-rack.properties conf/cassandra-topology.properties src/java/org/apache/cassandra/locator/PropertyFileSnitch.java src/java/org/apache/cassandra/utils/FBUtilities.java
Date Thu, 14 Oct 2010 20:17:47 GMT
Author: jbellis
Date: Thu Oct 14 20:17:47 2010
New Revision: 1022690

URL: http://svn.apache.org/viewvc?rev=1022690&view=rev
Log:
forward-port CASSANDRA-1481.  originally thought it was a non-issue in 0.7 because of endpoint
caching in Strategy, but getRack/getDatacenter are still called by sortByProximity in StorageProxy.
 patch by jbellis

Added:
    cassandra/trunk/conf/cassandra-topology.properties
      - copied, changed from r1022666, cassandra/trunk/conf/cassandra-rack.properties
Removed:
    cassandra/trunk/conf/cassandra-rack.properties
Modified:
    cassandra/trunk/CHANGES.txt
    cassandra/trunk/NEWS.txt
    cassandra/trunk/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java
    cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java

Modified: cassandra/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=1022690&r1=1022689&r2=1022690&view=diff
==============================================================================
--- cassandra/trunk/CHANGES.txt (original)
+++ cassandra/trunk/CHANGES.txt Thu Oct 14 20:17:47 2010
@@ -34,6 +34,10 @@ dev
  * fix removing tokens from SystemTable on decommission and removetoken
    (CASSANDRA-1609)
  * include CF metadata in cli 'show keyspaces' (CASSANDRA-1613)
+ * switch from Properties to HashMap in PropertyFileSnitch to
+   avoid synchronization bottleneck (CASSANDRA-1481)
+ * PropertyFileSnitch configuration file renamed to 
+   cassandra-topology.properties
 
 
 0.7-beta2

Modified: cassandra/trunk/NEWS.txt
URL: http://svn.apache.org/viewvc/cassandra/trunk/NEWS.txt?rev=1022690&r1=1022689&r2=1022690&view=diff
==============================================================================
--- cassandra/trunk/NEWS.txt (original)
+++ cassandra/trunk/NEWS.txt Thu Oct 14 20:17:47 2010
@@ -76,6 +76,8 @@ Configuraton
 ------------
     - Configuration file renamed to cassandra.yaml and log4j.properties to
       log4j-server.properties
+    - PropertyFileSnitch configuration file renamed to 
+      cassandra-topology.properties
     - The ThriftAddress and ThriftPort directives have been renamed to
       RPCAddress and RPCPort respectively.
     - EndPointSnitch was renamed to RackInferringSnitch.  A new SimpleSnitch

Copied: cassandra/trunk/conf/cassandra-topology.properties (from r1022666, cassandra/trunk/conf/cassandra-rack.properties)
URL: http://svn.apache.org/viewvc/cassandra/trunk/conf/cassandra-topology.properties?p2=cassandra/trunk/conf/cassandra-topology.properties&p1=cassandra/trunk/conf/cassandra-rack.properties&r1=1022666&r2=1022690&rev=1022690&view=diff
==============================================================================
--- cassandra/trunk/conf/cassandra-rack.properties (original)
+++ cassandra/trunk/conf/cassandra-topology.properties Thu Oct 14 20:17:47 2010
@@ -15,8 +15,8 @@
 # limitations under the License.
 
 # Cassandra Node IP=Data Center:Rack
-192.168.1.200=DC1:RAC1
-192.168.2.300=DC2:RAC2
+192.168.1.100=DC1:RAC1
+192.168.2.200=DC2:RAC2
 
 10.0.0.10=DC1:RAC1
 10.0.0.11=DC1:RAC1

Modified: cassandra/trunk/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java?rev=1022690&r1=1022689&r2=1022690&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java Thu Oct
14 20:17:47 2010
@@ -21,8 +21,10 @@ package org.apache.cassandra.locator;
 import java.io.FileReader;
 import java.io.IOException;
 import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Properties;
-import java.util.StringTokenizer;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -35,24 +37,21 @@ import org.apache.cassandra.utils.Wrappe
 /**
  * Used to determine if two IP's are in the same datacenter or on the same rack.
  * <p/>
- * Based on a properties file configuration.
+ * Based on a properties file in the following format:
+ *
+ * 10.0.0.13=DC1:RAC2
+ * 10.21.119.14=DC3:RAC2
+ * 10.20.114.15=DC2:RAC2
+ * default=DC1:r1
  */
 public class PropertyFileSnitch extends AbstractNetworkTopologySnitch
 {
-    /**
-     * A list of properties with keys being host:port and values being datacenter:rack
-     */
-    private volatile Properties hostProperties;
+    private static final Logger logger = LoggerFactory.getLogger(PropertyFileSnitch.class);
 
-    /**
-     * The default rack property file to be read.
-     */
-    private static String RACK_PROPERTY_FILENAME = "cassandra-rack.properties";
+    private static final String RACK_PROPERTY_FILENAME = "cassandra-topology.properties";
 
-    /**
-     * Reference to the logger.
-     */
-    private static Logger logger_ = LoggerFactory.getLogger(PropertyFileSnitch.class);
+    private static volatile Map<InetAddress, String[]> endpointMap;
+    private static volatile String[] defaultDCRack;
 
     public PropertyFileSnitch() throws ConfigurationException
     {
@@ -75,20 +74,13 @@ public class PropertyFileSnitch extends 
      */
     public String[] getEndpointInfo(InetAddress endpoint)
     {
-        String key = endpoint.getHostAddress();
-        String value = hostProperties.getProperty(key);
+        String[] value = endpointMap.get(endpoint);
         if (value == null)
         {
-            logger_.error("Could not find end point information for {}, will use default.",
key);
-            value = hostProperties.getProperty("default");
+            logger.debug("Could not find end point information for {}, will use default",
endpoint);
+            return defaultDCRack;
         }
-        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 value;
     }
 
     /**
@@ -115,24 +107,51 @@ public class PropertyFileSnitch extends 
 
     public void reloadConfiguration() throws ConfigurationException
     {
-        hostProperties = resourceToProperties(RACK_PROPERTY_FILENAME);
-        clearEndpointCache();
-    }
-
-    public static Properties resourceToProperties(String filename) throws ConfigurationException
-    {
-        String rackPropertyFilename = FBUtilities.resourceToFile(filename);
+        HashMap<InetAddress, String[]> reloadedMap = new HashMap<InetAddress, String[]>();
 
-        Properties localHostProperties;
+        String rackPropertyFilename = FBUtilities.resourceToFile(RACK_PROPERTY_FILENAME);
+        Properties properties = new Properties();
         try
         {
-            localHostProperties = new Properties();
-            localHostProperties.load(new FileReader(rackPropertyFilename));
+            properties.load(new FileReader(rackPropertyFilename));
         }
         catch (IOException e)
         {
-            throw new ConfigurationException("Unable to load " + rackPropertyFilename, e);
+            throw new ConfigurationException("Unable to read " + RACK_PROPERTY_FILENAME,
e);
         }
-        return localHostProperties;
+
+        for (Map.Entry<Object, Object> entry : properties.entrySet())
+        {
+            String key = (String) entry.getKey();
+            String value = (String) entry.getValue();
+
+            if (key.equals("default"))
+            {
+                defaultDCRack = value.split(":");
+                if (defaultDCRack.length < 2)
+                    defaultDCRack = new String[] { "default", "default" };
+            }
+            else
+            {
+                InetAddress host;
+                String hostString = key.replace("/", "");
+                try
+                {
+                    host = InetAddress.getByName(hostString);
+                }
+                catch (UnknownHostException e)
+                {
+                    throw new ConfigurationException("Unknown host " + hostString, e);
+                }
+                String[] token = value.split(":");
+                if (token.length < 2)
+                    token = new String[] { "default", "default" };
+                reloadedMap.put(host, token);
+            }
+        }
+
+        logger.debug("loaded network topology {}", FBUtilities.toString(reloadedMap));
+        endpointMap = reloadedMap;
+        clearEndpointCache();
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java?rev=1022690&r1=1022689&r2=1022690&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java Thu Oct 14 20:17:47
2010
@@ -676,9 +676,15 @@ public class FBUtilities
         StringBuilder sb = new StringBuilder("{");
         for (Map.Entry<?,?> entry : map.entrySet())
         {
-            sb.append(entry.getKey()).append(": ").append(entry.getValue()).append(", ");
+            sb.append(toString(entry.getKey())).append(": ").append(toString(entry.getValue())).append(",
");
         }
         sb.append("}");
         return sb.toString();
     }
+
+    /** slow! */
+    private static Object toString(Object o)
+    {
+        return o.getClass().isArray() ? Arrays.toString((Object[]) o) : o.toString();
+    }
 }



Mime
View raw message