cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alek...@apache.org
Subject [1/2] git commit: Warn when evicting prepared statements from cache
Date Thu, 18 Sep 2014 23:44:12 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 1a7db7ae0 -> efa8efad4


Warn when evicting prepared statements from cache

patch by Robbie Strickland; reviewed by Aleksey Yeschenko for
CASSANDRA-7930


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

Branch: refs/heads/trunk
Commit: e1bc6b4a4594083b7e875d1a296402981f26e7d0
Parents: aa8964a
Author: Robbie Strickland <rostrickland@gmail.com>
Authored: Thu Sep 18 16:41:49 2014 -0700
Committer: Aleksey Yeschenko <aleksey@apache.org>
Committed: Thu Sep 18 16:41:49 2014 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +-
 .../apache/cassandra/cql3/QueryProcessor.java   | 23 ++++++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/e1bc6b4a/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index e7e1361..527b4e9 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,6 @@
 2.1.1
  * (cqlsh) Add command line option for cqlshrc file path (CASSANDRA-7131)
- * Provide visibility into prepared statements churn (CASSANDRA-7921)
+ * Provide visibility into prepared statements churn (CASSANDRA-7921, CASSANDRA-7930)
  * Invalidate prepared statements when their keyspace or table is
    dropped (CASSANDRA-7566)
  * cassandra-stress: fix support for NetworkTopologyStrategy (CASSANDRA-7945)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e1bc6b4a/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 8744db4..9a09d42 100644
--- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java
+++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
@@ -21,6 +21,8 @@ import java.nio.ByteBuffer;
 import java.util.*;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.primitives.Ints;
@@ -29,8 +31,6 @@ import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
 import com.googlecode.concurrentlinkedhashmap.EntryWeigher;
 import com.googlecode.concurrentlinkedhashmap.EvictionListener;
 import org.antlr.runtime.*;
-import org.apache.cassandra.service.IMigrationListener;
-import org.apache.cassandra.service.MigrationManager;
 import org.github.jamm.MemoryMeter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -41,8 +41,7 @@ import org.apache.cassandra.db.composites.*;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.exceptions.*;
 import org.apache.cassandra.metrics.CQLMetrics;
-import org.apache.cassandra.service.ClientState;
-import org.apache.cassandra.service.QueryState;
+import org.apache.cassandra.service.*;
 import org.apache.cassandra.service.pager.QueryPager;
 import org.apache.cassandra.service.pager.QueryPagers;
 import org.apache.cassandra.thrift.ThriftClientState;
@@ -90,6 +89,8 @@ public class QueryProcessor implements QueryHandler
     @VisibleForTesting
     public static final CQLMetrics metrics = new CQLMetrics();
 
+    private static AtomicInteger lastMinuteEvictionsCount = new AtomicInteger(0);
+
     static
     {
         preparedStatements = new ConcurrentLinkedHashMap.Builder<MD5Digest, ParsedStatement.Prepared>()
@@ -100,6 +101,7 @@ public class QueryProcessor implements QueryHandler
                                  public void onEviction(MD5Digest md5Digest, ParsedStatement.Prepared
prepared)
                                  {
                                      metrics.preparedStatementsEvicted.inc();
+                                     lastMinuteEvictionsCount.incrementAndGet();
                                  }
                              }).build();
 
@@ -111,6 +113,7 @@ public class QueryProcessor implements QueryHandler
                                        public void onEviction(Integer integer, CQLStatement
cqlStatement)
                                        {
                                            metrics.preparedStatementsEvicted.inc();
+                                           lastMinuteEvictionsCount.incrementAndGet();
                                        }
                                    })
                                    .build();
@@ -152,6 +155,18 @@ public class QueryProcessor implements QueryHandler
     private QueryProcessor()
     {
         MigrationManager.instance.register(new MigrationSubscriber());
+
+        StorageService.scheduledTasks.scheduleAtFixedRate(new Runnable()
+        {
+            public void run()
+            {
+                long count = lastMinuteEvictionsCount.getAndSet(0);
+                if (count > 0)
+                    logger.info("{} prepared statements discarded in the last minute because
cache limit reached ({} bytes)",
+                                count,
+                                MAX_CACHE_PREPARED_MEMORY);
+            }
+        }, 1, 1, TimeUnit.MINUTES);
     }
 
     public ParsedStatement.Prepared getPrepared(MD5Digest id)


Mime
View raw message