@InterfaceAudience.Private class RegionStateNodeLock extends Object
This is because we need to hold region state node lock while updating region state to meta(for keeping consistency), so it is better to yield the procedure to release the procedure worker. But after waking up the procedure, we may use another procedure worker to execute the procedure, which means we need to unlock by another thread.
For locking by procedure, we will also suspend the procedure if the lock is not ready, and schedule it again when lock is ready. This is very important to not block the PEWorker as we may hold the lock when updating meta, which could take a lot of time.
Please see HBASE-28196 for more details.
Modifier and Type | Class and Description |
---|---|
private static interface |
RegionStateNodeLock.QueueEntry
This is for abstraction the common lock/unlock logic for both Thread and Procedure.
|
Modifier and Type | Field and Description |
---|---|
private int |
count |
private Lock |
lock |
private Object |
owner |
private RegionInfo |
regionInfo |
private Queue<RegionStateNodeLock.QueueEntry> |
waitingQueue |
Constructor and Description |
---|
RegionStateNodeLock(RegionInfo regionInfo) |
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
isLocked()
Check whether the lock is locked by someone.
|
(package private) boolean |
isLockedBy(Object lockBy)
Check whether the lock is locked by the given
lockBy . |
(package private) void |
lock()
Normal lock, will set the current thread as owner.
|
(package private) void |
lock(Procedure<?> proc,
Runnable wakeUp)
Lock by a procedure.
|
private void |
lock0(RegionStateNodeLock.QueueEntry entry) |
(package private) boolean |
tryLock()
Normal tryLock, will set the current thread as owner.
|
(package private) boolean |
tryLock(Procedure<?> proc)
TryLock by a procedure.
|
private boolean |
tryLock0(Object lockBy) |
(package private) void |
unlock()
Normal unLock, will use the current thread as owner.
|
(package private) void |
unlock(Procedure<?> proc)
Unlock by a procedure.
|
private void |
unlock0(Object unlockBy) |
private final RegionInfo regionInfo
private final Queue<RegionStateNodeLock.QueueEntry> waitingQueue
private int count
RegionStateNodeLock(RegionInfo regionInfo)
private void lock0(RegionStateNodeLock.QueueEntry entry) throws ProcedureSuspendedException
ProcedureSuspendedException
void lock()
boolean tryLock()
void unlock()
void lock(Procedure<?> proc, Runnable wakeUp) throws ProcedureSuspendedException
When the procedure can not get the lock immediately, a ProcedureSuspendedException will be
thrown to suspend the procedure. And when we want to wake up a procedure, we will call the
wakeUp
action. Usually in the wakeUp
action you should add the procedure back
to procedure scheduler.
ProcedureSuspendedException
boolean tryLock(Procedure<?> proc)
void unlock(Procedure<?> proc)
boolean isLocked()
boolean isLockedBy(Object lockBy)
lockBy
.Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.