Fix repair hang when given CF does not exist

patch by yukim; reviewed by krummas for CASSANDRA-7189


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

Branch: refs/heads/trunk
Commit: 359de196f1d7a8f9193d0e977b57ce5d846b9f01
Parents: 7b398c5
Author: Yuki Morishita <yu...@apache.org>
Authored: Mon May 12 12:36:35 2014 -0500
Committer: Yuki Morishita <yu...@apache.org>
Committed: Mon May 12 12:36:35 2014 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/service/StorageService.java       | 46 ++++++--------------
 2 files changed, 14 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/359de196/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index e307843..58c6277 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,6 +8,7 @@
  * Cleanup and optimize collation and slice iterators (CASSANDRA-7107)
  * Upgrade NBHM lib (CASSANDRA-7128)
  * Optimize netty server (CASSANDRA-6861)
+ * Fix repair hang when given CF does not exist (CASSANDRA-7189)
 Merged from 2.0:
  * Correctly delete scheduled range xfers (CASSANDRA-7143)
  * Make batchlog replica selection rack-aware (CASSANDRA-6551)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/359de196/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 f1e853a..68257bb 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -2444,6 +2444,7 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
      * @param autoAddIndexes Automatically add secondary indexes if a CF has 
them
      * @param keyspaceName keyspace
      * @param cfNames CFs
+     * @throws java.lang.IllegalArgumentException when given CF name does not 
exist
      */
     public Iterable<ColumnFamilyStore> getValidColumnFamilies(boolean 
allowIndexes, boolean autoAddIndexes, String keyspaceName, String... cfNames) 
throws IOException
     {
@@ -2490,12 +2491,6 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
             }
 
             ColumnFamilyStore cfStore = 
keyspace.getColumnFamilyStore(baseCfName);
-            if (cfStore == null)
-            {
-                // this means there was a cf passed in that is not recognized 
in the keyspace. report it and continue.
-                logger.warn(String.format("Invalid column family specified: 
%s. Proceeding with others.", baseCfName));
-                continue;
-            }
             if (idxName != null)
             {
                 Collection< SecondaryIndex > indexes = 
cfStore.indexManager.getIndexesByNames(new HashSet<>(Arrays.asList(cfName)));
@@ -2673,14 +2668,22 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
                     catch (IllegalArgumentException e)
                     {
                         logger.error("Repair failed:", e);
-                        sendNotification("repair", message, new int[]{cmd, 
ActiveRepairService.Status.FINISHED.ordinal()});
+                        sendNotification("repair", e.getMessage(), new 
int[]{cmd, ActiveRepairService.Status.FINISHED.ordinal()});
                         return;
                     }
                 }
 
+                // Validate columnfamilies
                 List<ColumnFamilyStore> columnFamilyStores = new ArrayList<>();
-                for (ColumnFamilyStore cfs : getValidColumnFamilies(false, 
false, keyspace, columnFamilies))
-                    columnFamilyStores.add(cfs);
+                try
+                {
+                    Iterables.addAll(columnFamilyStores, 
getValidColumnFamilies(false, false, keyspace, columnFamilies));
+                }
+                catch (IllegalArgumentException e)
+                {
+                    sendNotification("repair", e.getMessage(), new int[]{cmd, 
ActiveRepairService.Status.FINISHED.ordinal()});
+                    return;
+                }
 
                 UUID parentSession = null;
                 if (!fullRepair)
@@ -2699,7 +2702,7 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
                 List<RepairFuture> futures = new ArrayList<>(ranges.size());
                 for (Range<Token> range : ranges)
                 {
-                    RepairFuture future = forceKeyspaceRepair(parentSession, 
range, keyspace, isSequential, rangeToNeighbors.get(range), columnFamilies);
+                    RepairFuture future = 
ActiveRepairService.instance.submitRepairSession(parentSession, range, 
keyspace, isSequential, rangeToNeighbors.get(range), columnFamilies);
                     if (future == null)
                         continue;
                     futures.add(future);
@@ -2745,29 +2748,6 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
         }, null);
     }
 
-
-    public RepairFuture forceKeyspaceRepair(UUID parentRepairSession,
-                                            Range<Token> range,
-                                            String keyspaceName,
-                                            boolean isSequential,
-                                            Set<InetAddress> endpoints,
-                                            String ... columnFamilies) throws 
IOException
-    {
-        ArrayList<String> names = new ArrayList<>();
-        for (ColumnFamilyStore cfStore : getValidColumnFamilies(false, false, 
keyspaceName, columnFamilies))
-        {
-            names.add(cfStore.name);
-        }
-
-        if (names.isEmpty())
-        {
-            logger.info("No column family to repair for keyspace {}", 
keyspaceName);
-            return null;
-        }
-
-        return 
ActiveRepairService.instance.submitRepairSession(parentRepairSession, range, 
keyspaceName, isSequential, endpoints, names.toArray(new String[names.size()]));
-    }
-
     public void forceTerminateAllRepairSessions() {
         ActiveRepairService.instance.terminateSessions();
     }

Reply via email to