You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "Viraj Jasani (Jira)" <ji...@apache.org> on 2020/09/18 10:45:00 UTC
[jira] [Comment Edited] (HBASE-25052)
FastLongHistogram#getCountAtOrBelow method is broken.
[ https://issues.apache.org/jira/browse/HBASE-25052?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17198280#comment-17198280 ]
Viraj Jasani edited comment on HBASE-25052 at 9/18/20, 10:44 AM:
-----------------------------------------------------------------
[~shahrs87] you can provide higher bound of region with constructor.
In the test, if you define maxExpected argument, the test should pass:
{code:java}
HistogramImpl histogram = new HistogramImpl(10);
{code}
or maxExpected could be 100 also.
The default implementation of HistogramImpl() uses very huge long value, ideally not well fit for small data sets.
{code:java}
public HistogramImpl() {
this((long) Integer.MAX_VALUE << 2);
}
{code}
As part of HBASE-23245, we just updated *this(Integer.MAX_VALUE << 2)* to *this((long) Integer.MAX_VALUE << 2)*.
*Integer.MAX_VALUE << 2* = ((2^31)-1)**2,* which is an overflow for int. Hence, without converting this overflow to long, if we pass the value as is, it will be treated as -4. Hence, casting the value to long was the fix.
was (Author: vjasani):
[~shahrs87] you can provide higher bound of region with constructor.
In the test, if you define maxExpected argument, the test should pass:
{code:java}
HistogramImpl histogram = new HistogramImpl(10);
{code}
or maxExpected could be 100 also.
The default implementation of HistogramImpl() uses very huge long value, ideally not well fit for small data sets.
{code:java}
public HistogramImpl() {
this((long) Integer.MAX_VALUE << 2);
}
{code}
As part of HBASE-23245, we just updated *this(Integer.MAX_VALUE << 2)* to *this((long) Integer.MAX_VALUE << 2)*. *Integer.MAX_VALUE << 2* = ((2^31)-1)**2,* which is an overflow for int. Hence, without converting this overflow to long, if we pass the value as is, it will be treated as -4. Hence, casting the value to long was the fix.
> FastLongHistogram#getCountAtOrBelow method is broken.
> -----------------------------------------------------
>
> Key: HBASE-25052
> URL: https://issues.apache.org/jira/browse/HBASE-25052
> Project: HBase
> Issue Type: Bug
> Components: metrics
> Affects Versions: 3.0.0-alpha-1, 2.3.0, 1.6.0, 2.2.3
> Reporter: Rushabh Shah
> Priority: Major
>
> FastLongHistogram#getCountAtOrBelow method is broken.
> If I revert HBASE-23245 then it works fine.
> Wrote a small test case in TestHistogramImpl.java :
> {code:java}
> @Test
> public void testAdd1() {
> HistogramImpl histogram = new HistogramImpl();
> for (int i = 0; i < 100; i++) {
> histogram.update(i);
> }
> Snapshot snapshot = histogram.snapshot();
> // This should return count as 6 since we added 0, 1, 2, 3, 4, 5
> Assert.assertEquals(6, snapshot.getCountAtOrBelow(5));
> {code}
> It fails as below:
> java.lang.AssertionError:
> Expected :6
> Actual :100
--
This message was sent by Atlassian Jira
(v8.3.4#803005)