cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [05/10] git commit: Make MS.getBoundTerms() correct for batched statements
Date Wed, 30 Oct 2013 15:18:33 GMT
Make MS.getBoundTerms() correct for batched statements

patch by Aleksey Yeschenko and Sam Tunnicliffe; reviewed by
Sylvain Lebresne


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

Branch: refs/heads/trunk
Commit: 7187a8af05b53d5318f3e4fa47122b232c4c7e52
Parents: 0a38dd5
Author: Aleksey Yeschenko <aleksey@apache.org>
Authored: Wed Oct 30 13:20:47 2013 +0300
Committer: Aleksey Yeschenko <aleksey@apache.org>
Committed: Wed Oct 30 13:20:47 2013 +0300

----------------------------------------------------------------------
 .../apache/cassandra/cql3/VariableSpecifications.java    |  7 +++++++
 .../cassandra/cql3/statements/DeleteStatement.java       |  6 +++---
 .../cassandra/cql3/statements/ModificationStatement.java | 11 ++++++++---
 .../cassandra/cql3/statements/UpdateStatement.java       |  8 ++++----
 4 files changed, 22 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/7187a8af/src/java/org/apache/cassandra/cql3/VariableSpecifications.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/VariableSpecifications.java b/src/java/org/apache/cassandra/cql3/VariableSpecifications.java
index ecdba6f..297999a 100644
--- a/src/java/org/apache/cassandra/cql3/VariableSpecifications.java
+++ b/src/java/org/apache/cassandra/cql3/VariableSpecifications.java
@@ -24,6 +24,7 @@ public class VariableSpecifications
 {
     private final List<ColumnIdentifier> variableNames;
     private final ColumnSpecification[] specs;
+    private int collectedCount;
 
     public VariableSpecifications(List<ColumnIdentifier> variableNames)
     {
@@ -48,5 +49,11 @@ public class VariableSpecifications
         if (name != null)
             spec = new ColumnSpecification(spec.ksName, spec.cfName, name, spec.type);
         specs[bindIndex] = spec;
+        collectedCount++;
+    }
+
+    public int getCollectedCount()
+    {
+        return collectedCount;
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/7187a8af/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java b/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
index 3704e14..4852cf7 100644
--- a/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
@@ -31,9 +31,9 @@ import org.apache.cassandra.utils.Pair;
  */
 public class DeleteStatement extends ModificationStatement
 {
-    private DeleteStatement(int boundTerms, CFMetaData cfm, Attributes attrs)
+    private DeleteStatement(CFMetaData cfm, Attributes attrs)
     {
-        super(boundTerms, cfm, attrs);
+        super(cfm, attrs);
     }
 
     public boolean requireFullClusteringKey()
@@ -105,7 +105,7 @@ public class DeleteStatement extends ModificationStatement
 
         protected ModificationStatement prepareInternal(CFDefinition cfDef, VariableSpecifications
boundNames, Attributes attrs) throws InvalidRequestException
         {
-            DeleteStatement stmt = new DeleteStatement(boundNames.size(), cfDef.cfm, attrs);
+            DeleteStatement stmt = new DeleteStatement(cfDef.cfm, attrs);
 
             for (Operation.RawDeletion deletion : deletions)
             {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/7187a8af/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
index 0f425b8..7aebc48 100644
--- a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
@@ -46,19 +46,18 @@ public abstract class ModificationStatement implements CQLStatement
 {
     private static final ColumnIdentifier CAS_RESULT_COLUMN = new ColumnIdentifier("[applied]",
false);
 
-    private final int boundTerms;
     public final CFMetaData cfm;
     public final Attributes attrs;
 
     private final Map<ColumnIdentifier, Restriction> processedKeys = new HashMap<ColumnIdentifier,
Restriction>();
     private final List<Operation> columnOperations = new ArrayList<Operation>();
 
+    private int boundTerms;
     private List<Operation> columnConditions;
     private boolean ifNotExists;
 
-    public ModificationStatement(int boundTerms, CFMetaData cfm, Attributes attrs)
+    public ModificationStatement(CFMetaData cfm, Attributes attrs)
     {
-        this.boundTerms = boundTerms;
         this.cfm = cfm;
         this.attrs = attrs;
     }
@@ -579,6 +578,10 @@ public abstract class ModificationStatement implements CQLStatement
             CFMetaData metadata = ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
             CFDefinition cfDef = metadata.getCfDef();
 
+            // The collected count in the beginning of preparation.
+            // Will start at non-zero for statements nested inside a BatchStatement (the
second and the further ones).
+            int collected = boundNames.getCollectedCount();
+
             Attributes preparedAttributes = attrs.prepare(keyspace(), columnFamily());
             preparedAttributes.collectMarkerSpecification(boundNames);
 
@@ -634,6 +637,8 @@ public abstract class ModificationStatement implements CQLStatement
                     }
                 }
             }
+
+            stmt.boundTerms = boundNames.getCollectedCount() - collected;
             return stmt;
         }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/7187a8af/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java b/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
index 12348df..a387962 100644
--- a/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
@@ -35,9 +35,9 @@ public class UpdateStatement extends ModificationStatement
 {
     private static final Operation setToEmptyOperation = new Constants.Setter(null, new Constants.Value(ByteBufferUtil.EMPTY_BYTE_BUFFER));
 
-    private UpdateStatement(int boundTerms, CFMetaData cfm, Attributes attrs)
+    private UpdateStatement(CFMetaData cfm, Attributes attrs)
     {
-        super(boundTerms, cfm, attrs);
+        super(cfm, attrs);
     }
 
     public boolean requireFullClusteringKey()
@@ -131,7 +131,7 @@ public class UpdateStatement extends ModificationStatement
 
         protected ModificationStatement prepareInternal(CFDefinition cfDef, VariableSpecifications
boundNames, Attributes attrs) throws InvalidRequestException
         {
-            UpdateStatement stmt = new UpdateStatement(boundNames.size(), cfDef.cfm, attrs);
+            UpdateStatement stmt = new UpdateStatement(cfDef.cfm, attrs);
 
             // Created from an INSERT
             if (stmt.isCounter())
@@ -201,7 +201,7 @@ public class UpdateStatement extends ModificationStatement
 
         protected ModificationStatement prepareInternal(CFDefinition cfDef, VariableSpecifications
boundNames, Attributes attrs) throws InvalidRequestException
         {
-            UpdateStatement stmt = new UpdateStatement(boundNames.size(), cfDef.cfm, attrs);
+            UpdateStatement stmt = new UpdateStatement(cfDef.cfm, attrs);
 
             for (Pair<ColumnIdentifier, Operation.RawUpdate> entry : updates)
             {


Mime
View raw message