[ 
https://issues.apache.org/jira/browse/HADOOP-5859?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12713894#action_12713894
 ] 

Kan Zhang commented on HADOOP-5859:
-----------------------------------

> I just checked, the JDK6 implementation of LinkedList didn't declare the 
> "size" variable volatile. So Todd is right, a second thread may see a stale 
> cached value

I take it back. Actually, in this particular case the writeChunk() thread will 
be able to see the fresh value of ackQueue size whenever it's been modified. 
The reason is that writeChunk() reads ackQueue size while holding the dataQueue 
lock and waits on the dataQueue lock in a loop when condition is not satisfied. 
There are 2 threads that may modify ackQueue size. One is DataStreamer, who 
always holds both dataQueue and ackQueue locks when modifying ackQueue. So any 
changes to ackQueue by DataStreamer will be visible to writeChunk() thread. The 
other thread that modifies ackQueue is ResponseProcessor. It may modify 
ackQueue while holding only the ackQueue lock. However, immediately after 
ackQueue modification, it grabs the dataQueue lock and calls 
dataQueue.notifyAll() to wake up the writeChunk() thread. So when the 
writeChunk() thread grabs the dataQueue lock afterwards, the fresh value of 
ackQueue size will be visible. Make sense?


> FindBugs : fix "wait() or sleep() with locks held" warnings in hdfs
> -------------------------------------------------------------------
>
>                 Key: HADOOP-5859
>                 URL: https://issues.apache.org/jira/browse/HADOOP-5859
>             Project: Hadoop Core
>          Issue Type: Bug
>          Components: dfs
>            Reporter: Kan Zhang
>            Assignee: Kan Zhang
>         Attachments: 5859-21.patch, 5859-22.patch, 5859-26.patch, 
> 5859-33.patch, 5859-4.patch, 5859-5.patch, 5859-8.patch
>
>
> This JIRA fixes the following warnings:
> SWL   org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.closeInternal() calls 
> Thread.sleep() with a lock held
> TLW   wait() with two locks held in 
> org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.flushInternal()
> TLW   wait() with two locks held in 
> org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.flushInternal()
> TLW   wait() with two locks held in 
> org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.writeChunk(byte[], int, int, 
> byte[])

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to