You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ty...@apache.org on 2014/09/16 21:10:06 UTC

[1/2] git commit: Revert "Metrics for prepared stmt usage and eviction"

Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 681c380b5 -> b319b406b


Revert "Metrics for prepared stmt usage and eviction"

This reverts commit 19c6cc1982d2146a99ccaf6dccc087fe88d5785f.


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

Branch: refs/heads/cassandra-2.1
Commit: f19b4cb807d30cc7fdb1869c407ee9a5e9e3acce
Parents: 19c6cc1
Author: Tyler Hobbs <ty...@datastax.com>
Authored: Tue Sep 16 13:58:56 2014 -0500
Committer: Tyler Hobbs <ty...@datastax.com>
Committed: Tue Sep 16 13:58:56 2014 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 -
 .../apache/cassandra/cql3/QueryProcessor.java   | 47 +----------------
 .../cassandra/metrics/CqlStatementMetrics.java  | 54 --------------------
 .../apache/cassandra/service/ClientState.java   |  2 +-
 4 files changed, 3 insertions(+), 101 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f19b4cb8/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index cf7112c..3ee938a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,4 @@
 2.0.11:
- * Add metrics for prepared statement usage and eviction (CASSANDRA-7930)
  * Make CQLSSTableWriter sync within partitions (CASSANDRA-7360)
  * Potentially use non-local replicas in CqlConfigHelper (CASSANDRA-7906)
  * Explicitly disallowing mixing multi-column and single-column

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f19b4cb8/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 ee188a3..a59fe9b 100644
--- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java
+++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
@@ -19,14 +19,11 @@ package org.apache.cassandra.cql3;
 
 import java.nio.ByteBuffer;
 import java.util.*;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
 
 import com.google.common.primitives.Ints;
 
 import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
 import com.googlecode.concurrentlinkedhashmap.EntryWeigher;
-import com.googlecode.concurrentlinkedhashmap.EvictionListener;
 import org.antlr.runtime.*;
 import org.github.jamm.MemoryMeter;
 import org.slf4j.Logger;
@@ -35,10 +32,8 @@ import org.slf4j.LoggerFactory;
 import org.apache.cassandra.cql3.statements.*;
 import org.apache.cassandra.db.*;
 import org.apache.cassandra.exceptions.*;
-import org.apache.cassandra.metrics.CqlStatementMetrics;
 import org.apache.cassandra.service.ClientState;
 import org.apache.cassandra.service.QueryState;
-import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.thrift.ThriftClientState;
 import org.apache.cassandra.tracing.Tracing;
 import org.apache.cassandra.transport.messages.ResultMessage;
@@ -78,9 +73,6 @@ public class QueryProcessor implements QueryHandler
     private static final ConcurrentLinkedHashMap<MD5Digest, CQLStatement> preparedStatements;
     private static final ConcurrentLinkedHashMap<Integer, CQLStatement> thriftPreparedStatements;
 
-    public static final CqlStatementMetrics metrics = new CqlStatementMetrics();
-    private static AtomicLong evictionCount = new AtomicLong(0);
-
     static
     {
         if (MemoryMeter.isInitialized())
@@ -88,29 +80,11 @@ public class QueryProcessor implements QueryHandler
             preparedStatements = new ConcurrentLinkedHashMap.Builder<MD5Digest, CQLStatement>()
                                  .maximumWeightedCapacity(MAX_CACHE_PREPARED_MEMORY)
                                  .weigher(cqlMemoryUsageWeigher)
-                                 .listener(new EvictionListener<MD5Digest, CQLStatement>()
-                                  {
-                                      @Override
-                                      public void onEviction(MD5Digest md5Digest, CQLStatement prepared)
-                                      {
-                                          metrics.activePreparedStatements.dec();
-                                          metrics.evictedPreparedStatements.inc();
-                                          evictionCount.incrementAndGet();
-                                      }
-                                  }).build();
+                                 .build();
             thriftPreparedStatements = new ConcurrentLinkedHashMap.Builder<Integer, CQLStatement>()
                                        .maximumWeightedCapacity(MAX_CACHE_PREPARED_MEMORY)
                                        .weigher(thriftMemoryUsageWeigher)
-                                       .listener(new EvictionListener<Integer, CQLStatement>()
-                                        {
-                                            @Override
-                                            public void onEviction(Integer i, CQLStatement prepared)
-                                            {
-                                                metrics.activePreparedStatements.dec();
-                                                metrics.evictedPreparedStatements.inc();
-                                                evictionCount.incrementAndGet();
-                                            }
-                                        }).build();
+                                       .build();
         }
         else
         {
@@ -123,17 +97,6 @@ public class QueryProcessor implements QueryHandler
                                        .maximumWeightedCapacity(MAX_CACHE_PREPARED_COUNT)
                                        .build();
         }
-
-        StorageService.scheduledTasks.scheduleAtFixedRate(new Runnable() {
-            @Override
-            public void run() {
-                long count = evictionCount.getAndSet(0);
-                if (count > 0)
-                {
-                    logger.info("{} prepared statements discarded in the last minute because cache limit reached (cache limit = {} bytes)", count, MAX_CACHE_PREPARED_MEMORY);
-                }
-            }
-        }, 1, 1, TimeUnit.MINUTES);
     }
 
     private QueryProcessor()
@@ -209,9 +172,6 @@ public class QueryProcessor implements QueryHandler
         if (prepared.getBoundTerms() != options.getValues().size())
             throw new InvalidRequestException("Invalid amount of bind variables");
 
-        if (!queryState.getClientState().isInternal)
-            metrics.executedUnprepared.inc();
-
         return processStatement(prepared, queryState, options);
     }
 
@@ -311,7 +271,6 @@ public class QueryProcessor implements QueryHandler
         {
             int statementId = toHash.hashCode();
             thriftPreparedStatements.put(statementId, prepared.statement);
-            metrics.activePreparedStatements.inc();
             logger.trace(String.format("Stored prepared statement #%d with %d bind markers",
                                        statementId,
                                        prepared.statement.getBoundTerms()));
@@ -321,7 +280,6 @@ public class QueryProcessor implements QueryHandler
         {
             MD5Digest statementId = MD5Digest.compute(toHash);
             preparedStatements.put(statementId, prepared.statement);
-            metrics.activePreparedStatements.inc();
             logger.trace(String.format("Stored prepared statement %s with %d bind markers",
                                        statementId,
                                        prepared.statement.getBoundTerms()));
@@ -348,7 +306,6 @@ public class QueryProcessor implements QueryHandler
                     logger.trace("[{}] '{}'", i+1, variables.get(i));
         }
 
-        metrics.executedPrepared.inc();
         return processStatement(statement, queryState, options);
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f19b4cb8/src/java/org/apache/cassandra/metrics/CqlStatementMetrics.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/metrics/CqlStatementMetrics.java b/src/java/org/apache/cassandra/metrics/CqlStatementMetrics.java
deleted file mode 100644
index ba27d89..0000000
--- a/src/java/org/apache/cassandra/metrics/CqlStatementMetrics.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.cassandra.metrics;
-
-import com.yammer.metrics.Metrics;
-import com.yammer.metrics.core.Counter;
-import com.yammer.metrics.core.Gauge;
-import com.yammer.metrics.util.RatioGauge;
-
-
-public class CqlStatementMetrics
-{
-    private final MetricNameFactory factory = new DefaultNameFactory("CqlStatement");
-    public final Counter activePreparedStatements = Metrics.newCounter(factory.createMetricName("ActivePreparedStatements"));
-    public final Counter evictedPreparedStatements = Metrics.newCounter(factory.createMetricName("EvictedPreparedStatements"));
-    public final Counter executedPrepared = Metrics.newCounter(factory.createMetricName("ExecutedPrepared"));
-    public final Counter executedUnprepared = Metrics.newCounter(factory.createMetricName("ExecutedUnPrepared"));
-
-    public final Gauge<Double> preparedRatio = Metrics.newGauge(factory.createMetricName("PreparedUnpreparedRatio"), new RatioGauge()
-    {
-        protected double getNumerator()
-        {
-            long num = executedPrepared.count();
-            return num == 0 ? 1 : num;
-        }
-
-        protected double getDenominator()
-        {
-            long den = executedUnprepared.count();
-            return den == 0 ? 1 : den;
-        }
-    });
-
-    public void reset()
-    {
-        executedPrepared.clear();
-        executedUnprepared.clear();
-    }
-}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f19b4cb8/src/java/org/apache/cassandra/service/ClientState.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/ClientState.java b/src/java/org/apache/cassandra/service/ClientState.java
index c14540d..be3b895 100644
--- a/src/java/org/apache/cassandra/service/ClientState.java
+++ b/src/java/org/apache/cassandra/service/ClientState.java
@@ -102,7 +102,7 @@ public class ClientState
 
     // isInternal is used to mark ClientState as used by some internal component
     // that should have an ability to modify system keyspace.
-    public final boolean isInternal;
+    private final boolean isInternal;
 
     // The remote address of the client - null for internal clients.
     private final SocketAddress remoteAddress;


[2/2] git commit: Merge branch 'cassandra-2.0' into cassandra-2.1

Posted by ty...@apache.org.
Merge branch 'cassandra-2.0' into cassandra-2.1

Conflicts:
	CHANGES.txt
	src/java/org/apache/cassandra/cql3/QueryProcessor.java


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

Branch: refs/heads/cassandra-2.1
Commit: b319b406b9ff69fb64e696627f65b443431d1d64
Parents: 681c380 f19b4cb
Author: Tyler Hobbs <ty...@datastax.com>
Authored: Tue Sep 16 14:09:45 2014 -0500
Committer: Tyler Hobbs <ty...@datastax.com>
Committed: Tue Sep 16 14:09:45 2014 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 -
 .../apache/cassandra/cql3/QueryProcessor.java   | 53 +++++++-------------
 .../cassandra/metrics/CqlStatementMetrics.java  |  1 -
 3 files changed, 19 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/b319b406/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index 0abc66a,3ee938a..f89cc6d
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -1,93 -1,9 +1,92 @@@
 -2.0.11:
 +2.1.1
 + * Fix saving caches when a table is dropped (CASSANDRA-7784)
 + * Add better error checking of new stress profile (CASSANDRA-7716)
 + * Use ThreadLocalRandom and remove FBUtilities.threadLocalRandom (CASSANDRA-7934)
 + * Prevent operator mistakes due to simultaneous bootstrap (CASSANDRA-7069)
 + * cassandra-stress supports whitelist mode for node config (CASSANDRA-7658)
 + * GCInspector more closely tracks GC; cassandra-stress and nodetool report it (CASSANDRA-7916)
 + * nodetool won't output bogus ownership info without a keyspace (CASSANDRA-7173)
 + * Add human readable option to nodetool commands (CASSANDRA-5433)
 + * Don't try to set repairedAt on old sstables (CASSANDRA-7913)
 + * Add metrics for tracking PreparedStatement use (CASSANDRA-7719)
 + * (cqlsh) tab-completion for triggers (CASSANDRA-7824)
 + * (cqlsh) Support for query paging (CASSANDRA-7514)
 + * (cqlsh) Show progress of COPY operations (CASSANDRA-7789)
 + * Add syntax to remove multiple elements from a map (CASSANDRA-6599)
 + * Support non-equals conditions in lightweight transactions (CASSANDRA-6839)
 + * Add IF [NOT] EXISTS to create/drop triggers (CASSANDRA-7606)
 + * (cqlsh) Display the current logged-in user (CASSANDRA-7785)
 + * (cqlsh) Don't ignore CTRL-C during COPY FROM execution (CASSANDRA-7815)
 + * (cqlsh) Order UDTs according to cross-type dependencies in DESCRIBE
 +   output (CASSANDRA-7659)
 + * (cqlsh) Fix handling of CAS statement results (CASSANDRA-7671)
 + * (cqlsh) COPY TO/FROM improvements (CASSANDRA-7405)
 + * Support list index operations with conditions (CASSANDRA-7499)
 + * Add max live/tombstoned cells to nodetool cfstats output (CASSANDRA-7731)
 + * Validate IPv6 wildcard addresses properly (CASSANDRA-7680)
 + * (cqlsh) Error when tracing query (CASSANDRA-7613)
 + * Avoid IOOBE when building SyntaxError message snippet (CASSANDRA-7569)
 + * SSTableExport uses correct validator to create string representation of partition
 +   keys (CASSANDRA-7498)
 + * Avoid NPEs when receiving type changes for an unknown keyspace (CASSANDRA-7689)
 + * Add support for custom 2i validation (CASSANDRA-7575)
 + * Pig support for hadoop CqlInputFormat (CASSANDRA-6454)
 + * Add listen_interface and rpc_interface options (CASSANDRA-7417)
 + * Improve schema merge performance (CASSANDRA-7444)
 + * Adjust MT depth based on # of partition validating (CASSANDRA-5263)
 + * Optimise NativeCell comparisons (CASSANDRA-6755)
 + * Configurable client timeout for cqlsh (CASSANDRA-7516)
 + * Include snippet of CQL query near syntax error in messages (CASSANDRA-7111)
 +Merged from 2.0:
-  * Add metrics for prepared statement usage and eviction (CASSANDRA-7930)
   * Make CQLSSTableWriter sync within partitions (CASSANDRA-7360)
   * Potentially use non-local replicas in CqlConfigHelper (CASSANDRA-7906)
 - * Explicitly disallowing mixing multi-column and single-column
 + * Explicitly disallow mixing multi-column and single-column
     relations on clustering columns (CASSANDRA-7711)
   * Better error message when condition is set on PK column (CASSANDRA-7804)
 + * Don't send schema change responses and events for no-op DDL
 +   statements (CASSANDRA-7600)
 + * (Hadoop) fix cluster initialisation for a split fetching (CASSANDRA-7774)
 + * Throw InvalidRequestException when queries contain relations on entire
 +   collection columns (CASSANDRA-7506)
 + * (cqlsh) enable CTRL-R history search with libedit (CASSANDRA-7577)
 + * (Hadoop) allow ACFRW to limit nodes to local DC (CASSANDRA-7252)
 + * (cqlsh) cqlsh should automatically disable tracing when selecting
 +   from system_traces (CASSANDRA-7641)
 + * (Hadoop) Add CqlOutputFormat (CASSANDRA-6927)
 + * Don't depend on cassandra config for nodetool ring (CASSANDRA-7508)
 + * (cqlsh) Fix failing cqlsh formatting tests (CASSANDRA-7703)
 + * Fix IncompatibleClassChangeError from hadoop2 (CASSANDRA-7229)
 + * Add 'nodetool sethintedhandoffthrottlekb' (CASSANDRA-7635)
 + * (cqlsh) Add tab-completion for CREATE/DROP USER IF [NOT] EXISTS (CASSANDRA-7611)
 + * Catch errors when the JVM pulls the rug out from GCInspector (CASSANDRA-5345)
 + * cqlsh fails when version number parts are not int (CASSANDRA-7524)
 +Merged from 1.2:
 + * Don't index tombstones (CASSANDRA-7828)
 + * Improve PasswordAuthenticator default super user setup (CASSANDRA-7788)
 +
 +
 +2.1.0
 + * (cqlsh) Removed "ALTER TYPE <name> RENAME TO <name>" from tab-completion
 +   (CASSANDRA-7895)
 + * Fixed IllegalStateException in anticompaction (CASSANDRA-7892)
 + * cqlsh: DESCRIBE support for frozen UDTs, tuples (CASSANDRA-7863)
 + * Avoid exposing internal classes over JMX (CASSANDRA-7879)
 + * Add null check for keys when freezing collection (CASSANDRA-7869)
 + * Improve stress workload realism (CASSANDRA-7519)
 +
 +
 +2.1.0-rc7
 + * Add frozen keyword and require UDT to be frozen (CASSANDRA-7857)
 + * Track added sstable size correctly (CASSANDRA-7239)
 + * (cqlsh) Fix case insensitivity (CASSANDRA-7834)
 + * Fix failure to stream ranges when moving (CASSANDRA-7836)
 + * Correctly remove tmplink files (CASSANDRA-7803)
 + * (cqlsh) Fix column name formatting for functions, CAS operations,
 +   and UDT field selections (CASSANDRA-7806)
 + * (cqlsh) Fix COPY FROM handling of null/empty primary key
 +   values (CASSANDRA-7792)
 + * Fix ordering of static cells (CASSANDRA-7763)
 +Merged from 2.0:
   * Forbid re-adding dropped counter columns (CASSANDRA-7831)
   * Fix CFMetaData#isThriftCompatible() for PK-only tables (CASSANDRA-7832)
   * Always reject inequality on the partition key without token()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b319b406/src/java/org/apache/cassandra/cql3/QueryProcessor.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/cql3/QueryProcessor.java
index c983d72,a59fe9b..a5be108
--- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java
+++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
@@@ -19,34 -19,21 +19,30 @@@ package org.apache.cassandra.cql3
  
  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.AtomicLong;
  
 +import com.google.common.annotations.VisibleForTesting;
  import com.google.common.primitives.Ints;
  
  import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
  import com.googlecode.concurrentlinkedhashmap.EntryWeigher;
 +import com.googlecode.concurrentlinkedhashmap.EvictionListener;
  import org.antlr.runtime.*;
- import org.apache.cassandra.metrics.CqlStatementMetrics;
  import org.github.jamm.MemoryMeter;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import org.apache.cassandra.cql3.statements.*;
  import org.apache.cassandra.db.*;
 +import org.apache.cassandra.db.composites.*;
 +import org.apache.cassandra.db.marshal.AbstractType;
  import org.apache.cassandra.exceptions.*;
 +import org.apache.cassandra.metrics.CqlStatementMetrics;
  import org.apache.cassandra.service.ClientState;
  import org.apache.cassandra.service.QueryState;
 +import org.apache.cassandra.service.pager.QueryPager;
 +import org.apache.cassandra.service.pager.QueryPagers;
- import org.apache.cassandra.service.StorageService;
  import org.apache.cassandra.thrift.ThriftClientState;
  import org.apache.cassandra.tracing.Tracing;
  import org.apache.cassandra.transport.messages.ResultMessage;
@@@ -82,79 -70,32 +78,64 @@@ public class QueryProcessor implements 
          }
      };
  
 -    private static final ConcurrentLinkedHashMap<MD5Digest, CQLStatement> preparedStatements;
 +    private static final ConcurrentLinkedHashMap<MD5Digest, ParsedStatement.Prepared> preparedStatements;
      private static final ConcurrentLinkedHashMap<Integer, CQLStatement> thriftPreparedStatements;
  
 +    // A map for prepared statements used internally (which we don't want to mix with user statement, in particular we don't
 +    // bother with expiration on those.
 +    private static final ConcurrentMap<String, ParsedStatement.Prepared> internalStatements = new ConcurrentHashMap<>();
 +
 +    @VisibleForTesting
 +    public static final CqlStatementMetrics metrics = new CqlStatementMetrics();
-     private static AtomicLong evictionCount = new AtomicLong(0);
 +
      static
      {
 -        if (MemoryMeter.isInitialized())
 -        {
 -            preparedStatements = new ConcurrentLinkedHashMap.Builder<MD5Digest, CQLStatement>()
 -                                 .maximumWeightedCapacity(MAX_CACHE_PREPARED_MEMORY)
 -                                 .weigher(cqlMemoryUsageWeigher)
 -                                 .build();
 -            thriftPreparedStatements = new ConcurrentLinkedHashMap.Builder<Integer, CQLStatement>()
 -                                       .maximumWeightedCapacity(MAX_CACHE_PREPARED_MEMORY)
 -                                       .weigher(thriftMemoryUsageWeigher)
 -                                       .build();
 -        }
 -        else
 +        preparedStatements = new ConcurrentLinkedHashMap.Builder<MD5Digest, ParsedStatement.Prepared>()
 +                             .maximumWeightedCapacity(MAX_CACHE_PREPARED_MEMORY)
 +                             .weigher(cqlMemoryUsageWeigher)
 +                             .listener(new EvictionListener<MD5Digest, ParsedStatement.Prepared>()
 +                             {
 +                                 @Override
 +                                 public void onEviction(MD5Digest md5Digest, ParsedStatement.Prepared prepared)
 +                                 {
 +                                     metrics.activePreparedStatements.dec();
-                                      metrics.evictedPreparedStatements.inc();
-                                      evictionCount.incrementAndGet();
 +                                 }
 +                             }).build();
 +
 +        thriftPreparedStatements = new ConcurrentLinkedHashMap.Builder<Integer, CQLStatement>()
 +                                   .maximumWeightedCapacity(MAX_CACHE_PREPARED_MEMORY)
 +                                   .weigher(thriftMemoryUsageWeigher)
 +                                   .listener(new EvictionListener<Integer, CQLStatement>()
 +                                   {
 +                                       @Override
 +                                       public void onEviction(Integer integer, CQLStatement cqlStatement)
 +                                       {
 +                                           metrics.activePreparedStatements.dec();
-                                            metrics.evictedPreparedStatements.inc();
-                                            evictionCount.incrementAndGet();
 +                                       }
 +                                   })
 +                                   .build();
 +
-         StorageService.scheduledTasks.scheduleAtFixedRate(new Runnable() {
-             @Override
-             public void run() {
-                 long count = evictionCount.getAndSet(0);
-                 if (count > 0)
-                 {
-                     logger.info("{} prepared statements discarded in the last minute because cache limit reached (cache limit = {} bytes)", count, MAX_CACHE_PREPARED_MEMORY);
-                 }
-             }
-         }, 1, 1, TimeUnit.MINUTES);
 +    }
 +
 +    // Work aound initialization dependency
 +    private static enum InternalStateInstance
 +    {
 +        INSTANCE;
 +
 +        private final QueryState queryState;
 +
 +        InternalStateInstance()
          {
 -            logger.error("Unable to initialize MemoryMeter (jamm not specified as javaagent).  This means "
 -                         + "Cassandra will be unable to measure object sizes accurately and may consequently OOM.");
 -            preparedStatements = new ConcurrentLinkedHashMap.Builder<MD5Digest, CQLStatement>()
 -                                 .maximumWeightedCapacity(MAX_CACHE_PREPARED_COUNT)
 -                                 .build();
 -            thriftPreparedStatements = new ConcurrentLinkedHashMap.Builder<Integer, CQLStatement>()
 -                                       .maximumWeightedCapacity(MAX_CACHE_PREPARED_COUNT)
 -                                       .build();
 +            ClientState state = ClientState.forInternalCalls();
 +            try
 +            {
 +                state.setKeyspace(Keyspace.SYSTEM_KS);
 +            }
 +            catch (InvalidRequestException e)
 +            {
 +                throw new RuntimeException();
 +            }
 +            this.queryState = new QueryState(state);
          }
      }
  
@@@ -413,24 -266,24 +394,28 @@@
              throw new InvalidRequestException(String.format("Prepared statement of size %d bytes is larger than allowed maximum of %d bytes.",
                                                              statementSize,
                                                              MAX_CACHE_PREPARED_MEMORY));
-         if (forThrift)
 -
 -        if (forThrift)
++        try
          {
--            int statementId = toHash.hashCode();
--            thriftPreparedStatements.put(statementId, prepared.statement);
-             metrics.activePreparedStatements.inc();
-             logger.trace("Stored prepared statement #{} with {} bind markers",
-                     statementId,
-                     prepared.statement.getBoundTerms());
-             return ResultMessage.Prepared.forThrift(statementId, prepared.boundNames);
-         } else
 -            logger.trace(String.format("Stored prepared statement #%d with %d bind markers",
 -                                       statementId,
 -                                       prepared.statement.getBoundTerms()));
 -            return ResultMessage.Prepared.forThrift(statementId, prepared.boundNames);
 -        }
 -        else
++            if (forThrift)
++            {
++                int statementId = toHash.hashCode();
++                thriftPreparedStatements.put(statementId, prepared.statement);
++                logger.trace("Stored prepared statement #{} with {} bind markers",
++                        statementId,
++                        prepared.statement.getBoundTerms());
++                return ResultMessage.Prepared.forThrift(statementId, prepared.boundNames);
++            } else
++            {
++                MD5Digest statementId = MD5Digest.compute(toHash);
++                preparedStatements.put(statementId, prepared);
++                logger.trace("Stored prepared statement #{} with {} bind markers",
++                        statementId,
++                        prepared.statement.getBoundTerms());
++                return new ResultMessage.Prepared(statementId, prepared);
++            }
++        } finally
          {
--            MD5Digest statementId = MD5Digest.compute(toHash);
-             preparedStatements.put(statementId, prepared);
 -            preparedStatements.put(statementId, prepared.statement);
 -            logger.trace(String.format("Stored prepared statement %s with %d bind markers",
 -                                       statementId,
 -                                       prepared.statement.getBoundTerms()));
 -            return new ResultMessage.Prepared(statementId, prepared);
 +            metrics.activePreparedStatements.inc();
-             logger.trace("Stored prepared statement #{} with {} bind markers",
-                     statementId,
-                     prepared.statement.getBoundTerms());
-             return new ResultMessage.Prepared(statementId, prepared);
          }
      }
  

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b319b406/src/java/org/apache/cassandra/metrics/CqlStatementMetrics.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/metrics/CqlStatementMetrics.java
index ba27d89,0000000..02b4ad0
mode 100644,000000..100644
--- a/src/java/org/apache/cassandra/metrics/CqlStatementMetrics.java
+++ b/src/java/org/apache/cassandra/metrics/CqlStatementMetrics.java
@@@ -1,54 -1,0 +1,53 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements.  See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership.  The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.cassandra.metrics;
 +
 +import com.yammer.metrics.Metrics;
 +import com.yammer.metrics.core.Counter;
 +import com.yammer.metrics.core.Gauge;
 +import com.yammer.metrics.util.RatioGauge;
 +
 +
 +public class CqlStatementMetrics
 +{
 +    private final MetricNameFactory factory = new DefaultNameFactory("CqlStatement");
 +    public final Counter activePreparedStatements = Metrics.newCounter(factory.createMetricName("ActivePreparedStatements"));
-     public final Counter evictedPreparedStatements = Metrics.newCounter(factory.createMetricName("EvictedPreparedStatements"));
 +    public final Counter executedPrepared = Metrics.newCounter(factory.createMetricName("ExecutedPrepared"));
 +    public final Counter executedUnprepared = Metrics.newCounter(factory.createMetricName("ExecutedUnPrepared"));
 +
 +    public final Gauge<Double> preparedRatio = Metrics.newGauge(factory.createMetricName("PreparedUnpreparedRatio"), new RatioGauge()
 +    {
 +        protected double getNumerator()
 +        {
 +            long num = executedPrepared.count();
 +            return num == 0 ? 1 : num;
 +        }
 +
 +        protected double getDenominator()
 +        {
 +            long den = executedUnprepared.count();
 +            return den == 0 ? 1 : den;
 +        }
 +    });
 +
 +    public void reset()
 +    {
 +        executedPrepared.clear();
 +        executedUnprepared.clear();
 +    }
 +}