cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [2/6] cassandra git commit: Minimize buffers when using them in sstable metadata
Date Tue, 02 Feb 2016 13:21:04 GMT
Minimize buffers when using them in sstable metadata

patch by slebresne; reviewed by benedict for CASSANDRA-11026


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

Branch: refs/heads/cassandra-3.3
Commit: c83d108a30f3c6b670b32d94359df251bf931234
Parents: 839a5ba
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Wed Jan 27 17:30:14 2016 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Tue Feb 2 14:18:48 2016 +0100

----------------------------------------------------------------------
 CHANGES.txt                                             |  1 +
 .../io/sstable/metadata/MetadataCollector.java          | 12 ++++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/c83d108a/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index bed8703..da6f5cc 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.3
+ * Avoid memory leak when collecting sstable metadata (CASSANDRA-11026)
  * Mutations do not block for completion under view lock contention (CASSANDRA-10779)
  * Invalidate legacy schema tables when unloading them (CASSANDRA-11071)
  * (cqlsh) handle INSERT and UPDATE statements with LWT conditions correctly

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c83d108a/src/java/org/apache/cassandra/io/sstable/metadata/MetadataCollector.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/metadata/MetadataCollector.java b/src/java/org/apache/cassandra/io/sstable/metadata/MetadataCollector.java
index 1c93f58..3947dc8 100644
--- a/src/java/org/apache/cassandra/io/sstable/metadata/MetadataCollector.java
+++ b/src/java/org/apache/cassandra/io/sstable/metadata/MetadataCollector.java
@@ -39,6 +39,7 @@ import org.apache.cassandra.io.sstable.Component;
 import org.apache.cassandra.io.sstable.SSTable;
 import org.apache.cassandra.io.sstable.format.SSTableReader;
 import org.apache.cassandra.service.ActiveRepairService;
+import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.EstimatedHistogram;
 import org.apache.cassandra.utils.MurmurHash;
 import org.apache.cassandra.utils.StreamingHistogram;
@@ -232,12 +233,19 @@ public class MetadataCollector implements PartitionStatisticsCollector
         {
             AbstractType<?> type = comparator.subtype(i);
             ByteBuffer newValue = clustering.get(i);
-            minClusteringValues[i] = min(minClusteringValues[i], newValue, type);
-            maxClusteringValues[i] = max(maxClusteringValues[i], newValue, type);
+            minClusteringValues[i] = maybeMinimize(min(minClusteringValues[i], newValue,
type));
+            maxClusteringValues[i] = maybeMinimize(max(maxClusteringValues[i], newValue,
type));
         }
         return this;
     }
 
+    private static ByteBuffer maybeMinimize(ByteBuffer buffer)
+    {
+        // ByteBuffer.minimalBufferFor doesn't handle null, but we can get it in this case
since it's possible
+        // for some clustering values to be null
+        return buffer == null ? null : ByteBufferUtil.minimalBufferFor(buffer);
+    }
+
     private static ByteBuffer min(ByteBuffer b1, ByteBuffer b2, AbstractType<?> comparator)
     {
         if (b1 == null)


Mime
View raw message