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 2015/02/24 03:34:14 UTC
[jira] [Commented] (HDFS-7495) Lock inversion in
DFSInputStream#getBlockAt()
[ https://issues.apache.org/jira/browse/HDFS-7495?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14334283#comment-14334283 ]
Colin Patrick McCabe commented on HDFS-7495:
--------------------------------------------
[~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)