-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Stats based on LongAdder can return unexpected values #52411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
Pinging @elastic/es-core-features (:Core/Features/Stats) |
It appears that is documented. The Javadocs for
And here's the Javadocs for
|
dnhatn
added a commit
that referenced
this issue
Apr 13, 2021
A CounterMetric is used to track the number of completed and outstanding items, for example, the number of executed refreshes, the currently used memory by indexing, the current pending search requests. In all cases, the current count of CounterMetric is always non-negative. However, as this metric is implemented using a LongAdder, the returned count is NOT an atomic snapshot; invocation in the absence of concurrent updates returns an accurate result, but concurrent updates that occur while the sum is being calculated might not be incorporated. We can replace LongAdder with AtomicLong, but this commit chooses to continue using LongAdder but returns 0 when the sum value is negative. Relates #52411 Closes #70968
dnhatn
added a commit
to dnhatn/elasticsearch
that referenced
this issue
Apr 14, 2021
A CounterMetric is used to track the number of completed and outstanding items, for example, the number of executed refreshes, the currently used memory by indexing, the current pending search requests. In all cases, the current count of CounterMetric is always non-negative. However, as this metric is implemented using a LongAdder, the returned count is NOT an atomic snapshot; invocation in the absence of concurrent updates returns an accurate result, but concurrent updates that occur while the sum is being calculated might not be incorporated. We can replace LongAdder with AtomicLong, but this commit chooses to continue using LongAdder but returns 0 when the sum value is negative. Relates elastic#52411 Closes elastic#70968
dnhatn
added a commit
to dnhatn/elasticsearch
that referenced
this issue
Apr 14, 2021
A CounterMetric is used to track the number of completed and outstanding items, for example, the number of executed refreshes, the currently used memory by indexing, the current pending search requests. In all cases, the current count of CounterMetric is always non-negative. However, as this metric is implemented using a LongAdder, the returned count is NOT an atomic snapshot; invocation in the absence of concurrent updates returns an accurate result, but concurrent updates that occur while the sum is being calculated might not be incorporated. We can replace LongAdder with AtomicLong, but this commit chooses to continue using LongAdder but returns 0 when the sum value is negative. Relates elastic#52411 Closes elastic#70968
dnhatn
added a commit
that referenced
this issue
Apr 14, 2021
A CounterMetric is used to track the number of completed and outstanding items, for example, the number of executed refreshes, the currently used memory by indexing, the current pending search requests. In all cases, the current count of CounterMetric is always non-negative. However, as this metric is implemented using a LongAdder, the returned count is NOT an atomic snapshot; invocation in the absence of concurrent updates returns an accurate result, but concurrent updates that occur while the sum is being calculated might not be incorporated. We can replace LongAdder with AtomicLong, but this commit chooses to continue using LongAdder but returns 0 when the sum value is negative. Relates #52411 Closes #70968
dnhatn
added a commit
that referenced
this issue
Apr 14, 2021
A CounterMetric is used to track the number of completed and outstanding items, for example, the number of executed refreshes, the currently used memory by indexing, the current pending search requests. In all cases, the current count of CounterMetric is always non-negative. However, as this metric is implemented using a LongAdder, the returned count is NOT an atomic snapshot; invocation in the absence of concurrent updates returns an accurate result, but concurrent updates that occur while the sum is being calculated might not be incorporated. We can replace LongAdder with AtomicLong, but this commit chooses to continue using LongAdder but returns 0 when the sum value is negative. Relates #52411 Closes #70968
dnhatn
added a commit
that referenced
this issue
Apr 14, 2021
A CounterMetric is used to track the number of completed and outstanding items, for example, the number of executed refreshes, the currently used memory by indexing, the current pending search requests. In all cases, the current count of CounterMetric is always non-negative. However, as this metric is implemented using a LongAdder, the returned count is NOT an atomic snapshot; invocation in the absence of concurrent updates returns an accurate result, but concurrent updates that occur while the sum is being calculated might not be incorporated. We can replace LongAdder with AtomicLong, but this commit chooses to continue using LongAdder but returns 0 when the sum value is negative. Relates #52411 Closes #70968
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We expect certain stats values to be non-negative when serializing them over the wire. While investigating a test failure (#52406), I noticed that, due to concurrency, counts from
LongAdder
can be inexact, and even be negative even though in a properly serialized execution no such negative value should be observable.Here's a test illustrating the issue:
The text was updated successfully, but these errors were encountered: