cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1027456 - in /cassandra/branches/cassandra-0.7: ./ src/java/org/apache/cassandra/cli/ test/unit/org/apache/cassandra/cli/
Date Tue, 26 Oct 2010 10:54:58 GMT
Author: jbellis
Date: Tue Oct 26 10:54:58 2010
New Revision: 1027456

URL: http://svn.apache.org/viewvc?rev=1027456&view=rev
Log:
cli truncate support.  patch by Pavel Yaskevich; reviewed by jbellis for CASSANDRA-1653

Modified:
    cassandra/branches/cassandra-0.7/CHANGES.txt
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliCompleter.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliUserHelp.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/cli/CliTest.java

Modified: cassandra/branches/cassandra-0.7/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/CHANGES.txt?rev=1027456&r1=1027455&r2=1027456&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.7/CHANGES.txt Tue Oct 26 10:54:58 2010
@@ -59,6 +59,7 @@
    the old ones (CASSANDRA-1644)
  * upgrade to Thrift 0.5 (CASSANDRA-1367)
  * renamed CL.DCQUORUM to LOCAL_QUORUM and DCQUORUMSYNC to EACH_QUORUM
+ * cli truncate support (CASSANDRA-1653)
 
 
 0.7-beta2

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g?rev=1027456&r1=1027455&r2=1027456&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g Tue Oct 26 10:54:58
2010
@@ -55,6 +55,7 @@ tokens {
     NODE_UPDATE_KEYSPACE;
     NODE_UPDATE_COLUMN_FAMILY;
     NODE_LIST;
+    NODE_TRUNCATE;
 
     // Internal Nodes.
     NODE_COLUMN_ACCESS;
@@ -123,6 +124,7 @@ statement
     | setStatement
     | showStatement
     | listStatement
+    | truncateStatement
     | -> ^(NODE_NO_OP)
     ;
 
@@ -174,6 +176,8 @@ helpStatement
         -> ^(NODE_HELP NODE_THRIFT_COUNT)
     | K_HELP K_LIST 
         -> ^(NODE_HELP NODE_LIST)
+    | K_HELP K_TRUNCATE
+        -> ^(NODE_HELP NODE_TRUNCATE)
     | K_HELP 
         -> ^(NODE_HELP)
     | '?'    
@@ -231,6 +235,11 @@ listStatement
         -> ^(NODE_LIST columnFamily keyRangeExpr? ^(NODE_LIMIT $limit)?)
     ;
 
+truncateStatement
+    : K_TRUNCATE columnFamily
+        -> ^(NODE_TRUNCATE columnFamily)
+    ;
+
 showClusterName
     : K_SHOW K_CLUSTER K_NAME 
         -> ^(NODE_SHOW_CLUSTER_NAME)
@@ -430,6 +439,7 @@ K_AND:        'AND';
 K_UPDATE:     'UPDATE';
 K_LIST:       'LIST';
 K_LIMIT:      'LIMIT';
+K_TRUNCATE:   'TRUNCATE';
 
 // private syntactic rules
 fragment

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java?rev=1027456&r1=1027455&r2=1027456&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java Tue
Oct 26 10:54:58 2010
@@ -171,6 +171,9 @@ public class CliClient extends CliUserHe
                 case CliParser.NODE_LIST:
                     executeList(tree);
                     break;
+                case CliParser.NODE_TRUNCATE:
+                    executeTruncate(tree.getChild(0).getText());
+                    break;
                 case CliParser.NODE_NO_OP:
                     // comment lines come here; they are treated as no ops.
                     break;
@@ -943,6 +946,30 @@ public class CliClient extends CliUserHe
         printSliceList(columnFamilyDef, keySlices);
     }
 
+    // TRUNCATE <columnFamily>
+    private void executeTruncate(String columnFamily)
+    {
+        if (!CliMain.isConnected() || !hasKeySpace())
+            return;
+
+        // getting CfDef, it will fail if there is no such column family in current keySpace.

+        CfDef cfDef = getCfDef(columnFamily);
+
+        try
+        {
+            thriftClient.truncate(cfDef.getName());
+            sessionState.out.println(columnFamily + " truncated.");
+        }
+        catch (InvalidRequestException e)
+        {
+            throw new RuntimeException(e.getWhy());
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException(e.getMessage());
+        }
+    }
+
     // SHOW API VERSION
     private void executeShowVersion() throws TException
     {

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliCompleter.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliCompleter.java?rev=1027456&r1=1027455&r2=1027456&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliCompleter.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliCompleter.java Tue
Oct 26 10:54:58 2010
@@ -55,12 +55,16 @@ public class CliCompleter extends Simple
             "help set",
             "help del",
             "help count",
+            "help list",
+            "help truncate"
     };
     private static String[] keyspaceCommands = {
             "get",
             "set",
             "count",
-            "del"
+            "del",
+            "list",
+            "truncate"
     };
 
     public CliCompleter()

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliUserHelp.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliUserHelp.java?rev=1027456&r1=1027455&r2=1027456&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliUserHelp.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliUserHelp.java Tue
Oct 26 10:54:58 2010
@@ -281,6 +281,13 @@ public class CliUserHelp {
                 state.out.println("list Users[j:] limit 40");
                 break;
 
+            case CliParser.NODE_TRUNCATE:
+                state.out.println("truncate <column_family>");
+                state.out.println("Truncate specified column family.\n");
+                state.out.println("example:");
+                state.out.println("truncate Category");
+                break;
+            
             default:
                 state.out.println("?");
                 break;
@@ -324,7 +331,8 @@ public class CliUserHelp {
             state.out.println("del <cf>['<key>']['<super>']['<col>']
                        Delete sub column.");
             state.out.println("count <cf>['<key>']                          
          Count columns in record.");
             state.out.println("count <cf>['<key>']['<super>']         
        Count columns in a super column.");
-            state.out.println("list <cf>                                  List all
rows in the column family.");
+            state.out.println("truncate <column_family>                       Truncate
specified column family.");            
+            state.out.println("list <cf>                                    List all
rows in the column family.");
             state.out.println("list <cf>[<startKey>:]");
             state.out.println("                       List rows in the column family beginning
with <startKey>.");
             state.out.println("list <cf>[<startKey>:<endKey>]");

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/cli/CliTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/cli/CliTest.java?rev=1027456&r1=1027455&r2=1027456&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/cli/CliTest.java (original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/cli/CliTest.java Tue Oct
26 10:54:58 2010
@@ -52,6 +52,7 @@ public class CliTest extends TestCase
         "list CF3[h:]",
         "list CF3 limit 10",
         "list CF3[h:g] limit 10",
+        "truncate CF1",
         "update keyspace TestKeySpace with placement_strategy='org.apache.cassandra.locator.LocalStrategy'",
         "update keyspace TestKeySpace with replication_factor=1 and strategy_options=[{DC1:3,
DC2:4, DC5:1}]"
     };
@@ -101,6 +102,10 @@ public class CliTest extends TestCase
                     assertTrue(result.startsWith("=> (column="));
                 }
             }
+            else if (statement.startsWith("truncate "))
+            {
+                assertTrue(result.contains(" truncated."));
+            }
 
             outStream.reset(); // reset stream so we have only output from next statement
all the time
             errStream.reset(); // no errors to the end user.



Mime
View raw message