cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [3/7] git commit: Fix size computation of prepared statements
Date Mon, 18 Nov 2013 16:34:24 GMT
Fix size computation of prepared statements

patch by slebresne; reviewed by lyubent for CASSANDRA-6369


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

Branch: refs/heads/trunk
Commit: 0ffa5c20af381b697d25f19b7a987fef8fcc2e92
Parents: 34645c3
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Mon Nov 18 17:17:46 2013 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Mon Nov 18 17:17:46 2013 +0100

----------------------------------------------------------------------
 CHANGES.txt                                              |  1 +
 src/java/org/apache/cassandra/cql3/QueryProcessor.java   | 10 +++++++---
 .../apache/cassandra/cql3/statements/BatchStatement.java | 11 +++++++++++
 .../cassandra/cql3/statements/DeleteStatement.java       |  7 +++++++
 .../cassandra/cql3/statements/ModificationStatement.java |  2 +-
 .../cassandra/cql3/statements/SelectStatement.java       |  8 +++++++-
 .../cassandra/cql3/statements/UpdateStatement.java       |  7 +++++++
 7 files changed, 41 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/0ffa5c20/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 29e87d8..d7395a6 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -22,6 +22,7 @@
  * Make CL code for the native protocol match the one in C* 2.0
    (CASSANDRA-6347)
  * Disallow altering CQL3 table from thrift (CASSANDRA-6370)
+ * Fix size computation of prepared statement (CASSANDRA-6369)
 
 
 1.2.11

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0ffa5c20/src/java/org/apache/cassandra/cql3/QueryProcessor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/QueryProcessor.java b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
index 2d43bdc..40b9339 100644
--- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java
+++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
@@ -70,7 +70,7 @@ public class QueryProcessor
     private static final ConcurrentLinkedHashMap<MD5Digest, CQLStatement> preparedStatements;
     private static final ConcurrentLinkedHashMap<Integer, CQLStatement> thriftPreparedStatements;
 
-    static 
+    static
     {
         if (MemoryMeter.isInitialized())
         {
@@ -96,7 +96,6 @@ public class QueryProcessor
         }
     }
 
-
     public static CQLStatement getPrepared(MD5Digest id)
     {
         return preparedStatements.get(id);
@@ -328,6 +327,11 @@ public class QueryProcessor
 
     private static long measure(Object key)
     {
-        return MemoryMeter.isInitialized() ? meter.measureDeep(key) : 1;
+        if (!MemoryMeter.isInitialized())
+            return 1;
+
+        return key instanceof MeasurableForPreparedCache
+             ? ((MeasurableForPreparedCache)key).measureForPreparedCache(meter)
+             : meter.measureDeep(key);
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0ffa5c20/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java b/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java
index f93eb63..d211eb9 100644
--- a/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java
@@ -20,6 +20,8 @@ package org.apache.cassandra.cql3.statements;
 import java.nio.ByteBuffer;
 import java.util.*;
 
+import org.github.jamm.MemoryMeter;
+
 import org.apache.cassandra.auth.Permission;
 import org.apache.cassandra.cql3.*;
 import org.apache.cassandra.db.ConsistencyLevel;
@@ -29,6 +31,7 @@ import org.apache.cassandra.db.RowMutation;
 import org.apache.cassandra.exceptions.*;
 import org.apache.cassandra.service.ClientState;
 import org.apache.cassandra.utils.Pair;
+import org.apache.cassandra.utils.ObjectSizes;
 
 /**
  * A <code>BATCH</code> statement parsed from a CQL query.
@@ -54,6 +57,14 @@ public class BatchStatement extends ModificationStatement
         this.statements = statements;
     }
 
+    public long measureForPreparedCache(MemoryMeter meter)
+    {
+        long size = meter.measure(this) + meter.measure(statements);
+        for (ModificationStatement stmt : statements)
+            size += stmt.measureForPreparedCache(meter);
+        return size;
+    }
+
     @Override
     public void prepareKeyspace(ClientState state) throws InvalidRequestException
     {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0ffa5c20/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 68ae6b8..e05f009 100644
--- a/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
@@ -20,6 +20,8 @@ package org.apache.cassandra.cql3.statements;
 import java.nio.ByteBuffer;
 import java.util.*;
 
+import org.github.jamm.MemoryMeter;
+
 import org.apache.cassandra.cql3.*;
 import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.db.ConsistencyLevel;
@@ -51,6 +53,11 @@ public class DeleteStatement extends ModificationStatement
         this.toRemove = new ArrayList<Operation>(deletions.size());
     }
 
+    public long measureForPreparedCache(MemoryMeter meter)
+    {
+        return meter.measureDeep(this) - meter.measureDeep(cfDef);
+    }
+
     protected void validateConsistency(ConsistencyLevel cl) throws InvalidRequestException
     {
         if (type == Type.COUNTER)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0ffa5c20/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 5ede98f..bfbf511 100644
--- a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
@@ -38,7 +38,7 @@ import org.apache.cassandra.transport.messages.ResultMessage;
 /**
  * Abstract class for statements that apply on a given column family.
  */
-public abstract class ModificationStatement extends CFStatement implements CQLStatement
+public abstract class ModificationStatement extends CFStatement implements CQLStatement,
MeasurableForPreparedCache
 {
     public static enum Type
     {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0ffa5c20/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index c1c88ba..e1537fc 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -24,6 +24,7 @@ import java.util.concurrent.ExecutionException;
 import com.google.common.collect.AbstractIterator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.github.jamm.MemoryMeter;
 
 import org.apache.cassandra.auth.Permission;
 import org.apache.cassandra.cql3.*;
@@ -53,7 +54,7 @@ import org.apache.cassandra.utils.Pair;
  * column family, expression, result count, and ordering clause.
  *
  */
-public class SelectStatement implements CQLStatement
+public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
 {
     private static final Logger logger = LoggerFactory.getLogger(SelectStatement.class);
 
@@ -99,6 +100,11 @@ public class SelectStatement implements CQLStatement
         this.parameters = parameters;
     }
 
+    public long measureForPreparedCache(MemoryMeter meter)
+    {
+        return meter.measureDeep(this) - meter.measureDeep(cfDef);
+    }
+
     public int getBoundsTerms()
     {
         return boundTerms;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0ffa5c20/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 3796173..27e7db9 100644
--- a/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
@@ -20,6 +20,8 @@ package org.apache.cassandra.cql3.statements;
 import java.nio.ByteBuffer;
 import java.util.*;
 
+import org.github.jamm.MemoryMeter;
+
 import org.apache.cassandra.cql3.*;
 import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.db.*;
@@ -95,6 +97,11 @@ public class UpdateStatement extends ModificationStatement
         this.whereClause = null;
     }
 
+    public long measureForPreparedCache(MemoryMeter meter)
+    {
+        return meter.measureDeep(this) - meter.measureDeep(cfDef);
+    }
+
     protected void validateConsistency(ConsistencyLevel cl) throws InvalidRequestException
     {
         if (type == Type.COUNTER)


Mime
View raw message