cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject git commit: Ensures paging changes to native protocol are properly versioned
Date Wed, 26 Jun 2013 15:46:57 GMT
Updated Branches:
  refs/heads/trunk 3ec4ff5ed -> 8c062d807


Ensures paging changes to native protocol are properly versioned


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

Branch: refs/heads/trunk
Commit: 8c062d807e4a4c497dbc9a07c5d256ebf92e80fa
Parents: 3ec4ff5
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Wed Jun 26 17:46:50 2013 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Wed Jun 26 17:46:50 2013 +0200

----------------------------------------------------------------------
 .../transport/messages/ExecuteMessage.java      | 10 ++++-
 .../transport/messages/QueryMessage.java        | 42 +++++++++++---------
 2 files changed, 32 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/8c062d80/src/java/org/apache/cassandra/transport/messages/ExecuteMessage.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/transport/messages/ExecuteMessage.java b/src/java/org/apache/cassandra/transport/messages/ExecuteMessage.java
index 7c35e42..2d6b67b 100644
--- a/src/java/org/apache/cassandra/transport/messages/ExecuteMessage.java
+++ b/src/java/org/apache/cassandra/transport/messages/ExecuteMessage.java
@@ -50,7 +50,10 @@ public class ExecuteMessage extends Message.Request
                 values.add(CBUtil.readValue(body));
 
             ConsistencyLevel consistency = CBUtil.readConsistencyLevel(body);
-            int resultPageSize = body.readInt();
+
+            int resultPageSize = -1;
+            if (version >= 2)
+                resultPageSize = body.readInt();
             return new ExecuteMessage(id, values, consistency, resultPageSize);
         }
 
@@ -71,7 +74,10 @@ public class ExecuteMessage extends Message.Request
                 builder.addValue(value);
 
             builder.add(CBUtil.consistencyLevelToCB(msg.consistency));
-            builder.add(CBUtil.intToCB(msg.resultPageSize));
+
+            assert msg.resultPageSize == -1 || version >= 2;
+            if (version >= 2)
+                builder.add(CBUtil.intToCB(msg.resultPageSize));
             return builder.build();
         }
     };

http://git-wip-us.apache.org/repos/asf/cassandra/blob/8c062d80/src/java/org/apache/cassandra/transport/messages/QueryMessage.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/transport/messages/QueryMessage.java b/src/java/org/apache/cassandra/transport/messages/QueryMessage.java
index 860c404..1ec556c 100644
--- a/src/java/org/apache/cassandra/transport/messages/QueryMessage.java
+++ b/src/java/org/apache/cassandra/transport/messages/QueryMessage.java
@@ -45,18 +45,20 @@ public class QueryMessage extends Message.Request
         {
             String query = CBUtil.readLongString(body);
             ConsistencyLevel consistency = CBUtil.readConsistencyLevel(body);
-            int resultPageSize = body.readInt();
-            List<ByteBuffer> values;
-            if (body.readable())
-            {
-                int paramCount = body.readUnsignedShort();
-                values = paramCount == 0 ? Collections.<ByteBuffer>emptyList() : new
ArrayList<ByteBuffer>(paramCount);
-                for (int i = 0; i < paramCount; i++)
-                     values.add(CBUtil.readValue(body));
-            }
-            else
+
+            int resultPageSize = -1;
+            List<ByteBuffer> values = Collections.emptyList();
+
+            if (version >= 2)
             {
-                values = Collections.emptyList();
+                resultPageSize = body.readInt();
+                if (body.readable())
+                {
+                    int paramCount = body.readUnsignedShort();
+                    values = paramCount == 0 ? Collections.<ByteBuffer>emptyList()
: new ArrayList<ByteBuffer>(paramCount);
+                    for (int i = 0; i < paramCount; i++)
+                        values.add(CBUtil.readValue(body));
+                }
             }
             return new QueryMessage(query, values, consistency, resultPageSize);
         }
@@ -70,16 +72,20 @@ public class QueryMessage extends Message.Request
             //   - Number of values
             //   - The values
             int vs = msg.values.size();
-            CBUtil.BufferBuilder builder = new CBUtil.BufferBuilder(3 + (vs > 0 ? 1 :
0), 0, vs);
+            assert (msg.resultPageSize == -1 && vs == 0) || version >= 2 : "Version
1 of the protocol support neither a page size nor values";
+
+            CBUtil.BufferBuilder builder = new CBUtil.BufferBuilder(2 + (version == 1 ? 0
: 1 + (vs > 0 ? 1 : 0)), 0, vs);
             builder.add(CBUtil.longStringToCB(msg.query));
             builder.add(CBUtil.consistencyLevelToCB(msg.consistency));
-            builder.add(CBUtil.intToCB(msg.resultPageSize));
-            if (vs > 0)
+            if (version >= 2)
             {
-                assert version > 1 : "Version 1 of the protocol do not allow values";
-                builder.add(CBUtil.shortToCB(vs));
-                for (ByteBuffer value : msg.values)
-                    builder.addValue(value);
+                builder.add(CBUtil.intToCB(msg.resultPageSize));
+                if (vs > 0)
+                {
+                    builder.add(CBUtil.shortToCB(vs));
+                    for (ByteBuffer value : msg.values)
+                        builder.addValue(value);
+                }
             }
             return builder.build();
         }


Mime
View raw message