cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1102352 - in /cassandra/branches/cassandra-0.7: ./ src/java/org/apache/cassandra/cli/ src/java/org/apache/cassandra/net/ src/java/org/apache/cassandra/service/ test/unit/org/apache/cassandra/cli/
Date Thu, 12 May 2011 15:31:01 GMT
Author: jbellis
Date: Thu May 12 15:31:01 2011
New Revision: 1102352

URL: http://svn.apache.org/viewvc?rev=1102352&view=rev
Log:
add quote-escaping via backslash to CLI
patch by pyaskevich; reviewed by jbellis for CASSANDRA-2623

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/net/MessagingService.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/AbstractRowResolver.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/DatacenterReadCallback.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/IResponseResolver.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/RangeSliceResponseResolver.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/ReadCallback.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=1102352&r1=1102351&r2=1102352&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.7/CHANGES.txt Thu May 12 15:31:01 2011
@@ -23,6 +23,7 @@
  * fix counting bloom filter true positives (CASSANDRA-2637)
  * initialize local ep state prior to gossip startup if needed (CASSANDRA-2638)
  * fix empty Result with secondary index when limit=1 (CASSANDRA-2628)
+ * add quote-escaping via backslash to CLI (CASSANDRA-2623)
 
 
 0.7.5

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=1102352&r1=1102351&r2=1102352&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 Thu May 12 15:31:01
2011
@@ -581,10 +581,57 @@ Identifier
 
 // literals
 StringLiteral
-    :
-    '\'' (~'\'')* '\'' ( '\'' (~'\'')* '\'' )*
+    : '\'' SingleStringCharacter* '\''
     ;
 
+fragment SingleStringCharacter
+	: ~('\'' | '\\')
+	| '\\' EscapeSequence
+	;
+
+fragment EscapeSequence
+	: CharacterEscapeSequence
+	| '0'
+	| HexEscapeSequence
+	| UnicodeEscapeSequence
+	;
+
+fragment CharacterEscapeSequence
+	: SingleEscapeCharacter
+	| NonEscapeCharacter
+	;
+
+fragment NonEscapeCharacter
+	: ~(EscapeCharacter)
+	;
+
+fragment SingleEscapeCharacter
+	: '\'' | '"' | '\\' | 'b' | 'f' | 'n' | 'r' | 't' | 'v'
+	;
+
+fragment EscapeCharacter
+	: SingleEscapeCharacter
+	| DecimalDigit
+	| 'x'
+	| 'u'
+	;
+
+fragment HexEscapeSequence
+	: 'x' HexDigit HexDigit
+	;
+
+fragment UnicodeEscapeSequence
+	: 'u' HexDigit HexDigit HexDigit HexDigit
+	;
+
+fragment HexDigit
+	: DecimalDigit | ('a'..'f') | ('A'..'F')
+	;
+
+fragment DecimalDigit
+	: ('0'..'9')
+	;
+
 //
 // syntactic elements
 //

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/net/MessagingService.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/net/MessagingService.java?rev=1102352&r1=1102351&r2=1102352&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/net/MessagingService.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/net/MessagingService.java
Thu May 12 15:31:01 2011
@@ -259,6 +259,7 @@ public final class MessagingService impl
     public String sendRR(Message message, InetAddress to, IMessageCallback cb)
     {        
         String id = nextId();
+        logger_.debug("Message id to {} is {}", to, id);
         addCallback(cb, id, to);
         sendOneWay(message, id, to);
         return id;
@@ -266,7 +267,9 @@ public final class MessagingService impl
 
     public void sendOneWay(Message message, InetAddress to)
     {
-        sendOneWay(message, nextId(), to);
+        String id = nextId();
+        logger_.debug("Message id to {} is {}", to, id);
+        sendOneWay(message, id, to);
     }
 
     public void sendReply(Message message, String id, InetAddress to)

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/AbstractRowResolver.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/AbstractRowResolver.java?rev=1102352&r1=1102351&r2=1102352&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/AbstractRowResolver.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/AbstractRowResolver.java
Thu May 12 15:31:01 2011
@@ -55,16 +55,15 @@ public abstract class AbstractRowResolve
         this.table = table;
     }
 
-    public void preprocess(Message message)
+    public ReadResponse preprocess(Message message)
     {
         byte[] body = message.getMessageBody();
         ByteArrayInputStream bufIn = new ByteArrayInputStream(body);
         try
         {
             ReadResponse result = ReadResponse.serializer().deserialize(new DataInputStream(bufIn));
-            if (logger.isDebugEnabled())
-                logger.debug("Preprocessed {} response", result.isDigestQuery() ? "digest"
: "data");
             replies.put(message, result);
+            return result;
         }
         catch (IOException e)
         {

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/DatacenterReadCallback.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/DatacenterReadCallback.java?rev=1102352&r1=1102351&r2=1102352&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/DatacenterReadCallback.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/DatacenterReadCallback.java
Thu May 12 15:31:01 2011
@@ -48,17 +48,11 @@ public class DatacenterReadCallback<T> e
     }
 
     @Override
-    protected boolean waitingFor(Message message)
-    {
-        return localdc.equals(snitch.getDatacenter(message.getFrom()));
-    }
-
-    @Override
-    protected boolean waitingFor(ReadResponse response)
+    protected boolean waitingFor(ReadResponse response, InetAddress from)
     {
         // cheat and leverage our knowledge that a local read is the only way the ReadResponse
         // version of this method gets called
-        return true;
+        return localdc.equals(snitch.getDatacenter(from));
     }
     
     @Override

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/IResponseResolver.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/IResponseResolver.java?rev=1102352&r1=1102351&r2=1102352&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/IResponseResolver.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/IResponseResolver.java
Thu May 12 15:31:01 2011
@@ -20,6 +20,7 @@ package org.apache.cassandra.service;
 
 import java.io.IOException;
 
+import org.apache.cassandra.db.ReadResponse;
 import org.apache.cassandra.net.Message;
 
 public interface IResponseResolver<T> {
@@ -41,6 +42,6 @@ public interface IResponseResolver<T> {
      */
     public T getData() throws IOException;
 
-    public void preprocess(Message message);
+    public ReadResponse preprocess(Message message);
     public Iterable<Message> getMessages();
 }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/RangeSliceResponseResolver.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/RangeSliceResponseResolver.java?rev=1102352&r1=1102351&r2=1102352&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/RangeSliceResponseResolver.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/RangeSliceResponseResolver.java
Thu May 12 15:31:01 2011
@@ -24,16 +24,11 @@ import java.util.*;
 import java.util.concurrent.LinkedBlockingQueue;
 
 import com.google.common.collect.AbstractIterator;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Iterators;
 import org.apache.commons.collections.iterators.CollatingIterator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.cassandra.db.ColumnFamily;
-import org.apache.cassandra.db.DecoratedKey;
-import org.apache.cassandra.db.RangeSliceReply;
-import org.apache.cassandra.db.Row;
+import org.apache.cassandra.db.*;
 import org.apache.cassandra.net.Message;
 import org.apache.cassandra.utils.Pair;
 import org.apache.cassandra.utils.ReducingIterator;
@@ -114,7 +109,7 @@ public class RangeSliceResponseResolver 
         };
     }
 
-    public void preprocess(Message message)
+    public ReadResponse preprocess(Message message)
     {
         responses.add(message);
     }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/ReadCallback.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/ReadCallback.java?rev=1102352&r1=1102351&r2=1102352&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/ReadCallback.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/ReadCallback.java
Thu May 12 15:31:01 2011
@@ -42,6 +42,7 @@ import org.apache.cassandra.net.Message;
 import org.apache.cassandra.net.MessagingService;
 import org.apache.cassandra.thrift.ConsistencyLevel;
 import org.apache.cassandra.thrift.UnavailableException;
+import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.SimpleCondition;
 import org.apache.cassandra.utils.WrappedRunnable;
 
@@ -127,10 +128,13 @@ public class ReadCallback<T> implements 
 
     public void response(Message message)
     {
-        resolver.preprocess(message);
-        int n = waitingFor(message)
+        ReadResponse result = resolver.preprocess(message);
+        int n = waitingFor(result, message.getFrom())
               ? received.incrementAndGet()
               : received.get();
+        if (logger.isDebugEnabled())
+            logger.debug("{} response; {} qualifying responses seen.  Data is {}present",
+                         new Object[] { result.isDigestQuery() ? "digest" : "data", n, resolver.isDataPresent()
? "" : "not " });
         if (n >= blockfor && resolver.isDataPresent())
         {
             condition.signal();
@@ -139,18 +143,9 @@ public class ReadCallback<T> implements 
     }
 
     /**
-     * @return true if the message counts towards the blockfor threshold
-     * TODO turn the Message into a response so we don't need two versions of this method
-     */
-    protected boolean waitingFor(Message message)
-    {
-        return true;
-    }
-
-    /**
      * @return true if the response counts towards the blockfor threshold
      */
-    protected boolean waitingFor(ReadResponse response)
+    protected boolean waitingFor(ReadResponse response, InetAddress from)
     {
         return true;
     }
@@ -158,7 +153,9 @@ public class ReadCallback<T> implements 
     public void response(ReadResponse result)
     {
         ((RowDigestResolver) resolver).injectPreProcessed(result);
-        int n = waitingFor(result)
+        if (logger.isDebugEnabled())
+            logger.debug("Preprocessed {} response", result.isDigestQuery() ? "digest" :
"data");
+        int n = waitingFor(result, FBUtilities.getLocalAddress())
               ? received.incrementAndGet()
               : received.get();
         if (n >= blockfor && resolver.isDataPresent())

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=1102352&r1=1102351&r2=1102352&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 Thu May
12 15:31:01 2011
@@ -39,9 +39,14 @@ public class CliTest extends CleanupHelp
         "use TestKeySpace;",
         "create column family CF1 with comparator=UTF8Type and column_metadata=[{ column_name:world,
validation_class:IntegerType, index_type:0, index_name:IdxName }, { column_name:world2, validation_class:LongType,
index_type:KEYS, index_name:LongIdxName}];",
         "set CF1[hello][world] = 123848374878933948398384;",
+        "set CF1[hello][test_quote] = 'value\\'';",
+        "set CF1['k\\'ey'][VALUE] = 'VAL';",
+        "set CF1['k\\'ey'][VALUE] = 'VAL\\'';",
         "set CF1[hello][-31337] = 'some string value';",
         "get CF1[hello][-31337];",
         "get CF1[hello][world];",
+        "get CF1[hello][test_quote];",
+        "get CF1['k\\'ey'][VALUE]",
         "set CF1[hello][-31337] = -23876;",
         "set CF1[hello][-31337] = long(-23876);",
         "set CF1[hello][world2] = 15;",



Mime
View raw message