cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sn...@apache.org
Subject cassandra git commit: Reuse DataOutputBuffer from ColumnIndex
Date Fri, 08 Jul 2016 18:05:22 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk ab2f74404 -> ae4d705db


Reuse DataOutputBuffer from ColumnIndex

patch by Robert Stupp; reviewed by T Jake Luciani for CASSANDRA-11970


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

Branch: refs/heads/trunk
Commit: ae4d705db38b713400292fc46ae0858fb0545fe3
Parents: ab2f744
Author: Robert Stupp <snazy@snazy.de>
Authored: Fri Jul 8 20:04:23 2016 +0200
Committer: Robert Stupp <snazy@snazy.de>
Committed: Fri Jul 8 20:04:23 2016 +0200

----------------------------------------------------------------------
 CHANGES.txt                                         |  1 +
 src/java/org/apache/cassandra/db/ColumnIndex.java   | 16 +++++++++++++++-
 .../apache/cassandra/io/util/DataOutputBuffer.java  |  5 +++++
 3 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/ae4d705d/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b65aad1..690b1d6 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.10
+ * Reuse DataOutputBuffer from ColumnIndex (CASSANDRA-11970)
  * Remove DatabaseDescriptor dependency from SegmentedFile (CASSANDRA-11580)
  * Add supplied username to authentication error messages (CASSANDRA-12076)
  * Remove pre-startup check for open JMX port (CASSANDRA-12074)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ae4d705d/src/java/org/apache/cassandra/db/ColumnIndex.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/ColumnIndex.java b/src/java/org/apache/cassandra/db/ColumnIndex.java
index 2e7a2ee..9cea084 100644
--- a/src/java/org/apache/cassandra/db/ColumnIndex.java
+++ b/src/java/org/apache/cassandra/db/ColumnIndex.java
@@ -48,6 +48,8 @@ public class ColumnIndex
     // used, until the row-index-entry reaches config column_index_cache_size_in_kb
     private final List<IndexInfo> indexSamples = new ArrayList<>();
 
+    private DataOutputBuffer reusableBuffer;
+
     public int columnIndexCount;
     private int[] indexOffsets;
 
@@ -95,6 +97,8 @@ public class ColumnIndex
         this.firstClustering = null;
         this.lastClustering = null;
         this.openMarker = null;
+        if (this.buffer != null)
+            this.reusableBuffer = this.buffer;
         this.buffer = null;
     }
 
@@ -195,7 +199,7 @@ public class ColumnIndex
             indexSamplesSerializedSize += idxSerializer.serializedSize(cIndexInfo);
             if (indexSamplesSerializedSize + columnIndexCount * TypeSizes.sizeof(0) >
DatabaseDescriptor.getColumnIndexCacheSize())
             {
-                buffer = new DataOutputBuffer(DatabaseDescriptor.getColumnIndexCacheSize()
* 2);
+                buffer = useBuffer();
                 for (IndexInfo indexSample : indexSamples)
                 {
                     idxSerializer.serialize(indexSample, buffer);
@@ -215,6 +219,16 @@ public class ColumnIndex
         firstClustering = null;
     }
 
+    private DataOutputBuffer useBuffer()
+    {
+        if (reusableBuffer != null) {
+            buffer = reusableBuffer;
+            buffer.clear();
+        }
+        // don't use the standard RECYCLER as that only recycles up to 1MB and requires proper
cleanup
+        return new DataOutputBuffer(DatabaseDescriptor.getColumnIndexCacheSize() * 2);
+    }
+
     private void add(Unfiltered unfiltered) throws IOException
     {
         long pos = currentPosition();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ae4d705d/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 f08b48f..cc42c66 100644
--- a/src/java/org/apache/cassandra/io/util/DataOutputBuffer.java
+++ b/src/java/org/apache/cassandra/io/util/DataOutputBuffer.java
@@ -175,6 +175,11 @@ public class DataOutputBuffer extends BufferedDataOutputStreamPlus
         return new GrowingChannel();
     }
 
+    public void clear()
+    {
+        buffer.clear();
+    }
+
     @VisibleForTesting
     final class GrowingChannel implements WritableByteChannel
     {


Mime
View raw message