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

Heng Chen commented on HBASE-14222:
-----------------------------------

The problem is below:
{code}
1.    if (getValue(oldValAndFlags) == 1) {
2.     synchronized (this) { this.notifyAll(); }
3.    }
{code}
{code}
1.    if (getValue(oldValAndFlags) == 1) return; 
2.    synchronized (this) { this.wait(); }
{code}

there will be problem when wait Thread run to line 2  but lock was acquired by 
notify thread,  the result is wait thread will wait forever.

So we add condition check in wait thread sync block. 
{code}
while(getValue(oldValAndFlags) != 1) {
  this.wait();
}
{code}

when wait thread acquired lock if will check condition first, because notify 
has run, the condition {{getValue(oldValAndFlags) != 1}} will be false.
and wait thread will not wait.



> Improve DrainBarrier
> --------------------
>
>                 Key: HBASE-14222
>                 URL: https://issues.apache.org/jira/browse/HBASE-14222
>             Project: HBase
>          Issue Type: Bug
>          Components: util
>            Reporter: Hiroshi Ikeda
>            Assignee: Hiroshi Ikeda
>            Priority: Minor
>         Attachments: HBASE-14222-V2.patch, HBASE-14222.patch
>
>
> 1. {{DrainBarrier.stopAndDrainOps}} may wait forever if 
> {{DrainBarrier.endOp}} changes its state and calls {{Object.notifyAll}} just 
> before {{stopAndDrainOps}} enters the synchronized block to call 
> {{Object.wait}}. Moreover, {{Object.wait}} may wake up false-positively, and 
> {{stopAndDrainOps}} may break the block before outstanding operations are 
> complete.
> 2. Some tests for {{DrainBarrier}} catch and ignore {{AssertionError}} 
> explicitly thrown JUnit's {{fail}} method.
> The implementation of {{DrainBarrier}} is a little complex, and I'll fix and 
> refactor it.



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

Reply via email to