Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 ff5c497d1 -> 7232d72c0
  refs/heads/cassandra-3.0 76f175028 -> 7a274dd36
  refs/heads/cassandra-3.X a0419085d -> 2931a1938
  refs/heads/trunk a83aeba94 -> a48ebbcf0


Limit colUpdateTimeDelta histogram updates to reasonable deltas

patch by Joel Knighton; reviewed by Marcus Eriksson for CASSANDRA-11117


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

Branch: refs/heads/cassandra-2.2
Commit: 7232d72c0f375f8034b506d05278bf8ec975a36a
Parents: ff5c497
Author: Joel Knighton <joel.knigh...@datastax.com>
Authored: Thu Sep 29 21:56:27 2016 -0500
Committer: Marcus Eriksson <marc...@apache.org>
Committed: Thu Oct 13 15:01:29 2016 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../apache/cassandra/db/ColumnFamilyStore.java  |  7 +++++-
 .../cassandra/db/ColumnFamilyMetricTest.java    | 26 ++++++++++++++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/7232d72c/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index ae9ef7a..682f12b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.2.9
+ * Limit colUpdateTimeDelta histogram updates to reasonable deltas 
(CASSANDRA-11117)
  * Fix leak errors and execution rejected exceptions when draining 
(CASSANDRA-12457)
  * Fix merkle tree depth calculation (CASSANDRA-12580)
  * Make Collections deserialization more robust (CASSANDRA-12618)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/7232d72c/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 644d1f5..c6b69dc 100644
--- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
+++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
@@ -1347,8 +1347,13 @@ public class ColumnFamilyStore implements 
ColumnFamilyStoreMBean
         maybeUpdateRowCache(key);
         metric.samplers.get(Sampler.WRITES).addSample(key.getKey(), 
key.hashCode(), 1);
         metric.writeLatency.addNano(System.nanoTime() - start);
+        // CASSANDRA-11117 - certain resolution paths on memtable put can 
result in very
+        // large time deltas, either through a variety of sentinel timestamps 
(used for empty values, ensuring
+        // a minimal write, etc). This limits the time delta to the max value 
the histogram
+        // can bucket correctly. This also filters the Long.MAX_VALUE case 
where there was no previous value
+        // to update.
         if(timeDelta < Long.MAX_VALUE)
-            metric.colUpdateTimeDeltaHistogram.update(timeDelta);
+            
metric.colUpdateTimeDeltaHistogram.update(Math.min(18165375903306L, timeDelta));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cassandra/blob/7232d72c/test/unit/org/apache/cassandra/db/ColumnFamilyMetricTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/ColumnFamilyMetricTest.java 
b/test/unit/org/apache/cassandra/db/ColumnFamilyMetricTest.java
index 1337564..2d89e09 100644
--- a/test/unit/org/apache/cassandra/db/ColumnFamilyMetricTest.java
+++ b/test/unit/org/apache/cassandra/db/ColumnFamilyMetricTest.java
@@ -103,4 +103,30 @@ public class ColumnFamilyMetricTest
 
         store.enableAutoCompaction();
     }
+
+    @Test
+    public void testColUpdateTimeDeltaFiltering()
+    {
+        Keyspace keyspace = Keyspace.open("Keyspace1");
+        ColumnFamilyStore store = keyspace.getColumnFamilyStore("Standard2");
+
+        // This confirms another test/set up did not overflow the histogram
+        
store.metric.colUpdateTimeDeltaHistogram.cf.getSnapshot().get999thPercentile();
+
+        ByteBuffer key = ByteBufferUtil.bytes(4242);
+        Mutation m = new Mutation("Keyspace1", key);
+        m.add("Standard2", cellname("0"), ByteBufferUtil.bytes("0"), 0);
+        m.apply();
+
+        // The histogram should not have overflowed on the first write
+        
store.metric.colUpdateTimeDeltaHistogram.cf.getSnapshot().get999thPercentile();
+
+        m = new Mutation("Keyspace1", key);
+        // smallest time delta that would overflow the histogram if unfiltered
+        m.add("Standard2", cellname("0"), ByteBufferUtil.bytes("1"), 
18165375903307L);
+        m.apply();
+
+        // CASSANDRA-11117 - update with large timestamp delta should not 
overflow the histogram
+        
store.metric.colUpdateTimeDeltaHistogram.cf.getSnapshot().get999thPercentile();
+    }
 }

Reply via email to