[ 
https://issues.apache.org/jira/browse/HBASE-22486?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Guanghao Zhang updated HBASE-22486:
-----------------------------------
    Description: 
When the LockProcedure was scheduled. It will called TimeoutExecutorThread#add 
method.
{code:java}
public void add(Procedure<TEnvironment> procedure) {
  assert procedure.getState() == ProcedureState.WAITING_TIMEOUT;
  LOG.info("ADDED {}; timeout={}, timestamp={}", procedure, 
procedure.getTimeout(),
    procedure.getTimeoutTimestamp());
  queue.add(new DelayedProcedure<>(procedure));
}
{code}
But LockProcedure's unlock method may called before it was scheduled. And it 
will change the state to RUNNABLE. This will make the assert error.
{code:java}
// Can be called before procedure gets scheduled, in which case, the execute() 
will finish
// immediately and release the underlying locks.
public void unlock(final MasterProcedureEnv env) {
  unlock.set(true);
  locked.set(false);
  // Maybe timeout already awakened the event and the procedure has finished.
  synchronized (event) {
    if (!event.isReady()) {
      LOG.info("Update procedure {} state to RUNNABLE", this);
      setState(ProcedureProtos.ProcedureState.RUNNABLE);
      event.wake(env.getProcedureScheduler());
    }
  }
}
{code}

> Fix flaky test TestLockManager
> ------------------------------
>
>                 Key: HBASE-22486
>                 URL: https://issues.apache.org/jira/browse/HBASE-22486
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Guanghao Zhang
>            Assignee: Guanghao Zhang
>            Priority: Major
>
> When the LockProcedure was scheduled. It will called 
> TimeoutExecutorThread#add method.
> {code:java}
> public void add(Procedure<TEnvironment> procedure) {
>   assert procedure.getState() == ProcedureState.WAITING_TIMEOUT;
>   LOG.info("ADDED {}; timeout={}, timestamp={}", procedure, 
> procedure.getTimeout(),
>     procedure.getTimeoutTimestamp());
>   queue.add(new DelayedProcedure<>(procedure));
> }
> {code}
> But LockProcedure's unlock method may called before it was scheduled. And it 
> will change the state to RUNNABLE. This will make the assert error.
> {code:java}
> // Can be called before procedure gets scheduled, in which case, the 
> execute() will finish
> // immediately and release the underlying locks.
> public void unlock(final MasterProcedureEnv env) {
>   unlock.set(true);
>   locked.set(false);
>   // Maybe timeout already awakened the event and the procedure has finished.
>   synchronized (event) {
>     if (!event.isReady()) {
>       LOG.info("Update procedure {} state to RUNNABLE", this);
>       setState(ProcedureProtos.ProcedureState.RUNNABLE);
>       event.wake(env.getProcedureScheduler());
>     }
>   }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to