cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmcken...@apache.org
Subject [05/22] cassandra git commit: Fix SSTablesPerReadHistogram when row cache hit
Date Fri, 04 Dec 2015 18:20:22 GMT
Fix SSTablesPerReadHistogram when row cache hit

Patch by iburmistrov; reviewed by cyeksigian for CASSANDRA-10585


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

Branch: refs/heads/cassandra-3.0
Commit: acdbba7957be3567d6eeb756f098d81ca736d995
Parents: b876424
Author: Ivan Burmistrov <burmistrov.ivan@gmail.com>
Authored: Fri Dec 4 13:15:54 2015 -0500
Committer: Joshua McKenzie <jmckenzie@apache.org>
Committed: Fri Dec 4 13:15:54 2015 -0500

----------------------------------------------------------------------
 .../apache/cassandra/db/ColumnFamilyStore.java  |  4 +-
 .../org/apache/cassandra/db/RowCacheTest.java   | 51 ++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/acdbba79/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
index 54f6fff..a589b2e 100644
--- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
+++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
@@ -1683,7 +1683,9 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
             {
                 metric.rowCacheHit.inc();
                 Tracing.trace("Row cache hit");
-                return filterColumnFamily(cachedCf, filter);
+                ColumnFamily result = filterColumnFamily(cachedCf, filter);
+                metric.updateSSTableIterated(0);
+                return result;
             }
 
             metric.rowCacheHitOutOfRange.inc();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/acdbba79/test/unit/org/apache/cassandra/db/RowCacheTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/RowCacheTest.java b/test/unit/org/apache/cassandra/db/RowCacheTest.java
index 719c771..714d95d 100644
--- a/test/unit/org/apache/cassandra/db/RowCacheTest.java
+++ b/test/unit/org/apache/cassandra/db/RowCacheTest.java
@@ -45,6 +45,7 @@ import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 public class RowCacheTest extends SchemaLoader
 {
@@ -319,6 +320,56 @@ public class RowCacheTest extends SchemaLoader
         }
     }
 
+    @Test
+    public void testSSTablesPerReadHistogramWhenRowCache()
+    {
+        CompactionManager.instance.disableAutoCompaction();
+
+        Keyspace keyspace = Keyspace.open(KEYSPACE);
+        ColumnFamilyStore cachedStore  = keyspace.getColumnFamilyStore(COLUMN_FAMILY);
+
+        // empty the row cache
+        CacheService.instance.invalidateRowCache();
+
+        // set global row cache size to 1 MB
+        CacheService.instance.setRowCacheCapacityInMB(1);
+
+        // inserting 100 rows into both column families
+        insertData(KEYSPACE, COLUMN_FAMILY, 0, 100);
+
+        //force flush for confidence that SSTables exists
+        cachedStore.forceBlockingFlush();
+
+        // clear SSTablePerReadHistogram
+        cachedStore.metric.sstablesPerReadHistogram.cf.clear();
+
+        for (int i = 0; i < 100; i++)
+        {
+            DecoratedKey key = Util.dk("key" + i);
+
+            cachedStore.getColumnFamily(key, Composites.EMPTY, Composites.EMPTY, false, 1,
System.currentTimeMillis());
+
+            long count_before = cachedStore.metric.sstablesPerReadHistogram.cf.count();
+            cachedStore.getColumnFamily(key, Composites.EMPTY, Composites.EMPTY, false, 1,
System.currentTimeMillis());
+
+            // check that SSTablePerReadHistogram has been updated by zero,
+            // so count has been increased and in a 1/2 of requests there were zero read
SSTables
+            long count_after = cachedStore.metric.sstablesPerReadHistogram.cf.count();
+            double belowMedian_after = cachedStore.metric.sstablesPerReadHistogram.cf.getSnapshot().getValue(0.49);
+            double mean_after = cachedStore.metric.sstablesPerReadHistogram.cf.mean();
+            assertEquals("SSTablePerReadHistogram should be updated even key found in row
cache", count_before + 1, count_after);
+            assertTrue("In half of requests we have not touched SSTables, " +
+                       "so 49 percentile value (" + belowMedian_after + ") must be strongly
less than 0.9", belowMedian_after < 0.9D);
+            assertTrue("In half of requests we have not touched SSTables, " +
+                       "so mean value (" + mean_after + ") must be strongly less than 1,
but greater than 0", mean_after < 0.999D && mean_after > 0.001D);
+        }
+
+        assertEquals("Min value of SSTablesPerRead should be zero", 0, cachedStore.metric.sstablesPerReadHistogram.cf.min(),
0.01);
+
+        CacheService.instance.setRowCacheCapacityInMB(0);
+    }
+
+
     public void rowCacheLoad(int totalKeys, int keysToSave, int offset) throws Exception
     {
         CompactionManager.instance.disableAutoCompaction();


Mime
View raw message