cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject git commit: clean up IOException usage
Date Wed, 26 Sep 2012 18:23:52 GMT
Updated Branches:
  refs/heads/trunk b781ee7d5 -> cc68336ca


clean up IOException usage


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/cc68336c
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/cc68336c
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/cc68336c

Branch: refs/heads/trunk
Commit: cc68336cac161156abc0c37279cd8e91df226643
Parents: b781ee7
Author: Jonathan Ellis <jbellis@apache.org>
Authored: Wed Sep 26 13:22:35 2012 -0500
Committer: Jonathan Ellis <jbellis@apache.org>
Committed: Wed Sep 26 13:22:35 2012 -0500

----------------------------------------------------------------------
 src/java/org/apache/cassandra/db/DefsTable.java    |    7 +--
 src/java/org/apache/cassandra/db/SystemTable.java  |   15 +++++-
 .../cassandra/db/commitlog/CommitLogArchiver.java  |   17 +++++-
 .../org/apache/cassandra/dht/BootStrapper.java     |    4 +-
 .../org/apache/cassandra/net/MessagingService.java |   38 ++++++++++++--
 .../apache/cassandra/service/CassandraDaemon.java  |   11 ++++-
 .../apache/cassandra/service/StorageService.java   |    8 ++--
 7 files changed, 76 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc68336c/src/java/org/apache/cassandra/db/DefsTable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/DefsTable.java b/src/java/org/apache/cassandra/db/DefsTable.java
index 8abe76a..e43ce8a 100644
--- a/src/java/org/apache/cassandra/db/DefsTable.java
+++ b/src/java/org/apache/cassandra/db/DefsTable.java
@@ -158,14 +158,14 @@ public class DefsTable
         return keyspaces;
     }
 
-    public static void fixSchemaNanoTimestamps() throws IOException
+    public static void fixSchemaNanoTimestamps()
     {
         fixSchemaNanoTimestamp(SystemTable.SCHEMA_KEYSPACES_CF);
         fixSchemaNanoTimestamp(SystemTable.SCHEMA_COLUMNFAMILIES_CF);
         fixSchemaNanoTimestamp(SystemTable.SCHEMA_COLUMNS_CF);
     }
 
-    private static void fixSchemaNanoTimestamp(String columnFamily) throws IOException
+    private static void fixSchemaNanoTimestamp(String columnFamily)
     {
         ColumnFamilyStore cfs = Table.open(Table.SYSTEM_KS).getColumnFamilyStore(columnFamily);
 
@@ -303,8 +303,7 @@ public class DefsTable
      * Merge remote schema in form of row mutations with local and mutate ks/cf metadata
objects
      * (which also involves fs operations on add/drop ks/cf)
      *
-     * @param data The data of the message from remote node with schema information
-     * @param version The version of the message
+     * @param mutations the schema changes to apply
      *
      * @throws ConfigurationException If one of metadata attributes has invalid value
      * @throws IOException If data was corrupted during transportation or failed to apply
fs operations

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc68336c/src/java/org/apache/cassandra/db/SystemTable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/SystemTable.java b/src/java/org/apache/cassandra/db/SystemTable.java
index 7abccee..8c91e10 100644
--- a/src/java/org/apache/cassandra/db/SystemTable.java
+++ b/src/java/org/apache/cassandra/db/SystemTable.java
@@ -20,6 +20,7 @@ package org.apache.cassandra.db;
 import java.io.IOException;
 import java.net.InetAddress;
 import java.nio.ByteBuffer;
+import java.nio.charset.CharacterCodingException;
 import java.util.*;
 import java.util.concurrent.ExecutionException;
 
@@ -86,7 +87,7 @@ public class SystemTable
         return StorageService.getPartitioner().decorateKey(key);
     }
 
-    public static void finishStartup() throws IOException
+    public static void finishStartup()
     {
         DefsTable.fixSchemaNanoTimestamps();
         setupVersion();
@@ -115,7 +116,7 @@ public class SystemTable
     }
 
     /** if system data becomes incompatible across versions of cassandra, that logic (and
associated purging) is managed here */
-    private static void upgradeSystemData() throws IOException, ExecutionException, InterruptedException
+    private static void upgradeSystemData() throws ExecutionException, InterruptedException
     {
         Table table = Table.open(Table.SYSTEM_KS);
         ColumnFamilyStore oldStatusCfs = table.getColumnFamilyStore(OLD_STATUS_CF);
@@ -128,7 +129,15 @@ public class SystemTable
             ColumnFamily oldCf = oldStatusCfs.getColumnFamily(filter);
             Iterator<IColumn> oldColumns = oldCf.columns.iterator();
 
-            String clusterName = ByteBufferUtil.string(oldColumns.next().value());
+            String clusterName = null;
+            try
+            {
+                clusterName = ByteBufferUtil.string(oldColumns.next().value());
+            }
+            catch (CharacterCodingException e)
+            {
+                throw new RuntimeException(e);
+            }
             // serialize the old token as a collection of (one )tokens.
             Token token = StorageService.getPartitioner().getTokenFactory().fromByteArray(oldColumns.next().value());
             String tokenBytes = ByteBufferUtil.bytesToHex(serializeTokens(Collections.singleton(token)));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc68336c/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java b/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java
index c0732db..e9d850a 100644
--- a/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java
+++ b/src/java/org/apache/cassandra/db/commitlog/CommitLogArchiver.java
@@ -136,7 +136,7 @@ public class CommitLogArchiver
         return true;
     }
 
-    public void maybeRestoreArchive() throws IOException
+    public void maybeRestoreArchive()
     {
         if (Strings.isNullOrEmpty(restoreDirectories))
             return;
@@ -144,12 +144,23 @@ public class CommitLogArchiver
         for (String dir : restoreDirectories.split(","))
         {
             File[] files = new File(dir).listFiles();
+            if (files == null)
+            {
+                throw new RuntimeException("Unable to list director " + dir);
+            }
             for (File fromFile : files)
             {
                 File toFile = new File(DatabaseDescriptor.getCommitLogLocation(), new CommitLogDescriptor(CommitLogSegment.getNextId()).fileName());
                 String command = restoreCommand.replace("%from", fromFile.getPath());
-                command = command.replace("%to", toFile.getPath());       
-                exec(command);
+                command = command.replace("%to", toFile.getPath());
+                try
+                {
+                    exec(command);
+                }
+                catch (IOException e)
+                {
+                    throw new RuntimeException(e);
+                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc68336c/src/java/org/apache/cassandra/dht/BootStrapper.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/dht/BootStrapper.java b/src/java/org/apache/cassandra/dht/BootStrapper.java
index d6c0fc2..ff76534 100644
--- a/src/java/org/apache/cassandra/dht/BootStrapper.java
+++ b/src/java/org/apache/cassandra/dht/BootStrapper.java
@@ -67,7 +67,7 @@ public class BootStrapper
         tokenMetadata = tmd;
     }
 
-    public void bootstrap() throws IOException
+    public void bootstrap()
     {
         if (logger.isDebugEnabled())
             logger.debug("Beginning bootstrap process");
@@ -90,7 +90,7 @@ public class BootStrapper
      * otherwise, if num_tokens == 1, pick a token to assume half the load of the most-loaded
node.
      * else choose num_tokens tokens at random
      */
-    public static Collection<Token> getBootstrapTokens(final TokenMetadata metadata,
Map<InetAddress, Double> load) throws IOException, ConfigurationException
+    public static Collection<Token> getBootstrapTokens(final TokenMetadata metadata,
Map<InetAddress, Double> load) throws ConfigurationException
     {
         Collection<String> initialTokens = DatabaseDescriptor.getInitialTokens();
         // if user specified tokens, use those

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc68336c/src/java/org/apache/cassandra/net/MessagingService.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/net/MessagingService.java b/src/java/org/apache/cassandra/net/MessagingService.java
index 258e712..a2c5939 100644
--- a/src/java/org/apache/cassandra/net/MessagingService.java
+++ b/src/java/org/apache/cassandra/net/MessagingService.java
@@ -383,7 +383,7 @@ public final class MessagingService implements MessagingServiceMBean
      *
      * @param localEp InetAddress whose port to listen on.
      */
-    public void listen(InetAddress localEp) throws IOException, ConfigurationException
+    public void listen(InetAddress localEp) throws ConfigurationException
     {
         callbacks.reset(); // hack to allow tests to stop/restart MS
         for (ServerSocket ss : getServerSocket(localEp))
@@ -395,19 +395,41 @@ public final class MessagingService implements MessagingServiceMBean
         listenGate.signalAll();
     }
 
-    private List<ServerSocket> getServerSocket(InetAddress localEp) throws IOException,
ConfigurationException
+    private List<ServerSocket> getServerSocket(InetAddress localEp) throws ConfigurationException
     {
         final List<ServerSocket> ss = new ArrayList<ServerSocket>(2);
         if (DatabaseDescriptor.getEncryptionOptions().internode_encryption != EncryptionOptions.InternodeEncryption.none)
         {
-            ss.add(SSLFactory.getServerSocket(DatabaseDescriptor.getEncryptionOptions(),
localEp, DatabaseDescriptor.getSSLStoragePort()));
+            try
+            {
+                ss.add(SSLFactory.getServerSocket(DatabaseDescriptor.getEncryptionOptions(),
localEp, DatabaseDescriptor.getSSLStoragePort()));
+            }
+            catch (IOException e)
+            {
+                throw new ConfigurationException("Unable to create ssl socket");
+            }
             // setReuseAddress happens in the factory.
             logger.info("Starting Encrypted Messaging Service on SSL port {}", DatabaseDescriptor.getSSLStoragePort());
         }
 
-        ServerSocketChannel serverChannel = ServerSocketChannel.open();
+        ServerSocketChannel serverChannel = null;
+        try
+        {
+            serverChannel = ServerSocketChannel.open();
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException(e);
+        }
         ServerSocket socket = serverChannel.socket();
-        socket.setReuseAddress(true);
+        try
+        {
+            socket.setReuseAddress(true);
+        }
+        catch (SocketException e)
+        {
+            throw new ConfigurationException("Insufficient permissions to setReuseAddress");
+        }
         InetSocketAddress address = new InetSocketAddress(localEp, DatabaseDescriptor.getStoragePort());
         try
         {
@@ -421,7 +443,11 @@ public final class MessagingService implements MessagingServiceMBean
                 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;
+                throw new RuntimeException(e);
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException(e);
         }
         logger.info("Starting Messaging Service on port {}", DatabaseDescriptor.getStoragePort());
         ss.add(socket);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc68336c/src/java/org/apache/cassandra/service/CassandraDaemon.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/CassandraDaemon.java b/src/java/org/apache/cassandra/service/CassandraDaemon.java
index 773aa47..03da7e3 100644
--- a/src/java/org/apache/cassandra/service/CassandraDaemon.java
+++ b/src/java/org/apache/cassandra/service/CassandraDaemon.java
@@ -117,7 +117,7 @@ public class CassandraDaemon
      *
      * @throws IOException
      */
-    protected void setup() throws IOException
+    protected void setup()
     {
         logger.info("JVM vendor/version: {}/{}", System.getProperty("java.vm.name"), System.getProperty("java.version")
);
         logger.info("Heap size: {}/{}", Runtime.getRuntime().totalMemory(), Runtime.getRuntime().maxMemory());
@@ -259,7 +259,14 @@ public class CassandraDaemon
         }
 
         // replay the log if necessary
-        CommitLog.instance.recover();
+        try
+        {
+            CommitLog.instance.recover();
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException(e);
+        }
 
         // enable auto compaction
         for (Table table : Table.all())

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc68336c/src/java/org/apache/cassandra/service/StorageService.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StorageService.java b/src/java/org/apache/cassandra/service/StorageService.java
index a747e1e..61d7619 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -375,12 +375,12 @@ public class StorageService implements IEndpointStateChangeSubscriber,
StorageSe
         Schema.instance.updateVersionAndAnnounce();
     }
 
-    public synchronized void initServer() throws IOException, ConfigurationException
+    public synchronized void initServer() throws ConfigurationException
     {
         initServer(RING_DELAY);
     }
 
-    public synchronized void initServer(int delay) throws IOException, ConfigurationException
+    public synchronized void initServer(int delay) throws ConfigurationException
     {
         logger.info("Cassandra version: " + FBUtilities.getReleaseVersionString());
         logger.info("Thrift API version: " + Constants.VERSION);
@@ -487,7 +487,7 @@ public class StorageService implements IEndpointStateChangeSubscriber,
StorageSe
         }
     }
 
-    private void joinTokenRing(int delay) throws IOException, ConfigurationException
+    private void joinTokenRing(int delay) throws ConfigurationException
     {
         logger.info("Starting up server gossip");
         joined = true;
@@ -806,7 +806,7 @@ public class StorageService implements IEndpointStateChangeSubscriber,
StorageSe
             logger.debug(logMsg);
     }
 
-    private void bootstrap(Collection<Token> tokens) throws IOException
+    private void bootstrap(Collection<Token> tokens)
     {
         isBootstrapMode = true;
         SystemTable.updateTokens(tokens); // DON'T use setToken, that makes us part of the
ring locally which is incorrect until we are done bootstrapping


Mime
View raw message