You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-issues@hadoop.apache.org by "Colin Patrick McCabe (JIRA)" <ji...@apache.org> on 2013/02/22 20:52:12 UTC

[jira] [Commented] (HDFS-4522) LightWeightGSet expects incrementing a volatile to be atomic

    [ https://issues.apache.org/jira/browse/HDFS-4522?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13584599#comment-13584599 ] 

Colin Patrick McCabe commented on HDFS-4522:
--------------------------------------------

So this isn't a big problem, because this volatile int was only used for detecting concurrent modification (something the programmer should not be doing anyway.)  But it's easier to just fix it than to add a suppression, and people might copy this incorrect code.  Uploaded patch.
                
> LightWeightGSet expects incrementing a volatile to be atomic
> ------------------------------------------------------------
>
>                 Key: HDFS-4522
>                 URL: https://issues.apache.org/jira/browse/HDFS-4522
>             Project: Hadoop HDFS
>          Issue Type: Bug
>    Affects Versions: 2.0.4-beta
>            Reporter: Colin Patrick McCabe
>            Assignee: Colin Patrick McCabe
>            Priority: Minor
>         Attachments: HDFS-4522.001.patch
>
>
> LightWeightGSet uses a volatile integer to track the current modification number (kind of an epoch number).
> Unfortunately, it includes code like this, that increments this volatile int:
> {code}
>      //insert the element to the head of the linked list
>      modification++;
>      size++;
> {code}
> The bug here is that in between reading the value of modification, incrementing it, and storing it back in the variable, another thread may have modified it.  This could lead to lost updates.
> We should use {{AtomicInteger}} for these cases.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira