cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r795205 - in /incubator/cassandra/trunk: conf/storage-conf.xml src/java/org/apache/cassandra/config/DatabaseDescriptor.java src/java/org/apache/cassandra/service/CassandraDaemon.java
Date Fri, 17 Jul 2009 19:45:23 GMT
Author: eevans
Date: Fri Jul 17 19:45:22 2009
New Revision: 795205

URL: http://svn.apache.org/viewvc?rev=795205&view=rev
Log:
allow separate config of thrift bind address

This patch adds a new configuration directive 'ThriftAddress', an
analogue to ListenAddress for the thrift service.

If left unconfigured, the thrift service will fall back to the same
default as ListenAddress (i.e., InetAddress.getLocalHost). Unlike
ListenAddress, it is OK to set ThriftAddress to 0.0.0.0 which
will result in the service listening on all interfaces.

Patch by eevans; reviewed by Michael Greene for CASSANDRA-288

Modified:
    incubator/cassandra/trunk/conf/storage-conf.xml
    incubator/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java

Modified: incubator/cassandra/trunk/conf/storage-conf.xml
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/conf/storage-conf.xml?rev=795205&r1=795204&r2=795205&view=diff
==============================================================================
--- incubator/cassandra/trunk/conf/storage-conf.xml (original)
+++ incubator/cassandra/trunk/conf/storage-conf.xml Fri Jul 17 19:45:22 2009
@@ -139,7 +139,16 @@
     <StoragePort>7000</StoragePort>
     <!-- UDP port, for membership communications (gossip) -->
     <ControlPort>7001</ControlPort>
-    <!-- port clients connect to -->
+
+    <!-- The address to bind the Thrift RPC service to. Unlike 
+         ListenAddress above, you *can* specify 0.0.0.0 here if you want
+         Thrift to listen on all interfaces.
+         
+         Leaving this blank has the same effect it does for ListenAddress,
+         (i.e. it will be based on the configured hostname of the node).
+    -->
+    <ThriftAddress>localhost</ThriftAddress>
+    <!-- Thrift RPC port (the port clients connect to). -->
     <ThriftPort>9160</ThriftPort>
 
 

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java?rev=795205&r1=795204&r2=795205&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
Fri Jul 17 19:45:22 2009
@@ -44,6 +44,7 @@
     private static int controlPort_ = 7001;
     private static int thriftPort_ = 9160;
     private static String listenAddress_; // leave null so we can fall through to getLocalHost
+    private static String thriftAddress_;
     private static String clusterName_ = "Test";
     private static int replicationFactor_ = 3;
     private static long rpcTimeoutInMillis_ = 2000;
@@ -174,6 +175,11 @@
             if ( listenAddress != null)
                 listenAddress_ = listenAddress;
             
+            /* Local IP or hostname to bind thrift server to */
+            String thriftAddress = xmlUtils.getNodeValue("/Storage/ThriftAddress");
+            if ( thriftAddress != null )
+                thriftAddress_ = thriftAddress;
+            
             /* UDP port for control messages */
             port = xmlUtils.getNodeValue("/Storage/ControlPort");
             if ( port != null )
@@ -800,4 +806,9 @@
     {
         return listenAddress_;
     }
+    
+    public static String getThriftAddress()
+    {
+        return thriftAddress_;
+    }
 }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java?rev=795205&r1=795204&r2=795205&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraDaemon.java Fri
Jul 17 19:45:22 2009
@@ -57,6 +57,14 @@
     private void setup() throws IOException, TTransportException
     {
         int listenPort = DatabaseDescriptor.getThriftPort();
+        String listenAddr = DatabaseDescriptor.getThriftAddress();
+        
+        /* 
+         * If ThriftAddress was left completely unconfigured, then assume
+         * the same default as ListenAddress, (InetAddress.getLocalHost).
+         */
+        if (listenAddr == null)
+            listenAddr = FBUtilities.getHostAddress();
         
         Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
         {
@@ -90,7 +98,10 @@
         Cassandra.Processor processor = new Cassandra.Processor(peerStorageServer);
 
         // Transport
-        TServerSocket tServerSocket = new TServerSocket(new InetSocketAddress(FBUtilities.getHostAddress(),
listenPort));
+        TServerSocket tServerSocket = new TServerSocket(new InetSocketAddress(listenAddr,
listenPort));
+        
+        if (logger.isDebugEnabled())
+            logger.debug(String.format("Binding thrift service to %s:%s", listenAddr, listenPort));
 
         // Protocol factory
         TProtocolFactory tProtocolFactory = new TBinaryProtocol.Factory();



Mime
View raw message