Fix AssertionError in nodetool cfstats Backport CASSANDRA-10859
patch by yukim; reviewed by Jeremiah Jordan for CASSANDRA-11297 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/6e0395e5 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/6e0395e5 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/6e0395e5 Branch: refs/heads/cassandra-3.0 Commit: 6e0395e5a8cc7642128685d6d41248798e2e952b Parents: a956e9f Author: Yuki Morishita <yu...@apache.org> Authored: Wed Mar 2 13:19:05 2016 -0600 Committer: Yuki Morishita <yu...@apache.org> Committed: Mon Mar 7 12:39:39 2016 -0600 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../tools/nodetool/TableHistograms.java | 10 ++++------ .../cassandra/utils/EstimatedHistogram.java | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/6e0395e5/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index a6d6a14..89fa904 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.2.6 + * Fix AE in nodetool cfstats (backport CASSANDRA-10859) (CASSANDRA-11297) * Unresolved hostname leads to replace being ignored (CASSANDRA-11210) * Fix filtering on non-primary key columns for thrift static column families (CASSANDRA-6377) http://git-wip-us.apache.org/repos/asf/cassandra/blob/6e0395e5/src/java/org/apache/cassandra/tools/nodetool/TableHistograms.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/nodetool/TableHistograms.java b/src/java/org/apache/cassandra/tools/nodetool/TableHistograms.java index b152434..207a74e 100644 --- a/src/java/org/apache/cassandra/tools/nodetool/TableHistograms.java +++ b/src/java/org/apache/cassandra/tools/nodetool/TableHistograms.java @@ -66,14 +66,12 @@ public class TableHistograms extends NodeToolCmd } else { - long[] rowSizeBucketOffsets = new EstimatedHistogram(estimatedRowSize.length).getBucketOffsets(); - long[] columnCountBucketOffsets = new EstimatedHistogram(estimatedColumnCount.length).getBucketOffsets(); - EstimatedHistogram rowSizeHist = new EstimatedHistogram(rowSizeBucketOffsets, estimatedRowSize); - EstimatedHistogram columnCountHist = new EstimatedHistogram(columnCountBucketOffsets, estimatedColumnCount); + EstimatedHistogram rowSizeHist = new EstimatedHistogram(estimatedRowSize); + EstimatedHistogram columnCountHist = new EstimatedHistogram(estimatedColumnCount); if (rowSizeHist.isOverflowed()) { - System.err.println(String.format("Row sizes are larger than %s, unable to calculate percentiles", rowSizeBucketOffsets[rowSizeBucketOffsets.length - 1])); + System.err.println(String.format("Row sizes are larger than %s, unable to calculate percentiles", rowSizeHist.getLargestBucketOffset())); for (int i = 0; i < offsetPercentiles.length; i++) estimatedRowSizePercentiles[i] = Double.NaN; } @@ -85,7 +83,7 @@ public class TableHistograms extends NodeToolCmd if (columnCountHist.isOverflowed()) { - System.err.println(String.format("Column counts are larger than %s, unable to calculate percentiles", columnCountBucketOffsets[columnCountBucketOffsets.length - 1])); + System.err.println(String.format("Column counts are larger than %s, unable to calculate percentiles", columnCountHist.getLargestBucketOffset())); for (int i = 0; i < estimatedColumnCountPercentiles.length; i++) estimatedColumnCountPercentiles[i] = Double.NaN; } http://git-wip-us.apache.org/repos/asf/cassandra/blob/6e0395e5/src/java/org/apache/cassandra/utils/EstimatedHistogram.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/EstimatedHistogram.java b/src/java/org/apache/cassandra/utils/EstimatedHistogram.java index 6c929df..36048fb 100644 --- a/src/java/org/apache/cassandra/utils/EstimatedHistogram.java +++ b/src/java/org/apache/cassandra/utils/EstimatedHistogram.java @@ -66,6 +66,18 @@ public class EstimatedHistogram buckets = new AtomicLongArray(bucketOffsets.length + 1); } + /** + * Create EstimatedHistogram from only bucket data. + * + * @param bucketData bucket data + */ + public EstimatedHistogram(long[] bucketData) + { + assert bucketData != null && bucketData.length > 0 : "Bucket data must be an array of size more than 0"; + bucketOffsets = newOffsets(bucketData.length - 1, false); + buckets = new AtomicLongArray(bucketData); + } + public EstimatedHistogram(long[] offsets, long[] bucketData) { assert bucketData.length == offsets.length +1; @@ -243,6 +255,14 @@ public class EstimatedHistogram } /** + * @return the largest bucket offset + */ + public long getLargestBucketOffset() + { + return bucketOffsets[bucketOffsets.length - 1]; + } + + /** * @return true if this histogram has overflowed -- that is, a value larger than our largest bucket could bound was added */ public boolean isOverflowed()