Author: jbellis
Date: Wed Jan 19 22:51:16 2011
New Revision: 1061046
URL: http://svn.apache.org/viewvc?rev=1061046&view=rev
Log:
wrap some listen_address BindExceptions with more user-friendly error messages
patch by jbellis
Modified:
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/net/MessagingService.java
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/StorageService.java
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/InitClientTest.java
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/RemoveTest.java
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/StorageServiceClientTest.java
Modified:
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/net/MessagingService.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/net/MessagingService.java?rev=1061046&r1=1061045&r2=1061046&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/net/MessagingService.java
(original)
+++
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/net/MessagingService.java
Wed Jan 19 22:51:16 2011
@@ -21,10 +21,7 @@ package org.apache.cassandra.net;
import java.io.IOError;
import java.io.IOException;
import java.lang.management.ManagementFactory;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
+import java.net.*;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.ServerSocketChannel;
@@ -45,6 +42,7 @@ import org.slf4j.LoggerFactory;
import org.apache.cassandra.concurrent.DebuggableThreadPoolExecutor;
import org.apache.cassandra.concurrent.StageManager;
+import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.io.util.DataOutputBuffer;
import org.apache.cassandra.locator.ILatencyPublisher;
@@ -174,12 +172,25 @@ public final class MessagingService impl
* Listen on the specified port.
* @param localEp InetAddress whose port to listen on.
*/
- public void listen(InetAddress localEp) throws IOException
+ public void listen(InetAddress localEp) throws IOException,
ConfigurationException
{
ServerSocketChannel serverChannel = ServerSocketChannel.open();
final ServerSocket ss = serverChannel.socket();
ss.setReuseAddress(true);
- ss.bind(new InetSocketAddress(localEp,
DatabaseDescriptor.getStoragePort()));
+ InetSocketAddress address = new InetSocketAddress(localEp,
DatabaseDescriptor.getStoragePort());
+ try
+ {
+ ss.bind(address);
+ }
+ catch (BindException e)
+ {
+ if (e.getMessage().contains("in use"))
+ throw new ConfigurationException(address + " is in use by
another process. Change listen_address:storage_port in cassandra.yaml to
values that do not conflict with other services");
+ else if (e.getMessage().contains("Cannot assign requested
address"))
+ throw new ConfigurationException("Unable to bind to address "
+ address + ". Set listen_address in cassandra.yaml to an interface you can
bind to, e.g., your private IP address on EC2");
+ else
+ throw e;
+ }
socketThread = new SocketThread(ss, "ACCEPT-" + localEp);
socketThread.start();
listenGate.signalAll();
Modified:
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/StorageService.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/StorageService.java?rev=1061046&r1=1061045&r2=1061046&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/StorageService.java
(original)
+++
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/StorageService.java
Wed Jan 19 22:51:16 2011
@@ -282,7 +282,7 @@ public class StorageService implements I
return initialized;
}
- public synchronized void initClient() throws IOException
+ public synchronized void initClient() throws IOException,
ConfigurationException
{
if (initialized)
{
Modified:
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java?rev=1061046&r1=1061045&r2=1061046&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java
(original)
+++
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java
Wed Jan 19 22:51:16 2011
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
+import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.service.StorageService;
import org.junit.Test;
@@ -31,7 +32,7 @@ import org.apache.cassandra.utils.FBUtil
public class DynamicEndpointSnitchTest
{
@Test
- public void testSnitch() throws InterruptedException, IOException
+ public void testSnitch() throws InterruptedException, IOException,
ConfigurationException
{
// do this because SS needs to be initialized before DES can work
properly.
StorageService.instance.initClient();
Modified:
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/InitClientTest.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/InitClientTest.java?rev=1061046&r1=1061045&r2=1061046&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/InitClientTest.java
(original)
+++
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/InitClientTest.java
Wed Jan 19 22:51:16 2011
@@ -4,6 +4,8 @@ import org.junit.Test;
import java.io.IOException;
+import org.apache.cassandra.config.ConfigurationException;
+
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -26,12 +28,8 @@ import java.io.IOException;
public class InitClientTest // extends CleanupHelper
{
@Test
- public void testInitClientStartup()
+ public void testInitClientStartup() throws IOException,
ConfigurationException
{
- try {
- StorageService.instance.initClient();
- } catch (IOException ex) {
- throw new AssertionError(ex.getMessage());
- }
+ StorageService.instance.initClient();
}
}
Modified:
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/RemoveTest.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/RemoveTest.java?rev=1061046&r1=1061045&r2=1061046&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/RemoveTest.java
(original)
+++
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/RemoveTest.java
Wed Jan 19 22:51:16 2011
@@ -32,6 +32,7 @@ import org.junit.Test;
import org.apache.cassandra.CleanupHelper;
import org.apache.cassandra.Util;
import org.apache.cassandra.concurrent.Stage;
+import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.dht.IPartitioner;
import org.apache.cassandra.dht.RandomPartitioner;
import org.apache.cassandra.dht.Token;
@@ -58,7 +59,7 @@ public class RemoveTest extends CleanupH
List<InetAddress> hosts;
@Before
- public void setup() throws IOException
+ public void setup() throws IOException, ConfigurationException
{
tmd.clearUnsafe();
IPartitioner partitioner = new RandomPartitioner();
Modified:
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/StorageServiceClientTest.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/StorageServiceClientTest.java?rev=1061046&r1=1061045&r2=1061046&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/StorageServiceClientTest.java
(original)
+++
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/StorageServiceClientTest.java
Wed Jan 19 22:51:16 2011
@@ -20,6 +20,7 @@
package org.apache.cassandra.service;
import org.apache.cassandra.CleanupHelper;
+import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
@@ -31,7 +32,7 @@ import java.io.IOException;
public class StorageServiceClientTest
{
@Test
- public void testClientOnlyMode() throws IOException
+ public void testClientOnlyMode() throws IOException, ConfigurationException
{
CleanupHelper.mkdirs();
CleanupHelper.cleanup();