cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject [2/3] git commit: Allow truncating hints from nodetool. Patch by Sankalp Kohli, reviewed by brandonwilliams for CASSANDRA-6158
Date Mon, 30 Dec 2013 14:20:41 GMT
Allow truncating hints from nodetool.
Patch by Sankalp Kohli, reviewed by brandonwilliams for CASSANDRA-6158


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

Branch: refs/heads/trunk
Commit: 604e31b60998d5df349f8cc84d06bbae1391dc0e
Parents: bbc0891
Author: Brandon Williams <brandonwilliams@apache.org>
Authored: Mon Dec 30 08:17:50 2013 -0600
Committer: Brandon Williams <brandonwilliams@apache.org>
Committed: Mon Dec 30 08:17:50 2013 -0600

----------------------------------------------------------------------
 .../cassandra/db/HintedHandOffManager.java      | 24 ++++++++++++++-
 .../cassandra/db/HintedHandOffManagerMBean.java |  6 ++++
 .../org/apache/cassandra/tools/NodeCmd.java     |  8 ++++-
 .../org/apache/cassandra/tools/NodeProbe.java   | 21 +++++++++++++
 .../apache/cassandra/tools/NodeToolHelp.yaml    |  3 ++
 .../apache/cassandra/db/HintedHandOffTest.java  | 32 ++++++++++++++++++++
 6 files changed, 92 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/604e31b6/src/java/org/apache/cassandra/db/HintedHandOffManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/HintedHandOffManager.java b/src/java/org/apache/cassandra/db/HintedHandOffManager.java
index 9508a86..40d5aaa 100644
--- a/src/java/org/apache/cassandra/db/HintedHandOffManager.java
+++ b/src/java/org/apache/cassandra/db/HintedHandOffManager.java
@@ -225,7 +225,29 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean
                 }
             }
         };
-        StorageService.optionalTasks.execute(runnable);
+        StorageService.optionalTasks.submit(runnable);
+    }
+
+    //foobar
+    public void truncateAllHints() throws ExecutionException, InterruptedException
+    {
+        Runnable runnable = new Runnable()
+        {
+            public void run()
+            {
+                try
+                {
+                    logger.info("Truncating all stored hints.");
+                    Keyspace.open(Keyspace.SYSTEM_KS).getColumnFamilyStore(SystemKeyspace.HINTS_CF).truncateBlocking();
+                }
+                catch (Exception e)
+                {
+                    logger.warn("Could not truncate all hints.", e);
+                }
+            }
+        };
+        StorageService.optionalTasks.submit(runnable).get();
+
     }
 
     @VisibleForTesting

http://git-wip-us.apache.org/repos/asf/cassandra/blob/604e31b6/src/java/org/apache/cassandra/db/HintedHandOffManagerMBean.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/HintedHandOffManagerMBean.java b/src/java/org/apache/cassandra/db/HintedHandOffManagerMBean.java
index 9a024e6..bbb2a14 100644
--- a/src/java/org/apache/cassandra/db/HintedHandOffManagerMBean.java
+++ b/src/java/org/apache/cassandra/db/HintedHandOffManagerMBean.java
@@ -19,6 +19,7 @@ package org.apache.cassandra.db;
 
 import java.net.UnknownHostException;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 
 public interface HintedHandOffManagerMBean
 {
@@ -29,6 +30,11 @@ public interface HintedHandOffManagerMBean
     public void deleteHintsForEndpoint(final String host);
 
     /**
+     *  Truncate all the hints
+     */
+    public void truncateAllHints() throws ExecutionException, InterruptedException;
+
+    /**
      * List all the endpoints that this node has hints for.
      * @return set of endpoints; as Strings
      */

http://git-wip-us.apache.org/repos/asf/cassandra/blob/604e31b6/src/java/org/apache/cassandra/tools/NodeCmd.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/NodeCmd.java b/src/java/org/apache/cassandra/tools/NodeCmd.java
index c32539f..f1e7c73 100644
--- a/src/java/org/apache/cassandra/tools/NodeCmd.java
+++ b/src/java/org/apache/cassandra/tools/NodeCmd.java
@@ -164,6 +164,7 @@ public class NodeCmd
         STOP,
         STOPDAEMON,
         TPSTATS,
+        TRUNCATEHINTS,
         UPGRADESSTABLES,
         VERSION,
         DESCRIBERING,
@@ -1116,7 +1117,12 @@ public class NodeCmd
                 case RESETLOCALSCHEMA: probe.resetLocalSchema(); break;
                 case ENABLEBACKUP    : probe.setIncrementalBackupsEnabled(true); break;
                 case DISABLEBACKUP   : probe.setIncrementalBackupsEnabled(false); break;
-                    
+
+                case TRUNCATEHINTS:
+                    if (arguments.length > 1) badUse("Too many arguments.");
+                    else if (arguments.length == 1) probe.truncateHints(arguments[0]);
+                    else probe.truncateHints();
+                    break;
 
                 case STATUS :
                     if (arguments.length > 0) nodeCmd.printClusterStatus(System.out, arguments[0]);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/604e31b6/src/java/org/apache/cassandra/tools/NodeProbe.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/NodeProbe.java b/src/java/org/apache/cassandra/tools/NodeProbe.java
index 4f60464..1bb9d4e 100644
--- a/src/java/org/apache/cassandra/tools/NodeProbe.java
+++ b/src/java/org/apache/cassandra/tools/NodeProbe.java
@@ -726,6 +726,27 @@ public class NodeProbe
         hhProxy.pauseHintsDelivery(false);
     }
 
+    public void truncateHints(final String host)
+    {
+        hhProxy.deleteHintsForEndpoint(host);
+    }
+
+    public void truncateHints()
+    {
+        try
+        {
+            hhProxy.truncateAllHints();
+        }
+        catch (ExecutionException e)
+        {
+            throw new RuntimeException("Error while executing truncate hints", e);
+        }
+        catch (InterruptedException e)
+        {
+            throw new RuntimeException("Error while executing truncate hints", e);
+        }
+    }
+
     public void stopNativeTransport()
     {
         ssProxy.stopNativeTransport();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/604e31b6/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml
----------------------------------------------------------------------
diff --git a/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml b/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml
index 54d0884..42fda0d 100644
--- a/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml
+++ b/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml
@@ -67,6 +67,9 @@ commands:
   - name: enablehandoff
     help: |
       Reenable the future hints storing on the current node
+  - name: truncatehints <host-name>
+    help: |
+        Truncate all hints on the local node, or truncate hints for the endpoint specified.
   - name: resumehandoff
     help: |
       Resume hints delivery process

http://git-wip-us.apache.org/repos/asf/cassandra/blob/604e31b6/test/unit/org/apache/cassandra/db/HintedHandOffTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/HintedHandOffTest.java b/test/unit/org/apache/cassandra/db/HintedHandOffTest.java
index 23db4bb..ab5bc23 100644
--- a/test/unit/org/apache/cassandra/db/HintedHandOffTest.java
+++ b/test/unit/org/apache/cassandra/db/HintedHandOffTest.java
@@ -92,4 +92,36 @@ public class HintedHandOffTest extends SchemaLoader
         Map<UUID, Integer> returned = rows.one().getMap("hints_dropped", UUIDType.instance,
Int32Type.instance);
         assertEquals(Iterators.getLast(returned.values().iterator()).intValue(), 99);
     }
+
+    @Test(timeout = 5000)
+    public void testTruncateHints() throws Exception
+    {
+        Keyspace systemKeyspace = Keyspace.open("system");
+        ColumnFamilyStore hintStore = systemKeyspace.getColumnFamilyStore(SystemKeyspace.HINTS_CF);
+        hintStore.clearUnsafe();
+
+        // insert 1 hint
+        RowMutation rm = new RowMutation(KEYSPACE4, ByteBufferUtil.bytes(1));
+        rm.add(STANDARD1_CF, ByteBufferUtil.bytes(String.valueOf(COLUMN1)), ByteBufferUtil.EMPTY_BYTE_BUFFER,
System.currentTimeMillis());
+
+        HintedHandOffManager.instance.hintFor(rm, HintedHandOffManager.calculateHintTTL(rm),
UUID.randomUUID()).apply();
+
+        assert getNoOfHints() == 1;
+
+        HintedHandOffManager.instance.truncateAllHints();
+
+        while(getNoOfHints() > 0)
+        {
+            Thread.sleep(100);
+        }
+
+        assert getNoOfHints() == 0;
+    }
+
+    private int getNoOfHints()
+    {
+        String req = "SELECT * FROM system.%s";
+        UntypedResultSet resultSet = processInternal(String.format(req, SystemKeyspace.HINTS_CF));
+        return resultSet.size();
+    }
 }


Mime
View raw message