Author: jbellis
Date: Tue Apr 21 21:34:46 2009
New Revision: 767307
URL: http://svn.apache.org/viewvc?rev=767307&view=rev
Log:
configurable ListenAddress setting. allows running multiple instances of
Cassandra
on a single machine or VM. patch and review by Per Mellqvist, Eric Evans, and
jbellis for #43
Modified:
incubator/cassandra/trunk/conf/storage-conf.xml
incubator/cassandra/trunk/src/org/apache/cassandra/config/DatabaseDescriptor.java
incubator/cassandra/trunk/src/org/apache/cassandra/net/EndPoint.java
incubator/cassandra/trunk/src/org/apache/cassandra/service/CassandraDaemon.java
incubator/cassandra/trunk/src/org/apache/cassandra/utils/FBUtilities.java
incubator/cassandra/trunk/test/conf/storage-conf.xml
Modified: incubator/cassandra/trunk/conf/storage-conf.xml
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/conf/storage-conf.xml?rev=767307&r1=767306&r2=767307&view=diff
==============================================================================
--- incubator/cassandra/trunk/conf/storage-conf.xml (original)
+++ incubator/cassandra/trunk/conf/storage-conf.xml Tue Apr 21 21:34:46 2009
@@ -14,6 +14,7 @@
<RpcTimeoutInMillis>5000</RpcTimeoutInMillis>
<JobTrackerHost>tdsearch001.sf2p.facebook.com</JobTrackerHost>
<JobJarFileLocation>C:\Engagements\Cassandra-Nexus</JobJarFileLocation>
+ <ListenAddress>localhost</ListenAddress>
<StoragePort>7000</StoragePort>
<ControlPort>7001</ControlPort>
<ThriftPort>9160</ThriftPort>
Modified:
incubator/cassandra/trunk/src/org/apache/cassandra/config/DatabaseDescriptor.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/config/DatabaseDescriptor.java?rev=767307&r1=767306&r2=767307&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/org/apache/cassandra/config/DatabaseDescriptor.java
(original)
+++
incubator/cassandra/trunk/src/org/apache/cassandra/config/DatabaseDescriptor.java
Tue Apr 21 21:34:46 2009
@@ -48,6 +48,7 @@
private static int controlPort_ = 7001;
private static int httpPort_ = 7002;
private static int thriftPort_ = 9160;
+ private static String listenAddress_; // leave null so we can fall through
to getLocalHost
private static String clusterName_ = "Test";
private static int replicationFactor_ = 3;
private static long rpcTimeoutInMillis_ = 2000;
@@ -176,6 +177,11 @@
if ( port != null )
storagePort_ = Integer.parseInt(port);
+ /* Local IP or hostname to bind services to */
+ String listenAddress =
xmlUtils.getNodeValue("/Storage/ListenAddress");
+ if ( listenAddress != null)
+ listenAddress_ = listenAddress;
+
/* UDP port for control messages */
port = xmlUtils.getNodeValue("/Storage/ControlPort");
if ( port != null )
@@ -800,4 +806,9 @@
super(message);
}
}
+
+ public static String getListenAddress()
+ {
+ return listenAddress_;
+ }
}
Modified: incubator/cassandra/trunk/src/org/apache/cassandra/net/EndPoint.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/net/EndPoint.java?rev=767307&r1=767306&r2=767307&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/org/apache/cassandra/net/EndPoint.java
(original)
+++ incubator/cassandra/trunk/src/org/apache/cassandra/net/EndPoint.java Tue
Apr 21 21:34:46 2009
@@ -30,6 +30,7 @@
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.LogUtil;
import org.apache.log4j.Logger;
+import org.apache.cassandra.config.DatabaseDescriptor;
/**
* Author : Avinash Lakshman ( [email protected]) & Prashant Malik (
[email protected] )
@@ -81,12 +82,12 @@
try
{
host_ = FBUtilities.getHostName();
- port_ = port;
}
catch (UnknownHostException e)
{
- logger_.warn(LogUtil.throwableToString(e));
+ throw new RuntimeException(e);
}
+ port_ = port;
}
public String getHost()
Modified:
incubator/cassandra/trunk/src/org/apache/cassandra/service/CassandraDaemon.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/service/CassandraDaemon.java?rev=767307&r1=767306&r2=767307&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/org/apache/cassandra/service/CassandraDaemon.java
(original)
+++
incubator/cassandra/trunk/src/org/apache/cassandra/service/CassandraDaemon.java
Tue Apr 21 21:34:46 2009
@@ -20,6 +20,9 @@
import java.io.File;
import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.InetSocketAddress;
+import java.net.InetAddress;
import org.apache.log4j.Logger;
import org.apache.thrift.protocol.TBinaryProtocol;
@@ -30,6 +33,7 @@
import org.apache.thrift.transport.TTransportFactory;
import org.apache.thrift.TProcessorFactory;
import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.utils.FBUtilities;
/**
* This class supports two methods for creating a Cassandra node daemon,
@@ -65,7 +69,7 @@
Cassandra.Processor processor = new
Cassandra.Processor(peerStorageServer);
// Transport
- TServerSocket tServerSocket = new TServerSocket(listenPort);
+ TServerSocket tServerSocket = new TServerSocket(new
InetSocketAddress(FBUtilities.getHostName(), listenPort));
// Protocol factory
TProtocolFactory tProtocolFactory = new TBinaryProtocol.Factory();
Modified:
incubator/cassandra/trunk/src/org/apache/cassandra/utils/FBUtilities.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/utils/FBUtilities.java?rev=767307&r1=767306&r2=767307&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/org/apache/cassandra/utils/FBUtilities.java
(original)
+++ incubator/cassandra/trunk/src/org/apache/cassandra/utils/FBUtilities.java
Tue Apr 21 21:34:46 2009
@@ -40,6 +40,8 @@
import java.util.zip.Deflater;
import java.util.zip.Inflater;
+import org.apache.cassandra.config.DatabaseDescriptor;
+
/**
* Author : Avinash Lakshman ( [email protected]) & Prashant Malik (
[email protected] )
*/
@@ -148,6 +150,10 @@
public static String getHostName() throws UnknownHostException
{
+ if (DatabaseDescriptor.getListenAddress() != null)
+ {
+ return DatabaseDescriptor.getListenAddress();
+ }
return getLocalAddress().getCanonicalHostName();
}
Modified: incubator/cassandra/trunk/test/conf/storage-conf.xml
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/conf/storage-conf.xml?rev=767307&r1=767306&r2=767307&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/conf/storage-conf.xml (original)
+++ incubator/cassandra/trunk/test/conf/storage-conf.xml Tue Apr 21 21:34:46
2009
@@ -14,6 +14,7 @@
<RpcTimeoutInMillis>5000</RpcTimeoutInMillis>
<JobTrackerHost>tdsearch001.sf2p.facebook.com</JobTrackerHost>
<JobJarFileLocation>C:\Engagements\Cassandra-Nexus</JobJarFileLocation>
+ <ListenAddress>127.0.0.1</ListenAddress>
<StoragePort>7000</StoragePort>
<ControlPort>7001</ControlPort>
<ThriftPort>7001</ThriftPort>