adelapena commented on code in PR #1891:
URL: https://github.com/apache/cassandra/pull/1891#discussion_r1129286429
##########
src/java/org/apache/cassandra/utils/streamhist/StreamingTombstoneHistogramBuilder.java:
##########
@@ -242,47 +249,51 @@ void mergeNearestPoints()
{
assert isFull() : "DataHolder must be full in order to merge two
points";
- final int[] smallestDifference =
findPointPairWithSmallestDistance();
+ final long[] smallestDifference =
findPointPairWithSmallestDistance();
- final int point1 = smallestDifference[0];
- final int point2 = smallestDifference[1];
+ final long point1 = smallestDifference[0];
+ final long point2 = smallestDifference[1];
- long key = wrap(point1, 0);
- int index = Arrays.binarySearch(data, key);
+ int index = Arrays.binarySearch(points, point1);
if (index < 0)
{
index = -index - 1;
- assert (index < data.length) : "Not found in array";
- assert (unwrapPoint(data[index]) == point1) : "Not found in
array";
+ assert (index < points.length) : "Not found in array";
+ assert (points[index] == point1) : "Not found in array";
}
- long value1 = unwrapValue(data[index]);
- long value2 = unwrapValue(data[index + 1]);
-
- assert (unwrapPoint(data[index + 1]) == point2) : "point2 should
follow point1";
+ long value1 = values[index];
+ long value2 = values[index + 1];
- long sum = value1 + value2;
+ assert (points[index + 1] == point2) : "point2 should follow
point1";
- //let's evaluate in long values to handle overflow in
multiplication
- int newPoint = saturatingCastToInt((point1 * value1 + point2 *
value2) / sum);
+ long a = saturatingCastToLong(point1 * value1);
+ long b = saturatingCastToLong(point2 * value2);
+ long sum = saturatingCastToLong(value1 + value2);
+ long newPoint =
saturatingCastToMaxDeletionTime(saturatingCastToLong(a + b) / sum);
+ newPoint = newPoint <= point1 ?
saturatingCastToMaxDeletionTime(point1 + 1) : newPoint;
+ newPoint = newPoint > point2 ? point2 : newPoint;
Review Comment:
```suggestion
newPoint = Math.min(newPoint, point2);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]