cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r1214527 - in /cassandra/trunk/src/java/org/apache/cassandra: service/ClientState.java thrift/CassandraServer.java
Date Wed, 14 Dec 2011 22:55:36 GMT
Author: eevans
Date: Wed Dec 14 22:55:36 2011
New Revision: 1214527

URL: http://svn.apache.org/viewvc?rev=1214527&view=rev
Log:
use an LRU map for storage of prepared statements

Patch by eevans; reviewed by Rick Shaw for CASSANDRA-2475

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/service/ClientState.java
    cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/service/ClientState.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/service/ClientState.java?rev=1214527&r1=1214526&r2=1214527&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/service/ClientState.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/service/ClientState.java Wed Dec 14 22:55:36
2011
@@ -20,6 +20,7 @@ package org.apache.cassandra.service;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -42,6 +43,7 @@ import org.apache.cassandra.thrift.Inval
  */
 public class ClientState
 {
+    private static final int MAX_CACHE_PREPARED = 50;   // Ridiculously large, right?
     private static Logger logger = LoggerFactory.getLogger(ClientState.class);
 
     // Current user for the session
@@ -50,8 +52,12 @@ public class ClientState
     // Reusable array for authorization
     private final List<Object> resource = new ArrayList<Object>();
 
-    // a map of prepared statements index by an integer
-    private Map<Integer,CQLStatement> prepared = new HashMap<Integer,CQLStatement>();
+    // An LRU map of prepared statements
+    private Map<Integer, CQLStatement> prepared = new HashMap<Integer, CQLStatement>()
{
+        protected boolean removeEldestEntry(Map.Entry<Integer, CQLStatement> eldest)
{
+            return size() > MAX_CACHE_PREPARED;
+        }
+    };
 
     private long clock;
 

Modified: cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java?rev=1214527&r1=1214526&r2=1214527&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java Wed Dec 14 22:55:36
2011
@@ -1254,8 +1254,11 @@ public class CassandraServer implements 
         if (logger.isDebugEnabled()) logger.debug("execute_prepared_cql_query");
         
         CQLStatement statement = state().getPrepared().get(itemId);
-        if (logger.isTraceEnabled()) logger.trace("Retreving prepared statement: #"+ itemId
+ " count:"+state().getPrepared().size());
-        
+
+        if (statement == null)
+            throw new InvalidRequestException(String.format("Prepared query with ID %d not
found", itemId));
+        logger.trace("Retrieved prepared statement #{} with {} bind markers", itemId, state().getPrepared().size());
+
         return QueryProcessor.processPrepared(statement, state(), bindVariables);
     }
 



Mime
View raw message