Author: slebresne
Date: Fri Sep  2 16:12:36 2011
New Revision: 1164602

URL: http://svn.apache.org/viewvc?rev=1164602&view=rev
Log:
expose ability to only repair the primary range of a node
patch by slebresne; reviewed by jbellis for CASSANDRA-2606

Modified:
    cassandra/trunk/CHANGES.txt
    cassandra/trunk/NEWS.txt
    cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
    
cassandra/trunk/src/java/org/apache/cassandra/service/StorageServiceMBean.java
    cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java
    cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java

Modified: cassandra/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=1164602&r1=1164601&r2=1164602&view=diff
==============================================================================
--- cassandra/trunk/CHANGES.txt (original)
+++ cassandra/trunk/CHANGES.txt Fri Sep  2 16:12:36 2011
@@ -56,6 +56,8 @@
  * Make the compression algorithm and chunk length configurable 
(CASSANDRA-3001)
  * Add throttling for internode streaming (CASSANDRA-3080)
  * make the repair of a range repair all replica (CASSANDRA-2610)
+ * expose the ability to repair the first range (as returned by the
+   partitioner) of a node (CASSANDRA-2606)
 
 0.8.5
  * fix NPE when encryption_options is unspecified (CASSANDRA-3007)

Modified: cassandra/trunk/NEWS.txt
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/NEWS.txt?rev=1164602&r1=1164601&r2=1164602&view=diff
==============================================================================
--- cassandra/trunk/NEWS.txt (original)
+++ cassandra/trunk/NEWS.txt Fri Sep  2 16:12:36 2011
@@ -38,6 +38,10 @@ Other
       when HH is enabled, repair only needs to be run if a node crashes.
     - Because of this, read repair is disabled now by default on newly
       created ColumnFamilies.
+    - It is now possible to repair only the first range returned by the
+      partitioner for a node with `nodetool repair -pr`. It makes it
+      easier/possible to repair a full cluster without any work duplication by
+      running this command on every node of the cluster.
 
 
 0.8.5

Modified: 
cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java?rev=1164602&r1=1164601&r2=1164602&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java 
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java 
Fri Sep  2 16:12:36 2011
@@ -1602,9 +1602,8 @@ public class StorageService implements I
     public void forceTableRepair(final String tableName, final String... 
columnFamilies) throws IOException
     {
         if (Table.SYSTEM_TABLE.equals(tableName))
-        {
             return;
-        }
+
         List<AntiEntropyService.RepairFuture> futures = new 
ArrayList<AntiEntropyService.RepairFuture>();
         for (Range range : getLocalRanges(tableName))
         {
@@ -1632,7 +1631,7 @@ public class StorageService implements I
             }
             catch (Exception e)
             {
-                logger_.error("Repair session " + future.session + " failed.", 
e);
+                logger_.error("Repair session " + future.session.getName() + " 
failed.", e);
                 failedSession = true;
             }
         }
@@ -1641,6 +1640,23 @@ public class StorageService implements I
             throw new IOException("Some repair session(s) failed (see log for 
details).");
     }
 
+    public void forceTableRepairPrimaryRange(final String tableName, final 
String... columnFamilies) throws IOException
+    {
+        if (Table.SYSTEM_TABLE.equals(tableName))
+            return;
+
+        AntiEntropyService.RepairFuture future = 
forceTableRepair(getLocalPrimaryRange(), tableName, columnFamilies);
+        try
+        {
+            future.get();
+        }
+        catch (Exception e)
+        {
+            logger_.error("Repair session " + future.session.getName() + " 
failed.", e);
+            throw new IOException("Some repair session(s) failed (see log for 
details).");
+        }
+    }
+
     public AntiEntropyService.RepairFuture forceTableRepair(final Range range, 
final String tableName, final String... columnFamilies) throws IOException
     {
         ArrayList<String> names = new ArrayList<String>();

Modified: 
cassandra/trunk/src/java/org/apache/cassandra/service/StorageServiceMBean.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/service/StorageServiceMBean.java?rev=1164602&r1=1164601&r2=1164602&view=diff
==============================================================================
--- 
cassandra/trunk/src/java/org/apache/cassandra/service/StorageServiceMBean.java 
(original)
+++ 
cassandra/trunk/src/java/org/apache/cassandra/service/StorageServiceMBean.java 
Fri Sep  2 16:12:36 2011
@@ -222,6 +222,11 @@ public interface StorageServiceMBean
     public void forceTableRepair(String tableName, String... columnFamilies) 
throws IOException;
 
     /**
+     * Triggers proactive repair but only for the node primary range.
+     */
+    public void forceTableRepairPrimaryRange(String tableName, String... 
columnFamilies) throws IOException;
+
+    /**
      * transfer this node's data to other machines and remove it from service.
      */
     public void decommission() throws InterruptedException;

Modified: cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java?rev=1164602&r1=1164601&r2=1164602&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/tools/NodeCmd.java Fri Sep  2 
16:12:36 2011
@@ -51,6 +51,7 @@ public class NodeCmd
     private static final Pair<String, String> USERNAME_OPT = new Pair<String, 
String>("u",  "username");
     private static final Pair<String, String> PASSWORD_OPT = new Pair<String, 
String>("pw", "password");
     private static final Pair<String, String> TAG_OPT = new Pair<String, 
String>("t", "tag");
+    private static final Pair<String, String> PRIMARY_RANGE_OPT = new 
Pair<String, String>("pr", "partitioner-range");
     private static final int DEFAULT_PORT = 7199;
 
     private static ToolOptions options = null;
@@ -66,6 +67,7 @@ public class NodeCmd
         options.addOption(USERNAME_OPT, true, "remote jmx agent username");
         options.addOption(PASSWORD_OPT, true, "remote jmx agent password");
         options.addOption(TAG_OPT,      true, "optional name to give a 
snapshot");
+        options.addOption(PRIMARY_RANGE_OPT, false, "only repair the first 
range returned by the partitioner for the node");
     }
     
     public NodeCmd(NodeProbe probe)
@@ -119,7 +121,7 @@ public class NodeCmd
         addCmdHelp(header, "snapshot [keyspaces...] -t [snapshotName]", "Take 
a snapshot of the specified keyspaces using optional name snapshotName");
         addCmdHelp(header, "clearsnapshot [keyspaces...] -t [snapshotName]", 
"Remove snapshots for the specified keyspaces. Either remove all snapshots or 
remove the snapshots with the given name.");
         addCmdHelp(header, "flush [keyspace] [cfnames]", "Flush one or more 
column family");
-        addCmdHelp(header, "repair [keyspace] [cfnames]", "Repair one or more 
column family");
+        addCmdHelp(header, "repair [keyspace] [cfnames]", "Repair one or more 
column family (use -rp to repair only the first range returned by the 
partitioner)");
         addCmdHelp(header, "cleanup [keyspace] [cfnames]", "Run cleanup on one 
or more column family");
         addCmdHelp(header, "compact [keyspace] [cfnames]", "Force a (major) 
compaction on one or more column family");
         addCmdHelp(header, "scrub [keyspace] [cfnames]", "Scrub (rebuild 
sstables for) one or more column family");
@@ -669,7 +671,7 @@ public class NodeCmd
             case SCRUB   :
             case INVALIDATEKEYCACHE :
             case INVALIDATEROWCACHE :
-                optionalKSandCFs(command, arguments, probe);
+                optionalKSandCFs(command, cmd, arguments, probe);
                 break;
 
             case GETCOMPACTIONTHRESHOLD :
@@ -773,7 +775,7 @@ public class NodeCmd
         }
     }
 
-    private static void optionalKSandCFs(NodeCommand nc, String[] cmdArgs, 
NodeProbe probe) throws InterruptedException, IOException
+    private static void optionalKSandCFs(NodeCommand nc, ToolCommandLine cmd, 
String[] cmdArgs, NodeProbe probe) throws InterruptedException, IOException
     {
         // if there is one additional arg, it's the keyspace; more are 
columnfamilies
         List<String> keyspaces = cmdArgs.length == 0 ? probe.getKeyspaces() : 
Arrays.asList(cmdArgs[0]);
@@ -792,7 +794,12 @@ public class NodeCmd
             String[] columnFamilies = cmdArgs.length <= 1 ? new String[0] : 
Arrays.copyOfRange(cmdArgs, 1, cmdArgs.length);
             switch (nc)
             {
-                case REPAIR  : probe.forceTableRepair(keyspace, 
columnFamilies); break;
+                case REPAIR  :
+                    if (cmd.hasOption(PRIMARY_RANGE_OPT.left))
+                        probe.forceTableRepairPrimaryRange(keyspace, 
columnFamilies);
+                    else
+                        probe.forceTableRepair(keyspace, columnFamilies);
+                    break;
                 case INVALIDATEKEYCACHE : probe.invalidateKeyCaches(keyspace, 
columnFamilies); break;
                 case INVALIDATEROWCACHE : probe.invalidateRowCaches(keyspace, 
columnFamilies); break;
                 case FLUSH   :

Modified: cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java?rev=1164602&r1=1164601&r2=1164602&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java 
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java Fri Sep  
2 16:12:36 2011
@@ -197,6 +197,11 @@ public class NodeProbe
         ssProxy.forceTableRepair(tableName, columnFamilies);
     }
 
+    public void forceTableRepairPrimaryRange(String tableName, String... 
columnFamilies) throws IOException
+    {
+        ssProxy.forceTableRepairPrimaryRange(tableName, columnFamilies);
+    }
+
     public void invalidateKeyCaches(String tableName, String... 
columnFamilies) throws IOException
     {
         ssProxy.invalidateKeyCaches(tableName, columnFamilies);


Reply via email to