You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "ZanderXu (Jira)" <ji...@apache.org> on 2022/11/17 09:52:00 UTC
[jira] [Resolved] (HADOOP-18429) MutableGaugeFloat#incr(float) get stuck in an infinite loop
[ https://issues.apache.org/jira/browse/HADOOP-18429?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
ZanderXu resolved HADOOP-18429.
-------------------------------
Fix Version/s: 3.4.0
Hadoop Flags: Reviewed
Resolution: Fixed
> MutableGaugeFloat#incr(float) get stuck in an infinite loop
> -----------------------------------------------------------
>
> Key: HADOOP-18429
> URL: https://issues.apache.org/jira/browse/HADOOP-18429
> Project: Hadoop Common
> Issue Type: Bug
> Components: metrics
> Reporter: xinqiu.hu
> Assignee: Ashutosh Gupta
> Priority: Major
> Labels: pull-request-available
> Fix For: 3.4.0
>
>
> The current implementation converts the value from int to float, causing the compareAndSet method to get stuck.
> {code:java}
> private final boolean compareAndSet(float expect, float update) {
> return value.compareAndSet(Float.floatToIntBits(expect),
> Float.floatToIntBits(update));
> }
> private void incr(float delta) {
> while (true) {
> float current = value.get();
> float next = current + delta;
> if (compareAndSet(current, next)) {
> setChanged();
> return;
> }
> }
> } {code}
>
> Perhaps it could be:
> {code:java}
> private void incr(float delta) {
> while (true) {
> float current = Float.intBitsToFloat(value.get());
> float next = current + delta;
> if (compareAndSet(current, next)) {
> setChanged();
> return;
> }
> }
> } {code}
>
> The unit test looks like this
> {code:java}
> MutableGaugeFloat mgf = new MutableGaugeFloat(Context,3.2f);
> assertEquals(3.2f, mgf.value(), 0.0);
> mgf.incr();
> assertEquals(4.2f, mgf.value(), 0.0); {code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org