You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ja...@apache.org on 2017/01/03 22:04:58 UTC

[2/3] cassandra git commit: Avoid creating KeyCacheKey instance when key cache is disabled

Avoid creating KeyCacheKey instance when key cache is disabled

patch by Marcus Olsson; reviewed by jasobrown for CASSANDRA-13084


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

Branch: refs/heads/trunk
Commit: 3f1a3b2f60fed7b161cb0ddde6c8dda554cba624
Parents: 917d13f
Author: Marcus Olsson <ma...@ericsson.com>
Authored: Thu Dec 29 10:58:09 2016 +0100
Committer: Jason Brown <ja...@gmail.com>
Committed: Tue Jan 3 14:02:10 2017 -0800

----------------------------------------------------------------------
 CHANGES.txt                                            |  1 +
 .../cassandra/io/sstable/format/SSTableReader.java     | 13 +++++++++++--
 .../io/sstable/format/big/BigTableReader.java          |  4 +---
 3 files changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/3f1a3b2f/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 0557467..9ed66fd 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.12
+ * Avoid byte-array copy when key cache is disabled (CASANDRA-13084)
  * More fixes to the TokenAllocator (CASSANDRA-12990)
  * Require forceful decommission if number of nodes is less than replication factor (CASSANDRA-12510)
  * Allow IN restrictions on column families with collections (CASSANDRA-12654)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/3f1a3b2f/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java b/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java
index 56609b3..5d24f31 100644
--- a/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java
+++ b/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java
@@ -1496,12 +1496,16 @@ public abstract class SSTableReader extends SSTable implements SelfRefCounted<SS
 
     public RowIndexEntry getCachedPosition(DecoratedKey key, boolean updateStats)
     {
-        return getCachedPosition(new KeyCacheKey(metadata.ksAndCFName, descriptor, key.getKey()), updateStats);
+        if (keyCacheEnabled())
+        {
+            return getCachedPosition(getCacheKey(key), updateStats);
+        }
+        return null;
     }
 
     protected RowIndexEntry getCachedPosition(KeyCacheKey unifiedKey, boolean updateStats)
     {
-        if (keyCache != null && keyCache.getCapacity() > 0 && metadata.params.caching.cacheKeys())
+        if (keyCacheEnabled())
         {
             if (updateStats)
             {
@@ -1522,6 +1526,11 @@ public abstract class SSTableReader extends SSTable implements SelfRefCounted<SS
         return null;
     }
 
+    private boolean keyCacheEnabled()
+    {
+        return keyCache != null && keyCache.getCapacity() > 0 && metadata.params.caching.cacheKeys();
+    }
+
     /**
      * Get position updating key cache and stats.
      * @see #getPosition(PartitionPosition, SSTableReader.Operator, boolean)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/3f1a3b2f/src/java/org/apache/cassandra/io/sstable/format/big/BigTableReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/format/big/BigTableReader.java b/src/java/org/apache/cassandra/io/sstable/format/big/BigTableReader.java
index 8c64b01..3d14aca 100644
--- a/src/java/org/apache/cassandra/io/sstable/format/big/BigTableReader.java
+++ b/src/java/org/apache/cassandra/io/sstable/format/big/BigTableReader.java
@@ -147,9 +147,7 @@ public class BigTableReader extends SSTableReader
         // next, the key cache (only make sense for valid row key)
         if ((op == Operator.EQ || op == Operator.GE) && (key instanceof DecoratedKey))
         {
-            DecoratedKey decoratedKey = (DecoratedKey)key;
-            KeyCacheKey cacheKey = new KeyCacheKey(metadata.ksAndCFName, descriptor, decoratedKey.getKey());
-            RowIndexEntry cachedPosition = getCachedPosition(cacheKey, updateCacheAndStats);
+            RowIndexEntry cachedPosition = getCachedPosition((DecoratedKey)key, updateCacheAndStats);
             if (cachedPosition != null)
             {
                 Tracing.trace("Key cache hit for sstable {}", descriptor.generation);