cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tylerho...@apache.org
Subject [1/2] git commit: Avoid boxing in ColumnStats min/max trackers
Date Wed, 22 Oct 2014 16:30:47 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 5e6eb0e72 -> f6c9d282b


Avoid boxing in ColumnStats min/max trackers

Patch by Rajanarayanan Thottuvaikkatumana; reviewed by Tyler Hobbs for
CASSANDRA-8109


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

Branch: refs/heads/trunk
Commit: c774ea3463b06a1347b16e73fdb4a75ab80aa777
Parents: 94fea8d
Author: Rajanarayanan Thottuvaikkatumana <rnamboodiri@gmail.com>
Authored: Wed Oct 22 11:25:12 2014 -0500
Committer: Tyler Hobbs <tyler@datastax.com>
Committed: Wed Oct 22 11:25:12 2014 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../org/apache/cassandra/db/ColumnFamily.java   |  6 +-
 .../db/compaction/LazilyCompactedRow.java       |  6 +-
 .../cassandra/io/sstable/ColumnStats.java       | 64 +++++++++++++++-----
 .../cassandra/io/sstable/SSTableWriter.java     |  6 +-
 5 files changed, 59 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/c774ea34/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 5882080..4dfb81d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,6 @@
 2.1.2
  * Fix CREATE TABLE for CQL2 (CASSANDRA-8144)
+ * Avoid boxing in ColumnStats min/max trackers (CASSANDRA-8109)
 
 
 2.1.1

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c774ea34/src/java/org/apache/cassandra/db/ColumnFamily.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/ColumnFamily.java b/src/java/org/apache/cassandra/db/ColumnFamily.java
index 38b39fe..483ecb0 100644
--- a/src/java/org/apache/cassandra/db/ColumnFamily.java
+++ b/src/java/org/apache/cassandra/db/ColumnFamily.java
@@ -399,10 +399,10 @@ public abstract class ColumnFamily implements Iterable<Cell>,
IRowCacheEntry
         // note that we default to MIN_VALUE/MAX_VALUE here to be able to override them later
in this method
         // we are checking row/range tombstones and actual cells - there should always be
data that overrides
         // these with actual values
-        ColumnStats.MinTracker<Long> minTimestampTracker = new ColumnStats.MinTracker<>(Long.MIN_VALUE);
-        ColumnStats.MaxTracker<Long> maxTimestampTracker = new ColumnStats.MaxTracker<>(Long.MAX_VALUE);
+        ColumnStats.MinLongTracker minTimestampTracker = new ColumnStats.MinLongTracker(Long.MIN_VALUE);
+        ColumnStats.MaxLongTracker maxTimestampTracker = new ColumnStats.MaxLongTracker(Long.MAX_VALUE);
         StreamingHistogram tombstones = new StreamingHistogram(SSTable.TOMBSTONE_HISTOGRAM_BIN_SIZE);
-        ColumnStats.MaxTracker<Integer> maxDeletionTimeTracker = new ColumnStats.MaxTracker<>(Integer.MAX_VALUE);
+        ColumnStats.MaxIntTracker maxDeletionTimeTracker = new ColumnStats.MaxIntTracker(Integer.MAX_VALUE);
         List<ByteBuffer> minColumnNamesSeen = Collections.emptyList();
         List<ByteBuffer> maxColumnNamesSeen = Collections.emptyList();
         boolean hasLegacyCounterShards = false;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c774ea34/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java b/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java
index fa59dba..cfdbd17 100644
--- a/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java
+++ b/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java
@@ -198,11 +198,11 @@ public class LazilyCompactedRow extends AbstractCompactedRow
         // if the row tombstone is 'live' we need to set timestamp to MAX_VALUE to be able
to overwrite it later
         // markedForDeleteAt is MIN_VALUE for 'live' row tombstones (which we use to default
maxTimestampSeen)
 
-        ColumnStats.MinTracker<Long> minTimestampTracker = new ColumnStats.MinTracker<>(Long.MIN_VALUE);
-        ColumnStats.MaxTracker<Long> maxTimestampTracker = new ColumnStats.MaxTracker<>(Long.MAX_VALUE);
+        ColumnStats.MinLongTracker minTimestampTracker = new ColumnStats.MinLongTracker(Long.MIN_VALUE);
+        ColumnStats.MaxLongTracker maxTimestampTracker = new ColumnStats.MaxLongTracker(Long.MAX_VALUE);
         // we need to set MIN_VALUE if we are 'live' since we want to overwrite it later
         // we are bound to have either a RangeTombstone or standard cells will set this properly:
-        ColumnStats.MaxTracker<Integer> maxDeletionTimeTracker = new ColumnStats.MaxTracker<>(Integer.MAX_VALUE);
+        ColumnStats.MaxIntTracker maxDeletionTimeTracker = new ColumnStats.MaxIntTracker(Integer.MAX_VALUE);
 
         StreamingHistogram tombstones = new StreamingHistogram(SSTable.TOMBSTONE_HISTOGRAM_BIN_SIZE);
         List<ByteBuffer> minColumnNameSeen = Collections.emptyList();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c774ea34/src/java/org/apache/cassandra/io/sstable/ColumnStats.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/ColumnStats.java b/src/java/org/apache/cassandra/io/sstable/ColumnStats.java
index 873aa09..83a16c9 100644
--- a/src/java/org/apache/cassandra/io/sstable/ColumnStats.java
+++ b/src/java/org/apache/cassandra/io/sstable/ColumnStats.java
@@ -18,7 +18,6 @@
 package org.apache.cassandra.io.sstable;
 
 import java.nio.ByteBuffer;
-import java.util.Comparator;
 import java.util.List;
 
 import org.apache.cassandra.utils.StreamingHistogram;
@@ -63,18 +62,19 @@ public class ColumnStats
         this.hasLegacyCounterShards = hasLegacyCounterShards;
     }
 
-    public static class MinTracker<T extends Comparable<T>>
+    // We use explicit classes for ints and longs instead of generics to avoid boxing and
unboxing (See CASSANDRA-8109)
+    public static class MinLongTracker
     {
-        private final T defaultValue;
+        private final long defaultValue;
         private boolean isSet = false;
-        private T value;
+        private long value;
 
-        public MinTracker(T defaultValue)
+        public MinLongTracker(long defaultValue)
         {
             this.defaultValue = defaultValue;
         }
 
-        public void update(T value)
+        public void update(long value)
         {
             if (!isSet)
             {
@@ -83,12 +83,12 @@ public class ColumnStats
             }
             else
             {
-                if (value.compareTo(this.value) < 0)
+                if (value <this.value)
                     this.value = value;
             }
         }
 
-        public T get()
+        public long get()
         {
             if (isSet)
                 return value;
@@ -96,18 +96,18 @@ public class ColumnStats
         }
     }
 
-    public static class MaxTracker<T extends Comparable<T>>
+    public static class MaxLongTracker
     {
-        private final T defaultValue;
+        private final long defaultValue;
         private boolean isSet = false;
-        private T value;
+        private long value;
 
-        public MaxTracker(T defaultValue)
+        public MaxLongTracker(long defaultValue)
         {
             this.defaultValue = defaultValue;
         }
 
-        public void update(T value)
+        public void update(long value)
         {
             if (!isSet)
             {
@@ -116,16 +116,50 @@ public class ColumnStats
             }
             else
             {
-                if (value.compareTo(this.value) > 0)
+                if (value >this.value)
                     this.value = value;
             }
         }
 
-        public T get()
+        public long get()
         {
             if (isSet)
                 return value;
             return defaultValue;
         }
     }
+
+    public static class MaxIntTracker
+    {
+        private final int defaultValue;
+        private boolean isSet = false;
+        private int value;
+
+        public MaxIntTracker(int defaultValue)
+        {
+            this.defaultValue = defaultValue;
+        }
+
+        public void update(int value)
+        {
+            if (!isSet)
+            {
+                this.value = value;
+                isSet = true;
+            }
+            else
+            {
+                if (value >this.value)
+                    this.value = value;
+            }
+        }
+
+        public int get()
+        {
+            if (isSet)
+                return value;
+            return defaultValue;
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c774ea34/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java b/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java
index e92803a..50c2ca3 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java
@@ -244,9 +244,9 @@ public class SSTableWriter extends SSTable
     {
         long currentPosition = beforeAppend(key);
 
-        ColumnStats.MaxTracker<Long> maxTimestampTracker = new ColumnStats.MaxTracker<>(Long.MAX_VALUE);
-        ColumnStats.MinTracker<Long> minTimestampTracker = new ColumnStats.MinTracker<>(Long.MIN_VALUE);
-        ColumnStats.MaxTracker<Integer> maxDeletionTimeTracker = new ColumnStats.MaxTracker<>(Integer.MAX_VALUE);
+        ColumnStats.MaxLongTracker maxTimestampTracker = new ColumnStats.MaxLongTracker(Long.MAX_VALUE);
+        ColumnStats.MinLongTracker minTimestampTracker = new ColumnStats.MinLongTracker(Long.MIN_VALUE);
+        ColumnStats.MaxIntTracker maxDeletionTimeTracker = new ColumnStats.MaxIntTracker(Integer.MAX_VALUE);
         List<ByteBuffer> minColumnNames = Collections.emptyList();
         List<ByteBuffer> maxColumnNames = Collections.emptyList();
         StreamingHistogram tombstones = new StreamingHistogram(TOMBSTONE_HISTOGRAM_BIN_SIZE);


Mime
View raw message