cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject cassandra git commit: Cleanup recycled BTree references, trim large recycled buffers
Date Wed, 01 Jun 2016 20:24:30 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 59949ac38 -> eb5a59a31


Cleanup recycled BTree references, trim large recycled buffers

Patch by Alex Petrov; reviewed by Jake Luciani for 11838-trunk

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

Branch: refs/heads/trunk
Commit: eb5a59a311a14cc0a3c37a13d10abc8c5a0f6d1b
Parents: 59949ac
Author: Alex Petrov <oleksandr.petrov@gmail.com>
Authored: Mon May 30 09:09:41 2016 +0200
Committer: T Jake Luciani <jake@apache.org>
Committed: Wed Jun 1 16:24:07 2016 -0400

----------------------------------------------------------------------
 .../cassandra/io/util/DataOutputBuffer.java       | 18 +++++++++++++++---
 .../org/apache/cassandra/utils/btree/BTree.java   |  1 +
 2 files changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb5a59a3/src/java/org/apache/cassandra/io/util/DataOutputBuffer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/util/DataOutputBuffer.java b/src/java/org/apache/cassandra/io/util/DataOutputBuffer.java
index 8dbad8c..f4f50b1 100644
--- a/src/java/org/apache/cassandra/io/util/DataOutputBuffer.java
+++ b/src/java/org/apache/cassandra/io/util/DataOutputBuffer.java
@@ -40,6 +40,13 @@ public class DataOutputBuffer extends BufferedDataOutputStreamPlus
      */
     private static final long DOUBLING_THRESHOLD = Long.getLong(Config.PROPERTY_PREFIX +
"DOB_DOUBLING_THRESHOLD_MB", 64);
 
+    /*
+     * Only recycle OutputBuffers up to 1Mb. Larger buffers will be trimmed back to this
size.
+     */
+    private static final int MAX_RECYCLE_BUFFER_SIZE = 1024 * 1024;
+
+    private static final int DEFAULT_INITIAL_BUFFER_SIZE = 128;
+
     public static final Recycler<DataOutputBuffer> RECYCLER = new Recycler<DataOutputBuffer>()
     {
         protected DataOutputBuffer newObject(Handle handle)
@@ -52,12 +59,12 @@ public class DataOutputBuffer extends BufferedDataOutputStreamPlus
 
     private DataOutputBuffer(Recycler.Handle handle)
     {
-        this(128, handle);
+        this(DEFAULT_INITIAL_BUFFER_SIZE, handle);
     }
 
     public DataOutputBuffer()
     {
-        this(128);
+        this(DEFAULT_INITIAL_BUFFER_SIZE);
     }
 
     public DataOutputBuffer(int size)
@@ -79,8 +86,13 @@ public class DataOutputBuffer extends BufferedDataOutputStreamPlus
     public void recycle()
     {
         assert handle != null;
-        buffer.rewind();
 
+        // Avoid throwing away instances that are too large, trim large buffers to default
size instead.
+        // See CASSANDRA-11838 for details.
+        if (buffer().capacity() > MAX_RECYCLE_BUFFER_SIZE)
+            buffer = ByteBuffer.allocate(DEFAULT_INITIAL_BUFFER_SIZE);
+
+        buffer.rewind();
         RECYCLER.recycle(this, handle);
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb5a59a3/src/java/org/apache/cassandra/utils/btree/BTree.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/btree/BTree.java b/src/java/org/apache/cassandra/utils/btree/BTree.java
index 4f21d26..5665869 100644
--- a/src/java/org/apache/cassandra/utils/btree/BTree.java
+++ b/src/java/org/apache/cassandra/utils/btree/BTree.java
@@ -838,6 +838,7 @@ public class BTree
         {
             this.comparator = comparator;
             quickResolver = null;
+            Arrays.fill(values, 0, count, null);
             count = 0;
             detected = true;
             auto = true;


Mime
View raw message