cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r894467 - in /incubator/cassandra/trunk: src/java/org/apache/cassandra/db/ src/java/org/apache/cassandra/io/ src/java/org/apache/cassandra/service/ src/java/org/apache/cassandra/utils/ test/unit/org/apache/cassandra/db/
Date Tue, 29 Dec 2009 19:25:19 GMT
Author: jbellis
Date: Tue Dec 29 19:25:18 2009
New Revision: 894467

URL: http://svn.apache.org/viewvc?rev=894467&view=rev
Log:
convert Runnables containing code involving checked exceptions to WrappedRunnable, which reduces
the boilerplate of rethrowing as RuntimeException.  Also replace one-off Runner class from
test suite that served a similar purpose.  patch by jbellis

Added:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/WrappedRunnable.java   (with
props)
Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLogExecutorService.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CompactionManager.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/HintedHandOffManager.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/io/DeletionService.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=894467&r1=894466&r2=894467&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Tue
Dec 29 19:25:18 2009
@@ -368,23 +368,16 @@
             memtable_ = new Memtable(table_, columnFamily_);
             // a second executor that makes sure the onMemtableFlushes get called in the
right order,
             // while keeping the wait-for-flush (future.get) out of anything latency-sensitive.
-            return commitLogUpdater_.submit(new Runnable()
+            return commitLogUpdater_.submit(new WrappedRunnable()
             {
-                public void run()
+                public void runMayThrow() throws InterruptedException, IOException
                 {
-                    try
+                    condition.await();
+                    if (writeCommitLog)
                     {
-                        condition.await();
-                        if (writeCommitLog)
-                        {
-                            // if we're not writing to the commit log, we are replaying the
log, so marking
-                            // the log header with "you can discard anything written before
the context" is not valid
-                            onMemtableFlush(ctx);
-                        }
-                    }
-                    catch (Exception e)
-                    {
-                        throw new RuntimeException(e);
+                        // if we're not writing to the commit log, we are replaying the log,
so marking
+                        // the log header with "you can discard anything written before the
context" is not valid
+                        onMemtableFlush(ctx);
                     }
                 }
             });
@@ -675,18 +668,11 @@
             public void run()
             {
                 final List sortedKeys = flushable.getSortedKeys();
-                flushWriter_.submit(new Runnable()
+                flushWriter_.submit(new WrappedRunnable()
                 {
-                    public void run()
+                    public void runMayThrow() throws IOException
                     {
-                        try
-                        {
-                            addSSTable(flushable.writeSortedContents(sortedKeys));
-                        }
-                        catch (IOException e)
-                        {
-                            throw new RuntimeException(e);
-                        }
+                        addSSTable(flushable.writeSortedContents(sortedKeys));
                         if (flushable instanceof Memtable)
                         {
                             getMemtablesPendingFlushNotNull(columnFamily_).remove(flushable);

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java?rev=894467&r1=894466&r2=894467&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java Tue Dec 29 19:25:18
2009
@@ -23,6 +23,7 @@
 import org.apache.cassandra.io.util.DataOutputBuffer;
 import org.apache.cassandra.io.DeletionService;
 import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.WrappedRunnable;
 import org.apache.cassandra.concurrent.StageManager;
 
 import org.apache.commons.lang.StringUtils;
@@ -187,18 +188,11 @@
 
         if (DatabaseDescriptor.getCommitLogSync() == DatabaseDescriptor.CommitLogSync.periodic)
         {
-            final Runnable syncer = new Runnable()
+            final Runnable syncer = new WrappedRunnable()
             {
-                public void run()
+                public void runMayThrow() throws IOException
                 {
-                    try
-                    {
-                        sync();
-                    }
-                    catch (IOException e)
-                    {
-                        throw new RuntimeException(e);
-                    }
+                    sync();
                 }
             };
 
@@ -215,7 +209,7 @@
                         }
                         catch (InterruptedException e)
                         {
-                            throw new RuntimeException(e);
+                            throw new AssertionError(e);
                         }
                     }
                 }
@@ -339,9 +333,9 @@
                 tablesRecovered.add(table);
                 final Collection<ColumnFamily> columnFamilies = new ArrayList<ColumnFamily>(rm.getColumnFamilies());
                 final long entryLocation = reader.getFilePointer();
-                Runnable runnable = new Runnable()
+                Runnable runnable = new WrappedRunnable()
                 {
-                    public void run()
+                    public void runMayThrow() throws IOException
                     {
                         /* remove column families that have already been flushed before applying
the rest */
                         for (ColumnFamily columnFamily : columnFamilies)
@@ -354,14 +348,7 @@
                         }
                         if (!rm.isEmpty())
                         {
-                            try
-                            {
-                                Table.open(rm.getTable()).apply(rm, null, false);
-                            }
-                            catch (IOException e)
-                            {
-                                throw new IOError(e);
-                            }
+                            Table.open(rm.getTable()).apply(rm, null, false);
                         }
                     }
                 };

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLogExecutorService.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLogExecutorService.java?rev=894467&r1=894466&r2=894467&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLogExecutorService.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLogExecutorService.java
Tue Dec 29 19:25:18 2009
@@ -32,6 +32,7 @@
 import javax.management.ObjectName;
 
 import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.utils.WrappedRunnable;
 
 public class CommitLogExecutorService extends AbstractExecutorService implements CommitLogExecutorServiceMBean
 {
@@ -42,32 +43,25 @@
     public CommitLogExecutorService()
     {
         queue = new ArrayBlockingQueue<CheaterFutureTask>(10000);
-        Runnable runnable = new Runnable()
+        Runnable runnable = new WrappedRunnable()
         {
-            public void run()
+            public void runMayThrow() throws Exception
             {
-                try
+                if (DatabaseDescriptor.getCommitLogSync() == DatabaseDescriptor.CommitLogSync.batch)
                 {
-                    if (DatabaseDescriptor.getCommitLogSync() == DatabaseDescriptor.CommitLogSync.batch)
+                    while (true)
                     {
-                        while (true)
-                        {
-                            processWithSyncBatch();
-                            completedTaskCount++;
-                        }
-                    }
-                    else
-                    {
-                        while (true)
-                        {
-                            process();
-                            completedTaskCount++;
-                        }
+                        processWithSyncBatch();
+                        completedTaskCount++;
                     }
                 }
-                catch (Exception e)
+                else
                 {
-                    throw new RuntimeException(e);
+                    while (true)
+                    {
+                        process();
+                        completedTaskCount++;
+                    }
                 }
             }
         };

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CompactionManager.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CompactionManager.java?rev=894467&r1=894466&r2=894467&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CompactionManager.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CompactionManager.java Tue
Dec 29 19:25:18 2009
@@ -36,6 +36,7 @@
 import org.apache.cassandra.service.AntiEntropyService;
 import org.apache.cassandra.io.util.FileUtils;
 import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.WrappedRunnable;
 import org.cliffc.high_scale_lib.NonBlockingHashMap;
 
 import java.net.InetAddress;
@@ -444,18 +445,11 @@
      */
     static void gcAfterRpcTimeout()
     {
-        new Thread(new Runnable()
+        new Thread(new WrappedRunnable()
         {
-            public void run()
+            public void runMayThrow() throws InterruptedException
             {
-                try
-                {
-                    Thread.sleep(DatabaseDescriptor.getRpcTimeout());
-                }
-                catch (InterruptedException e)
-                {
-                    throw new AssertionError(e);
-                }
+                Thread.sleep(DatabaseDescriptor.getRpcTimeout());
                 System.gc();
             }
         }).start();

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/HintedHandOffManager.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/HintedHandOffManager.java?rev=894467&r1=894466&r2=894467&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/HintedHandOffManager.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/HintedHandOffManager.java Tue
Dec 29 19:25:18 2009
@@ -41,6 +41,7 @@
 import org.apache.cassandra.service.*;
 import org.apache.cassandra.db.filter.IdentityQueryFilter;
 import org.apache.cassandra.db.filter.QueryPath;
+import org.apache.cassandra.utils.WrappedRunnable;
 
 
 /**
@@ -254,18 +255,11 @@
 
     public void scheduleHandoffsFor(final ColumnFamilyStore columnFamilyStore)
     {
-        final Runnable r = new Runnable()
+        final Runnable r = new WrappedRunnable()
         {
-            public void run()
+            public void runMayThrow() throws Exception
             {
-                try
-                {
-                    deliverAllHints(columnFamilyStore);
-                }
-                catch (Exception e)
-                {
-                    throw new RuntimeException(e);
-                }
+                deliverAllHints(columnFamilyStore);
             }
         };
         TimerTask task = new TimerTask()
@@ -285,18 +279,11 @@
     */
     public void deliverHints(final InetAddress to)
     {
-        Runnable r = new Runnable()
+        Runnable r = new WrappedRunnable()
         {
-            public void run()
+            public void runMayThrow() throws Exception
             {
-                try
-                {
-                    deliverHintsToEndpoint(to);
-                }
-                catch (Exception e)
-                {
-                    throw new RuntimeException(e);
-                }
+                deliverHintsToEndpoint(to);
             }
         };
     	executor_.submit(r);

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/io/DeletionService.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/DeletionService.java?rev=894467&r1=894466&r2=894467&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/io/DeletionService.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/io/DeletionService.java Tue Dec
29 19:25:18 2009
@@ -6,6 +6,7 @@
 
 import org.apache.cassandra.concurrent.JMXEnabledThreadPoolExecutor;
 import org.apache.cassandra.io.util.FileUtils;
+import org.apache.cassandra.utils.WrappedRunnable;
 
 public class DeletionService
 {
@@ -13,18 +14,12 @@
 
     public static void deleteAsync(final String file) throws IOException
     {
-        Runnable deleter = new Runnable()
+        Runnable deleter = new WrappedRunnable()
         {
-            public void run()
+            @Override
+            protected void runMayThrow() throws IOException
             {
-                try
-                {
-                    FileUtils.deleteWithConfirm(new File(file));
-                }
-                catch (IOException e)
-                {
-                    throw new RuntimeException(e);
-                }
+                FileUtils.deleteWithConfirm(new File(file));
             }
         };
         executor.submit(deleter);

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java?rev=894467&r1=894466&r2=894467&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageProxy.java Tue
Dec 29 19:25:18 2009
@@ -40,6 +40,7 @@
 import org.apache.cassandra.utils.TimedStatsDeque;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.Pair;
+import org.apache.cassandra.utils.WrappedRunnable;
 import org.apache.cassandra.locator.TokenMetadata;
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.dht.Range;
@@ -122,18 +123,11 @@
                             {
                                 if (logger.isDebugEnabled())
                                     logger.debug("insert writing local key " + rm.key());
-                                Runnable runnable = new Runnable()
+                                Runnable runnable = new WrappedRunnable()
                                 {
-                                    public void run()
+                                    public void runMayThrow() throws IOException
                                     {
-                                        try
-                                        {
-                                            rm.apply();
-                                        }
-                                        catch (IOException e)
-                                        {
-                                            throw new IOError(e);
-                                        }
+                                        rm.apply();
                                     }
                                 };
                                 StageManager.getStage(StageManager.mutationStage_).execute(runnable);
@@ -268,19 +262,12 @@
     {
         if (logger.isDebugEnabled())
             logger.debug("insert writing local key " + rm.key());
-        Runnable runnable = new Runnable()
+        Runnable runnable = new WrappedRunnable()
         {
-            public void run()
+            public void runMayThrow() throws IOException
             {
-                try
-                {
-                    rm.apply();
-                    responseHandler.localResponse();
-                }
-                catch (IOException e)
-                {
-                    throw new IOError(e);
-                }
+                rm.apply();
+                responseHandler.localResponse();
             }
         };
         StageManager.getStage(StageManager.mutationStage_).execute(runnable);

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java?rev=894467&r1=894466&r2=894467&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java Tue
Dec 29 19:25:18 2009
@@ -38,6 +38,7 @@
 import org.apache.cassandra.net.*;
 import org.apache.cassandra.service.AntiEntropyService.TreeRequestVerbHandler;
 import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.WrappedRunnable;
 import org.apache.cassandra.io.SSTableReader;
 import org.apache.cassandra.io.Streaming;
 import org.apache.cassandra.io.StreamRequestVerbHandler;
@@ -1359,22 +1360,15 @@
         logger_.info("move sleeping " + Streaming.RING_DELAY);
         Thread.sleep(Streaming.RING_DELAY);
 
-        Runnable finishMoving = new Runnable()
+        Runnable finishMoving = new WrappedRunnable()
         {
-            public void run()
+            public void runMayThrow() throws IOException
             {
-                try
-                {
-                    Token bootstrapToken = token;
-                    if (bootstrapToken == null)
-                        bootstrapToken = BootStrapper.getBalancedToken(tokenMetadata_, StorageLoadBalancer.instance().getLoadInfo());
-                    logger_.info("re-bootstrapping to new token " + bootstrapToken);
-                    startBootstrap(bootstrapToken);
-                }
-                catch (IOException e)
-                {
-                    throw new IOError(e);
-                }
+                Token bootstrapToken = token;
+                if (bootstrapToken == null)
+                    bootstrapToken = BootStrapper.getBalancedToken(tokenMetadata_, StorageLoadBalancer.instance().getLoadInfo());
+                logger_.info("re-bootstrapping to new token " + bootstrapToken);
+                startBootstrap(bootstrapToken);
             }
         };
         unbootstrap(finishMoving);

Added: incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/WrappedRunnable.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/WrappedRunnable.java?rev=894467&view=auto
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/WrappedRunnable.java (added)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/WrappedRunnable.java Tue
Dec 29 19:25:18 2009
@@ -0,0 +1,18 @@
+package org.apache.cassandra.utils;
+
+public abstract class WrappedRunnable implements Runnable
+{
+    public final void run()
+    {
+        try
+        {
+            runMayThrow();
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
+    abstract protected void runMayThrow() throws Exception;
+}

Propchange: incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/WrappedRunnable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java?rev=894467&r1=894466&r2=894467&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
(original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
Tue Dec 29 19:25:18 2009
@@ -28,6 +28,8 @@
 
 import static junit.framework.Assert.assertEquals;
 import org.apache.cassandra.CleanupHelper;
+import org.apache.cassandra.utils.WrappedRunnable;
+
 import java.net.InetAddress;
 import org.apache.cassandra.dht.Range;
 import org.apache.cassandra.dht.IPartitioner;
@@ -81,9 +83,9 @@
         rm.delete(new QueryPath("Standard2", null, null), System.currentTimeMillis());
         rm.apply();
 
-        TableTest.Runner r = new TableTest.Runner()
+        Runnable r = new WrappedRunnable()
         {
-            public void run() throws IOException
+            public void runMayThrow() throws IOException
             {
                 SliceQueryFilter sliceFilter = new SliceQueryFilter("key1", new QueryPath("Standard2",
null, null), ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, false, 1);
                 assertNull(store.getColumnFamily(sliceFilter));

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java?rev=894467&r1=894466&r2=894467&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java (original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/TableTest.java Tue Dec 29
19:25:18 2009
@@ -30,6 +30,7 @@
 
 import static junit.framework.Assert.*;
 import org.apache.cassandra.CleanupHelper;
+import org.apache.cassandra.utils.WrappedRunnable;
 import static org.apache.cassandra.Util.column;
 import static org.apache.cassandra.Util.getBytes;
 import org.apache.cassandra.db.filter.NamesQueryFilter;
@@ -45,12 +46,7 @@
     private static final String KEY2 = "key2";
     private static final String TEST_KEY = "key1";
 
-    public interface Runner
-    {
-        public void run() throws Exception;
-    }
-
-    public static void reTest(ColumnFamilyStore cfs, Runner verify) throws Exception
+    public static void reTest(ColumnFamilyStore cfs, Runnable verify) throws Exception
     {
         verify.run();
         cfs.forceBlockingFlush();
@@ -69,9 +65,9 @@
         rm.add(cf);
         rm.apply();
 
-        Runner verify = new Runner()
+        Runnable verify = new WrappedRunnable()
         {
-            public void run() throws Exception
+            public void runMayThrow() throws Exception
             {
                 ColumnFamily cf;
 
@@ -102,9 +98,9 @@
         rm.add(cf);
         rm.apply();
 
-        Runner verify = new Runner()
+        Runnable verify = new WrappedRunnable()
         {
-            public void run() throws Exception
+            public void runMayThrow() throws Exception
             {
                 ColumnFamily cf;
 
@@ -184,9 +180,9 @@
         rm.add(cf);
         rm.apply();
 
-        Runner verify = new Runner()
+        Runnable verify = new WrappedRunnable()
         {
-            public void run() throws Exception
+            public void runMayThrow() throws Exception
             {
                 ColumnFamily cf;
 
@@ -262,9 +258,9 @@
         rm.delete(new QueryPath("Standard1", null, "col4".getBytes()), 2L);
         rm.apply();
 
-        Runner verify = new Runner()
+        Runnable verify = new WrappedRunnable()
         {
-            public void run() throws Exception
+            public void runMayThrow() throws Exception
             {
                 ColumnFamily cf;
 
@@ -323,9 +319,9 @@
         rm.add(cf);
         rm.apply();
 
-        Runner verify = new Runner()
+        Runnable verify = new WrappedRunnable()
         {
-            public void run() throws Exception
+            public void runMayThrow() throws Exception
             {
                 ColumnFamily cf;
 
@@ -435,9 +431,9 @@
         rm.add(cf);
         rm.apply();
 
-        Runner verify = new Runner()
+        Runnable verify = new WrappedRunnable()
         {
-            public void run() throws Exception
+            public void runMayThrow() throws Exception
             {
                 ColumnFamily cf = cfStore.getColumnFamily(ROW, new QueryPath("Super1"), ArrayUtils.EMPTY_BYTE_ARRAY,
ArrayUtils.EMPTY_BYTE_ARRAY, false, 10);
                 assertColumns(cf, "sc1");



Mime
View raw message