Permalink
Browse files

Add broadcast_rpc_address option to cassandra.yaml

Patch by Tyler Hobbs, reviewed by Jason Brown for CASSANDRA-5899
  • Loading branch information...
1 parent 7e0f7a0 commit 893c11f5451b199365f2edecc9914a20879ac552 @thobbs thobbs committed Mar 7, 2014
View
@@ -1,4 +1,5 @@
2.1.0-beta2
+ * Add broadcast_rpc_address option to cassandra.yaml (CASSANDRA-5899)
* Auto reload GossipingPropertyFileSnitch config (CASSANDRA-5897)
* Fix overflow of memtable_total_space_in_mb (CASSANDRA-6573)
* Fix ABTC NPE (CASSANDRA-6692)
View
@@ -373,18 +373,23 @@ native_transport_port: 9042
start_rpc: true
# The address to bind the Thrift RPC service and native transport
-# server -- clients connect here.
+# server to.
#
-# Leaving this blank has the same effect it does for ListenAddress,
+# Leaving this blank has the same effect as on listen_address
# (i.e. it will be based on the configured hostname of the node).
#
-# Note that unlike ListenAddress above, it is allowed to specify 0.0.0.0
-# here if you want to listen on all interfaces, but that will break clients
-# that rely on node auto-discovery.
+# Note that unlike listen_address, you can specify 0.0.0.0, but you must also
+# set broadcast_rpc_address to a value other than 0.0.0.0.
rpc_address: localhost
# port for Thrift to listen for clients on
rpc_port: 9160
+# RPC address to broadcast to drivers and other Cassandra nodes. This cannot
+# be set to 0.0.0.0. If left blank, this will be set to the value of
+# rpc_address. If rpc_address is set to 0.0.0.0, broadcast_rpc_address must
+# be set.
+# broadcast_rpc_address: 1.2.3.4
+
# enable or disable keepalive on rpc connections
rpc_keepalive: true
@@ -104,6 +104,7 @@
public Boolean start_rpc = true;
public String rpc_address;
+ public String broadcast_rpc_address;
public Integer rpc_port = 9160;
public Integer rpc_listen_backlog = 50;
public String rpc_server_type = "sync";
@@ -68,6 +68,7 @@
private static InetAddress listenAddress; // leave null so we can fall through to getLocalHost
private static InetAddress broadcastAddress;
private static InetAddress rpcAddress;
+ private static InetAddress broadcastRpcAddress;
private static SeedProvider seedProvider;
private static IInternodeAuthenticator internodeAuthenticator;
@@ -325,6 +326,39 @@ else if (conf.disk_access_mode == Config.DiskAccessMode.mmap_index_only)
rpcAddress = FBUtilities.getLocalAddress();
}
+ /* RPC address to broadcast */
+ if (conf.broadcast_rpc_address != null)
+ {
+ if (conf.broadcast_rpc_address.equals("0.0.0.0"))
+ throw new ConfigurationException("broadcast_rpc_address cannot be 0.0.0.0");
+
+ try
+ {
+ broadcastRpcAddress = InetAddress.getByName(conf.broadcast_rpc_address);
+ }
+ catch (UnknownHostException e)
+ {
+ throw new ConfigurationException("Unkown broadcast_rpc_address '" + conf.broadcast_rpc_address + "'");
+ }
+ }
+ else
+ {
+ InetAddress bindAll;
+ try
+ {
+ bindAll = InetAddress.getByAddress(new byte[4]);
+ }
+ catch (UnknownHostException e)
+ {
+ throw new RuntimeException("Host 0.0.0.0 is somehow unknown");
+ }
+
+ if (rpcAddress.equals(bindAll))
+ throw new ConfigurationException("If rpc_address is set to 0.0.0.0, you must set broadcast_rpc_address " +
+ "to a value other than 0.0.0.0");
+ broadcastRpcAddress = rpcAddress;
+ }
+
if (conf.thrift_framed_transport_size_in_mb <= 0)
throw new ConfigurationException("thrift_framed_transport_size_in_mb must be positive");
@@ -1026,6 +1060,16 @@ public static InetAddress getRpcAddress()
return rpcAddress;
}
+ public static void setBroadcastRpcAddress(InetAddress broadcastRPCAddr)
+ {
+ broadcastRpcAddress = broadcastRPCAddr;
+ }
+
+ public static InetAddress getBroadcastRpcAddress()
+ {
+ return broadcastRpcAddress;
+ }
+
public static String getRpcServerType()
{
return conf.rpc_server_type;
@@ -1071,11 +1115,6 @@ public static boolean startNativeTransport()
return conf.start_native_transport;
}
- public static InetAddress getNativeTransportAddress()
- {
- return getRpcAddress();
- }
-
public static int getNativeTransportPort()
{
return Integer.parseInt(System.getProperty("cassandra.native_transport_port", conf.native_transport_port.toString()));
@@ -52,6 +52,7 @@ public Ec2MultiRegionSnitch() throws IOException, ConfigurationException
localPrivateAddress = awsApiCall(PRIVATE_IP_QUERY_URL);
// use the Public IP to broadcast Address to other nodes.
DatabaseDescriptor.setBroadcastAddress(localPublicAddress);
+ DatabaseDescriptor.setBroadcastRpcAddress(localPublicAddress);
}
public void gossiperStarting()
@@ -360,7 +360,7 @@ public void run()
thriftServer = new ThriftServer(rpcAddr, rpcPort, listenBacklog);
// Native transport
- InetAddress nativeAddr = DatabaseDescriptor.getNativeTransportAddress();
+ InetAddress nativeAddr = DatabaseDescriptor.getRpcAddress();
int nativePort = DatabaseDescriptor.getNativeTransportPort();
nativeServer = new org.apache.cassandra.transport.Server(nativeAddr, nativePort);
}
@@ -637,7 +637,7 @@ else if (shouldBootstrap())
getTokenMetadata().updateHostId(SystemKeyspace.getLocalHostId(), FBUtilities.getBroadcastAddress());
appStates.put(ApplicationState.NET_VERSION, valueFactory.networkVersion());
appStates.put(ApplicationState.HOST_ID, valueFactory.hostId(SystemKeyspace.getLocalHostId()));
- appStates.put(ApplicationState.RPC_ADDRESS, valueFactory.rpcaddress(DatabaseDescriptor.getRpcAddress()));
+ appStates.put(ApplicationState.RPC_ADDRESS, valueFactory.rpcaddress(DatabaseDescriptor.getBroadcastRpcAddress()));
appStates.put(ApplicationState.RELEASE_VERSION, valueFactory.releaseVersion());
logger.info("Starting up server gossip");
Gossiper.instance.register(this);
@@ -1049,7 +1049,7 @@ public double getSeverity(InetAddress endpoint)
public String getRpcaddress(InetAddress endpoint)
{
if (endpoint.equals(FBUtilities.getBroadcastAddress()))
- return DatabaseDescriptor.getRpcAddress().getHostAddress();
+ return DatabaseDescriptor.getBroadcastRpcAddress().getHostAddress();
else if (Gossiper.instance.getEndpointStateForEndpoint(endpoint).getApplicationState(ApplicationState.RPC_ADDRESS) == null)
return endpoint.getHostAddress();
else
@@ -331,6 +331,8 @@ private InetAddress getRpcAddress(InetAddress endpoint)
InetAddress rpcAddress = InetAddress.getByName(StorageService.instance.getRpcaddress(endpoint));
// If rpcAddress == 0.0.0.0 (i.e. bound on all addresses), returning that is not very helpful,
// so return the internal address (which is ok since "we're bound on all addresses").
+ // Note that after all nodes are running a version that includes CASSANDRA-5899, rpcAddress should
+ // never be 0.0.0.0, so this can eventually be removed.
return rpcAddress.equals(bindAll) ? endpoint : rpcAddress;
}
catch (UnknownHostException e)

0 comments on commit 893c11f

Please sign in to comment.