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
Nested ClassesModifier and TypeClassDescriptionprivate static interfaceThis is for abstraction the common lock/unlock logic for both Thread and Procedure. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate final Lockprivate Objectprivate final RegionInfoprivate final Queue<RegionStateNodeLock.QueueEntry> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) booleanisLocked()Check whether the lock is locked by someone.(package private) booleanisLockedBy(Object lockBy) Check whether the lock is locked by the givenlockBy.(package private) voidlock()Normal lock, will set the current thread as owner.(package private) voidLock by a procedure.private void(package private) booleantryLock()Normal tryLock, will set the current thread as owner.(package private) booleanTryLock by a procedure.private boolean(package private) voidunlock()Normal unLock, will use the current thread as owner.(package private) voidUnlock 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
wakeUpaction. Usually in thewakeUpaction 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.
-