Class RegionStateNodeLock
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static interface
This is for abstraction the common lock/unlock logic for both Thread and Procedure. -
Field Summary
Modifier and TypeFieldDescriptionprivate int
private final Lock
private Object
private final RegionInfo
private final Queue<RegionStateNodeLock.QueueEntry>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription(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 givenlockBy
.(package private) void
lock()
Normal lock, will set the current thread as owner.(package private) void
Lock by a procedure.private void
(package private) boolean
tryLock()
Normal tryLock, will set the current thread as owner.(package private) boolean
TryLock by a procedure.private boolean
(package private) void
unlock()
Normal unLock, will use the current thread as owner.(package private) void
Unlock by a procedure.private void
-
Field Details
-
regionInfo
-
lock
-
waitingQueue
-
owner
-
count
-
-
Constructor Details
-
RegionStateNodeLock
RegionStateNodeLock(RegionInfo regionInfo)
-
-
Method Details
-
lock0
- Throws:
ProcedureSuspendedException
-
tryLock0
-
unlock0
-
lock
void lock()Normal lock, will set the current thread as owner. Typically you should use try...finally to call unlock in the finally block. -
tryLock
boolean tryLock()Normal tryLock, will set the current thread as owner. Typically you should use try...finally to call unlock in the finally block. -
unlock
void unlock()Normal unLock, will use the current thread as owner. Typically you should use try...finally to call unlock in the finally block. -
lock
Lock by a procedure. You can release the lock in another thread.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 thewakeUp
action you should add the procedure back to procedure scheduler.- Throws:
ProcedureSuspendedException
-
tryLock
TryLock by a procedure. You can release the lock in another thread. -
unlock
Unlock by a procedure. You do not need to call this method in the same thread with lock. -
isLocked
boolean isLocked()Check whether the lock is locked by someone. -
isLockedBy
Check whether the lock is locked by the givenlockBy
.
-