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

Colin Patrick McCabe edited comment on HDFS-7495 at 2/24/15 2:35 AM:
---------------------------------------------------------------------

As you commented, on closer inspection, this code isn't incorrect, it is just 
very, very tricky.  

The patch you posted is a step in the right direction, but it still modifies 
these variables without any synchronization, which will lead to findbugs 
warnings (as you saw).

I think this can be refactored to move that block out of getBlockAt altogether 
to avoid both findbugs and the confusing code.


was (Author: cmccabe):
[~tedyu], please don't close things without at least an explanation.

On closer inspection, this code isn't incorrect, it is just very, very tricky.  
The comment here is the clue:
{code}
        // synchronized not strictly needed, since we only get here
        // from synchronized caller methods
{code}

The intent is that there is no "real" lock inversion because we only ever call 
getBlockAt with updatePosition = true when we already hold the stream lock.  Of 
course, these are re-entrant locks, like all Java locks  The "synchronized" 
block is actually probably only there for findbugs.

Although this code is correct, it is not maintainable.  It's just too 
confusing.  I think this can be refactored to avoid this block.

> Lock inversion in DFSInputStream#getBlockAt()
> ---------------------------------------------
>
>                 Key: HDFS-7495
>                 URL: https://issues.apache.org/jira/browse/HDFS-7495
>             Project: Hadoop HDFS
>          Issue Type: Bug
>            Reporter: Ted Yu
>            Priority: Minor
>         Attachments: hdfs-7495-001.patch
>
>
> There're two locks: one on DFSInputStream.this , one on 
> DFSInputStream.infoLock
> Normally lock is obtained on infoLock, then on DFSInputStream.infoLock
> However, such order is not observed in DFSInputStream#getBlockAt() :
> {code}
>     synchronized(infoLock) {
> ...
>       if (updatePosition) {
>         // synchronized not strictly needed, since we only get here
>         // from synchronized caller methods
>         synchronized(this) {
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to