Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

use waitOnFuture more often

  • Loading branch information...
commit dbc8bd85f23acd78de70e22b50c7168ca338dc2e 1 parent 35be1cc
Jonathan Ellis authored
13  src/java/org/apache/cassandra/db/ColumnFamilyStore.java
@@ -804,18 +804,7 @@ public void run()
804 804
 
805 805
     public void forceBlockingFlush()
806 806
     {
807  
-        try
808  
-        {
809  
-            forceFlush().get();
810  
-        }
811  
-        catch (InterruptedException e)
812  
-        {
813  
-            throw new AssertionError(e);
814  
-        }
815  
-        catch (ExecutionException e)
816  
-        {
817  
-            throw new RuntimeException(e);
818  
-        }
  807
+        FBUtilities.waitOnFuture(forceFlush());
819 808
     }
820 809
 
821 810
     public void maybeUpdateRowCache(DecoratedKey key, ColumnFamily columnFamily)
14  src/java/org/apache/cassandra/db/commitlog/BatchCommitLogExecutorService.java
@@ -21,6 +21,7 @@
21 21
 import java.util.concurrent.*;
22 22
 
23 23
 import org.apache.cassandra.config.DatabaseDescriptor;
  24
+import org.apache.cassandra.utils.FBUtilities;
24 25
 import org.apache.cassandra.utils.WrappedRunnable;
25 26
 
26 27
 class BatchCommitLogExecutorService extends AbstractCommitLogExecutorService
@@ -127,18 +128,7 @@ public void execute(Runnable command)
127 128
 
128 129
     public void add(CommitLog.LogRecordAdder adder)
129 130
     {
130  
-        try
131  
-        {
132  
-            submit((Callable)adder).get();
133  
-        }
134  
-        catch (InterruptedException e)
135  
-        {
136  
-            throw new RuntimeException(e);
137  
-        }
138  
-        catch (ExecutionException e)
139  
-        {
140  
-            throw new RuntimeException(e);
141  
-        }
  131
+        FBUtilities.waitOnFuture(submit((Callable)adder));
142 132
     }
143 133
 
144 134
     public void shutdown()
14  src/java/org/apache/cassandra/db/commitlog/CommitLog.java
@@ -36,6 +36,7 @@
36 36
 import org.apache.cassandra.io.FSWriteError;
37 37
 import org.apache.cassandra.metrics.CommitLogMetrics;
38 38
 import org.apache.cassandra.net.MessagingService;
  39
+import org.apache.cassandra.utils.FBUtilities;
39 40
 
40 41
 /*
41 42
  * Commit Log tracks every write operation into the system. The aim of the commit log is to be able to
@@ -246,18 +247,7 @@ public Object call()
246 247
             }
247 248
         };
248 249
 
249  
-        try
250  
-        {
251  
-            executor.submit(task).get();
252  
-        }
253  
-        catch (InterruptedException e)
254  
-        {
255  
-            throw new RuntimeException(e);
256  
-        }
257  
-        catch (ExecutionException e)
258  
-        {
259  
-            throw new RuntimeException(e);
260  
-        }
  250
+        FBUtilities.waitOnFuture(executor.submit(task));
261 251
     }
262 252
 
263 253
     /**
15  src/java/org/apache/cassandra/db/commitlog/PeriodicCommitLogExecutorService.java
@@ -67,19 +67,8 @@ public void run()
67 67
             {
68 68
                 while (run)
69 69
                 {
70  
-                    try
71  
-                    {
72  
-                        submit(syncer).get();
73  
-                        Thread.sleep(DatabaseDescriptor.getCommitLogSyncPeriod());
74  
-                    }
75  
-                    catch (InterruptedException e)
76  
-                    {
77  
-                        throw new AssertionError(e);
78  
-                    }
79  
-                    catch (ExecutionException e)
80  
-                    {
81  
-                        throw new RuntimeException(e);
82  
-                    }
  70
+                    FBUtilities.waitOnFuture(submit(syncer));
  71
+                    FBUtilities.sleep(DatabaseDescriptor.getCommitLogSyncPeriod());
83 72
                 }
84 73
             }
85 74
         }, "PERIODIC-COMMIT-LOG-SYNCER").start();
17  src/java/org/apache/cassandra/db/compaction/ParallelCompactionIterable.java
@@ -90,20 +90,9 @@ protected AbstractCompactedRow computeNext()
90 90
 
91 91
             CompactedRowContainer container = reducer.next();
92 92
             AbstractCompactedRow compactedRow;
93  
-            try
94  
-            {
95  
-                compactedRow = container.future == null
96  
-                             ? container.row
97  
-                             : new PrecompactedRow(container.key, container.future.get());
98  
-            }
99  
-            catch (InterruptedException e)
100  
-            {
101  
-                throw new AssertionError(e);
102  
-            }
103  
-            catch (ExecutionException e)
104  
-            {
105  
-                throw new RuntimeException(e);
106  
-            }
  93
+            compactedRow = container.future == null
  94
+                         ? container.row
  95
+                         : new PrecompactedRow(container.key, FBUtilities.waitOnFuture(container.future));
107 96
 
108 97
             return compactedRow;
109 98
         }
22  src/java/org/apache/cassandra/db/index/SecondaryIndex.java
@@ -42,6 +42,7 @@
42 42
 import org.apache.cassandra.io.sstable.ReducingKeyIterator;
43 43
 import org.apache.cassandra.io.sstable.SSTableReader;
44 44
 import org.apache.cassandra.service.StorageService;
  45
+import org.apache.cassandra.utils.FBUtilities;
45 46
 
46 47
 /**
47 48
  * Abstract base class for different types of secondary indexes.
@@ -183,25 +184,10 @@ protected void buildIndexBlocking()
183 184
                                                                   Collections.singleton(getIndexName()),
184 185
                                                                   new ReducingKeyIterator(sstables));
185 186
         Future<?> future = CompactionManager.instance.submitIndexBuild(builder);
186  
-        try
187  
-        {
188  
-            future.get();
189  
-            forceBlockingFlush();
  187
+        FBUtilities.waitOnFuture(future);
  188
+        forceBlockingFlush();
190 189
 
191  
-            setIndexBuilt();
192  
-        }
193  
-        catch (InterruptedException e)
194  
-        {
195  
-            throw new AssertionError(e);
196  
-        }
197  
-        catch (ExecutionException e)
198  
-        {
199  
-            throw new RuntimeException(e);
200  
-        }
201  
-        finally
202  
-        {
203  
-            SSTableReader.releaseReferences(sstables);
204  
-        }
  190
+        setIndexBuilt();
205 191
         logger.info("Index build of " + getIndexName() + " complete");
206 192
     }
207 193
 
14  src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java
@@ -35,6 +35,7 @@
35 35
 import org.apache.cassandra.io.sstable.SSTableReader;
36 36
 import org.apache.cassandra.thrift.IndexExpression;
37 37
 import org.apache.cassandra.thrift.IndexType;
  38
+import org.apache.cassandra.utils.FBUtilities;
38 39
 
39 40
 /**
40 41
  * Manages all the indexes associated with a given CFS
@@ -139,18 +140,7 @@ public void maybeBuildSecondaryIndexes(Collection<SSTableReader> sstables, Set<S
139 140
 
140 141
         SecondaryIndexBuilder builder = new SecondaryIndexBuilder(baseCfs, idxNames, new ReducingKeyIterator(sstables));
141 142
         Future<?> future = CompactionManager.instance.submitIndexBuild(builder);
142  
-        try
143  
-        {
144  
-            future.get();
145  
-        }
146  
-        catch (InterruptedException e)
147  
-        {
148  
-            throw new AssertionError(e);
149  
-        }
150  
-        catch (ExecutionException e)
151  
-        {
152  
-            throw new RuntimeException(e);
153  
-        }
  143
+        FBUtilities.waitOnFuture(future);
154 144
 
155 145
         flushIndexesBlocking();
156 146
 
15  src/java/org/apache/cassandra/io/sstable/SSTableDeletingTask.java
@@ -30,6 +30,7 @@
30 30
 
31 31
 import org.apache.cassandra.db.DataTracker;
32 32
 import org.apache.cassandra.service.StorageService;
  33
+import org.apache.cassandra.utils.FBUtilities;
33 34
 
34 35
 public class SSTableDeletingTask implements Runnable
35 36
 {
@@ -101,18 +102,8 @@ public void run()
101 102
             {
102 103
             }
103 104
         };
104  
-        try
105  
-        {
106  
-            StorageService.tasks.schedule(runnable, 0, TimeUnit.MILLISECONDS).get();
107  
-        }
108  
-        catch (InterruptedException e)
109  
-        {
110  
-            throw new AssertionError(e);
111  
-        }
112  
-        catch (ExecutionException e)
113  
-        {
114  
-            throw new RuntimeException(e);
115  
-        }
  105
+
  106
+        FBUtilities.waitOnFuture(StorageService.tasks.schedule(runnable, 0, TimeUnit.MILLISECONDS));
116 107
     }
117 108
 }
118 109
 
4  src/java/org/apache/cassandra/utils/FBUtilities.java
@@ -366,11 +366,11 @@ public static void waitOnFutures(Iterable<Future<?>> futures)
366 366
             waitOnFuture(f);
367 367
     }
368 368
 
369  
-    public static void waitOnFuture(Future<?> future)
  369
+    public static <T> T waitOnFuture(Future<T> future)
370 370
     {
371 371
         try
372 372
         {
373  
-            future.get();
  373
+            return future.get();
374 374
         }
375 375
         catch (ExecutionException ee)
376 376
         {

0 notes on commit dbc8bd8

Please sign in to comment.
Something went wrong with that request. Please try again.