Mmuzaf commented on code in PR #3102:
URL: https://github.com/apache/cassandra/pull/3102#discussion_r1714133974
##########
src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java:
##########
@@ -371,42 +363,50 @@ private void rescaleIfNeeded(long now)
{
try
{
- rescale(now);
+ decayingBuckets = rescale(now);
}
finally
{
- decayLandmark = now;
rescaling.set(false);
}
}
}
}
- private void rescale(long now)
+ /**
+ * rescale races with update;
+ * If rescale is called at the same time as an update, and an update falls
into an already
+ * processed bucket this update will be lost. We accept that for the sake
of update performance.
+ * OTOH, if the update falls into a bucket that is yet to be processed, it
will be added
+ * with a weight that is consistent with the rescaleFactor used by
rescale, so the new rescaled
+ * buckets will all have values consistent with the new decay landmark.
+ */
+ private DecayingBuckets rescale(long now)
{
- // despite striping its safe to rescale each bucket individually
- final double rescaleFactor = forwardDecayWeight(now);
- for (int i = 0; i < decayingBuckets.length(); i++)
+ final double rescaleFactor = decayingBuckets.forwardDecayWeight(now);
Review Comment:
We are reading the `decayingBuckets` three times here and if the `rebase`
method is called, this could potentially cause a problem. So I would save the
decayingBuckets to a local ref and read it.
--
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]