diff --git a/CHANGES.txt b/CHANGES.txt
index 187d8a0adac0..44e19224676f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -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
diff --git a/NEWS.txt b/NEWS.txt
index 91c3286a0a52..3ffca3a6ff59 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -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
diff --git a/conf/cassandra-rack.properties b/conf/cassandra-topology.properties
similarity index 95%
rename from conf/cassandra-rack.properties
rename to conf/cassandra-topology.properties
index 718eb5d4db74..28c42f1f15d3 100644
--- a/conf/cassandra-rack.properties
+++ b/conf/cassandra-topology.properties
@@ -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
diff --git a/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java b/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java
index 203bb905fbb5..38c12ba7c645 100644
--- a/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java
+++ b/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java
@@ -21,8 +21,10 @@
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 @@
/**
* Used to determine if two IP's are in the same datacenter or on the same rack.
*
- * 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 endpointMap;
+ private static volatile String[] defaultDCRack;
public PropertyFileSnitch() throws ConfigurationException
{
@@ -75,20 +74,13 @@ protected void runMayThrow() throws ConfigurationException
*/
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");
- }
- StringTokenizer st = new StringTokenizer(value, ":");
- if (st.countTokens() < 2)
- {
- logger_.error("Value for " + key + " is invalid: " + value);
- return new String[] { "default", "default" };
+ logger.debug("Could not find end point information for {}, will use default", endpoint);
+ return defaultDCRack;
}
- return new String[] { st.nextToken(), st.nextToken() };
+ return value;
}
/**
@@ -115,24 +107,51 @@ public String getRack(InetAddress endpoint)
public void reloadConfiguration() throws ConfigurationException
{
- hostProperties = resourceToProperties(RACK_PROPERTY_FILENAME);
- clearEndpointCache();
- }
+ HashMap reloadedMap = new HashMap();
- public static Properties resourceToProperties(String filename) throws ConfigurationException
- {
- String rackPropertyFilename = FBUtilities.resourceToFile(filename);
-
- 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