Class MasterProcedureScheduler
java.lang.Object
org.apache.hadoop.hbase.procedure2.AbstractProcedureScheduler
org.apache.hadoop.hbase.master.procedure.MasterProcedureScheduler
- All Implemented Interfaces:
ProcedureScheduler
ProcedureScheduler for the Master Procedures. This ProcedureScheduler tries to provide to the
ProcedureExecutor procedures that can be executed without having to wait on a lock. Most of the
master operations can be executed concurrently, if they are operating on different tables (e.g.
two create table procedures can be performed at the same time) or against two different servers;
say two servers that crashed at about the same time.
Each procedure should implement an Interface providing information for this queue. For example table related procedures should implement TableProcedureInterface. Each procedure will be pushed in its own queue, and based on the operation type we may make smarter decisions: e.g. we can abort all the operations preceding a delete table, or similar.
Concurrency control
Concurrent access to member variables (tableRunQueue, serverRunQueue, locking, tableMap, serverBuckets) is controlled by schedLock(). This mainly includes:AbstractProcedureScheduler.push(Procedure, boolean, boolean): A push will add a Queue back to run-queue when:- Queue was empty before push (so must have been out of run-queue)
- Child procedure is added (which means parent procedure holds exclusive lock, and it must have moved Queue out of run-queue)
AbstractProcedureScheduler.poll(long): A poll will remove a Queue from run-queue when:- Queue becomes empty after poll
- Exclusive lock is requested by polled procedure and lock is available (returns the procedure)
- Exclusive lock is requested but lock is not available (returns null)
- Polled procedure is child of parent holding exclusive lock and the next procedure is not a child
- Namespace/table/region locks: Queue is added back to run-queue when lock being released is:
- Exclusive lock
- Last shared lock (in case queue was removed because next procedure in queue required exclusive lock)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final AvlUtil.AvlKeyComparator<GlobalQueue>private GlobalQueueprivate final SchemaLockingprivate static final org.slf4j.Loggerprivate static final AvlUtil.AvlKeyComparator<MetaQueue>private MetaQueueprivate static final AvlUtil.AvlKeyComparator<PeerQueue>private PeerQueueprivate static final AvlUtil.AvlKeyComparator<ServerQueue>private final ServerQueue[]private final FairQueue<ServerName>private static final AvlUtil.AvlKeyComparator<TableQueue>private TableQueueprivate final Map<TableName,TableProcedureWaitingQueue> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T extends Comparable<T>>
voidaddToRunQueue(FairQueue<T> fairq, Queue<T> queue, Supplier<String> reason) voidclear()Clear current state of scheduler such that it is equivalent to newly created scheduler.private <T extends Comparable<T>,TNode extends Queue<T>>
voidclear(TNode treeMap, FairQueue<T> fairq, AvlUtil.AvlKeyComparator<TNode> comparator) private voidvoidcompletionCleanup(Procedure proc) The procedure in execution completed.protected Proceduredequeue()Fetch one Procedure from the queue NOTE: this method is called with the sched lock held.private <T extends Comparable<T>>
voidprivate <T extends Comparable<T>>
Procedure<?>For debugging.protected voidAdd the procedure to the queue.private static intgetBucketIndex(Object[] buckets, int hashCode) private static StringgetGlobalId(Procedure<?> proc) private GlobalQueuegetGlobalQueue(String globalId) getLockResource(LockedResourceType resourceType, String resourceName) getLocks()List lock queues.private MetaQueueprivate static Stringprivate PeerQueuegetPeerQueue(String peerId) private static ServerNamegetServerName(Procedure<?> proc) private ServerQueuegetServerQueue(ServerName serverName, ServerProcedureInterface proc) private static TableNamegetTableName(Procedure<?> proc) private TableQueuegetTableQueue(TableName tableName) private static booleanisGlobalProcedure(Procedure<?> proc) private <T extends Comparable<T>>
booleanisLockReady(Procedure<?> proc, Queue<T> rq) private static booleanisMetaProcedure(Procedure<?> proc) private static booleanisPeerProcedure(Procedure<?> proc) private static booleanisServerProcedure(Procedure<?> proc) private static booleanisTableProcedure(Procedure<?> proc) private voidlogLockedResource(LockedResourceType resourceType, String resourceName) Get lock info for a resource of specified type and name and log details(package private) booleanmarkTableAsDeleted(TableName table, Procedure<?> procedure) Tries to remove the queue and the table-lock of the specified table.protected booleanReturns true if there are procedures available to process.protected intReturns the number of elements in this queue.private intprivate static <T extends Comparable<T>>
voidremoveFromRunQueue(FairQueue<T> fairq, Queue<T> queue, Supplier<String> reason) private voidremoveGlobalQueue(String globalId) private voidremovePeerQueue(String peerId) private voidremoveServerQueue(ServerName serverName) private voidremoveTableQueue(TableName tableName) private voidserverBucketToString(org.apache.commons.lang3.builder.ToStringBuilder builder, String queueName, Queue<?> queue) private booleantoString()private voidtryCleanupGlobalQueue(String globalId, Procedure<?> procedure) private voidtryCleanupPeerQueue(String peerId, Procedure<?> procedure) private <T extends Comparable<T>,TNode extends Queue<T>>
booleantryCleanupQueue(T id, Procedure<?> proc, Supplier<TNode> getMap, AvlUtil.AvlKeyComparator<TNode> comparator, Function<T, LockAndQueue> getLock, FairQueue<T> runQueue, Consumer<T> removeQueue) private voidtryCleanupServerQueue(ServerName serverName, Procedure<?> proc) booleanwaitGlobalExclusiveLock(Procedure<?> procedure, String globalId) Try to acquire the share lock on global.booleanwaitMetaExclusiveLock(Procedure<?> procedure) Deprecated.booleanwaitNamespaceExclusiveLock(Procedure<?> procedure, String namespace) Suspend the procedure if the specified namespace is already locked.booleanwaitPeerExclusiveLock(Procedure<?> procedure, String peerId) Try to acquire the exclusive lock on the specified peer.booleanwaitRegion(Procedure<?> procedure, RegionInfo regionInfo) Suspend the procedure if the specified region is already locked.booleanwaitRegions(Procedure<?> procedure, TableName table, RegionInfo... regionInfos) Suspend the procedure if the specified set of regions are already locked.booleanwaitServerExclusiveLock(Procedure<?> procedure, ServerName serverName) Try to acquire the exclusive lock on the specified server.booleanwaitTableExclusiveLock(Procedure<?> procedure, TableName table) Suspend the procedure if the specified table is already locked.private TableQueuewaitTableQueueSharedLock(Procedure<?> procedure, TableName table) booleanwaitTableSharedLock(Procedure<?> procedure, TableName table) Suspend the procedure if the specified table is already locked.voidwakeGlobalExclusiveLock(Procedure<?> procedure, String globalId) Wake the procedures waiting for global.voidwakeMetaExclusiveLock(Procedure<?> procedure) Deprecated.only used forRecoverMetaProcedure.voidwakeNamespaceExclusiveLock(Procedure<?> procedure, String namespace) Wake the procedures waiting for the specified namespacevoidwakePeerExclusiveLock(Procedure<?> procedure, String peerId) Wake the procedures waiting for the specified peervoidwakeRegion(Procedure<?> procedure, RegionInfo regionInfo) Wake the procedures waiting for the specified regionvoidwakeRegions(Procedure<?> procedure, TableName table, RegionInfo... regionInfos) Wake the procedures waiting for the specified regionsvoidwakeServerExclusiveLock(Procedure<?> procedure, ServerName serverName) Wake the procedures waiting for the specified servervoidwakeTableExclusiveLock(Procedure<?> procedure, TableName table) Wake the procedures waiting for the specified tablevoidwakeTableSharedLock(Procedure<?> procedure, TableName table) Wake the procedures waiting for the specified tablevoidThe procedure can't run at the moment.Methods inherited from class org.apache.hadoop.hbase.procedure2.AbstractProcedureScheduler
addBack, addBack, addFront, addFront, addFront, getNullPollCalls, getPollCalls, hasRunnables, poll, poll, poll, push, schedLock, schedUnlock, signalAll, size, start, stop, waitProcedure, wakeEvents, wakePollIfNeeded, wakeProcedure, wakeWaitingProcedures
-
Field Details
-
LOG
-
SERVER_QUEUE_KEY_COMPARATOR
-
TABLE_QUEUE_KEY_COMPARATOR
-
PEER_QUEUE_KEY_COMPARATOR
-
META_QUEUE_KEY_COMPARATOR
-
GLOBAL_QUEUE_KEY_COMPARATOR
-
serverRunQueue
-
tableRunQueue
-
peerRunQueue
-
metaRunQueue
-
globalRunQueue
-
serverBuckets
-
tableMap
-
peerMap
-
metaMap
-
globalMap
-
procedureRetriever
-
locking
-
tableProcsWaitingEnqueue
-
-
Constructor Details
-
MasterProcedureScheduler
-
-
Method Details
-
yield
Description copied from interface:ProcedureSchedulerThe procedure can't run at the moment. add it back to the queue, giving priority to someone else.- Parameters:
proc- the Procedure to add back to the list
-
shouldWaitBeforeEnqueuing
-
enqueue
Description copied from class:AbstractProcedureSchedulerAdd the procedure to the queue. NOTE: this method is called with the sched lock held.- Specified by:
enqueuein classAbstractProcedureScheduler- Parameters:
proc- the Procedure to addaddFront- true if the item should be added to the front of the queue
-
doAdd
private <T extends Comparable<T>> void doAdd(FairQueue<T> fairq, Queue<T> queue, Procedure<?> proc, boolean addFront) -
queueHasRunnables
Description copied from class:AbstractProcedureSchedulerReturns true if there are procedures available to process. NOTE: this method is called with the sched lock held.- Specified by:
queueHasRunnablesin classAbstractProcedureScheduler- Returns:
- true if there are procedures available to process, otherwise false.
-
dequeue
Description copied from class:AbstractProcedureSchedulerFetch one Procedure from the queue NOTE: this method is called with the sched lock held.- Specified by:
dequeuein classAbstractProcedureScheduler- Returns:
- the Procedure to execute, or null if nothing is available.
-
isLockReady
-
doPoll
-
getLocks
Description copied from interface:ProcedureSchedulerList lock queues.- Returns:
- the locks
-
getLockResource
- Returns:
LockedResourcefor resource of specified type & name. null if resource is not locked.
-
clear
Description copied from interface:ProcedureSchedulerClear current state of scheduler such that it is equivalent to newly created scheduler. Used for testing failure and recovery. To emulate server crash/restart,ProcedureExecutorresets its own state and calls clear() on scheduler. -
clearQueue
-
clear
private <T extends Comparable<T>,TNode extends Queue<T>> void clear(TNode treeMap, FairQueue<T> fairq, AvlUtil.AvlKeyComparator<TNode> comparator) -
queueSize
-
queueSize
Description copied from class:AbstractProcedureSchedulerReturns the number of elements in this queue. NOTE: this method is called with the sched lock held.- Specified by:
queueSizein classAbstractProcedureScheduler- Returns:
- the number of elements in this queue.
-
completionCleanup
Description copied from interface:ProcedureSchedulerThe procedure in execution completed. This can be implemented to perform cleanups.- Parameters:
proc- the Procedure that completed the execution.
-
addToRunQueue
private static <T extends Comparable<T>> void addToRunQueue(FairQueue<T> fairq, Queue<T> queue, Supplier<String> reason) -
removeFromRunQueue
private static <T extends Comparable<T>> void removeFromRunQueue(FairQueue<T> fairq, Queue<T> queue, Supplier<String> reason) -
getTableQueue
-
removeTableQueue
-
markTableAsDeleted
Tries to remove the queue and the table-lock of the specified table. If there are new operations pending (e.g. a new create), the remove will not be performed.- Parameters:
table- the name of the table that should be marked as deletedprocedure- the procedure that is removing the table- Returns:
- true if deletion succeeded, false otherwise meaning that there are other new operations pending for that table (e.g. a new create).
-
isTableProcedure
-
getTableName
-
getServerQueue
-
removeServerQueue
-
tryCleanupServerQueue
-
getBucketIndex
-
isServerProcedure
-
getServerName
-
getPeerQueue
-
removePeerQueue
-
tryCleanupPeerQueue
-
isPeerProcedure
-
getPeerId
-
getMetaQueue
-
isMetaProcedure
-
getGlobalQueue
-
removeGlobalQueue
-
tryCleanupGlobalQueue
-
isGlobalProcedure
-
getGlobalId
-
tryCleanupQueue
private <T extends Comparable<T>,TNode extends Queue<T>> boolean tryCleanupQueue(T id, Procedure<?> proc, Supplier<TNode> getMap, AvlUtil.AvlKeyComparator<TNode> comparator, Function<T, LockAndQueue> getLock, FairQueue<T> runQueue, Consumer<T> removeQueue) -
logLockedResource
Get lock info for a resource of specified type and name and log details -
waitTableExclusiveLock
Suspend the procedure if the specified table is already locked. Other operations in the table-queue will be executed after the lock is released.- Parameters:
procedure- the procedure trying to acquire the locktable- Table to lock- Returns:
- true if the procedure has to wait for the table to be available
-
wakeTableExclusiveLock
Wake the procedures waiting for the specified table- Parameters:
procedure- the procedure releasing the locktable- the name of the table that has the exclusive lock
-
waitRegion
Suspend the procedure if the specified region is already locked.- Parameters:
procedure- the procedure trying to acquire the lock on the regionregionInfo- the region we are trying to lock- Returns:
- true if the procedure has to wait for the regions to be available
-
waitRegions
Suspend the procedure if the specified set of regions are already locked.- Parameters:
procedure- the procedure trying to acquire the lock on the regionstable- the table name of the regions we are trying to lockregionInfos- the list of regions we are trying to lock- Returns:
- true if the procedure has to wait for the regions to be available
-
wakeRegion
Wake the procedures waiting for the specified region- Parameters:
procedure- the procedure that was holding the regionregionInfo- the region the procedure was holding
-
wakeRegions
Wake the procedures waiting for the specified regions- Parameters:
procedure- the procedure that was holding the regionsregionInfos- the list of regions the procedure was holding
-
waitNamespaceExclusiveLock
Suspend the procedure if the specified namespace is already locked.- Parameters:
procedure- the procedure trying to acquire the locknamespace- Namespace to lock- Returns:
- true if the procedure has to wait for the namespace to be available
- See Also:
-
wakeNamespaceExclusiveLock
Wake the procedures waiting for the specified namespace- Parameters:
procedure- the procedure releasing the locknamespace- the namespace that has the exclusive lock- See Also:
-
waitServerExclusiveLock
Try to acquire the exclusive lock on the specified server.- Parameters:
procedure- the procedure trying to acquire the lockserverName- Server to lock- Returns:
- true if the procedure has to wait for the server to be available
- See Also:
-
wakeServerExclusiveLock
Wake the procedures waiting for the specified server- Parameters:
procedure- the procedure releasing the lockserverName- the server that has the exclusive lock- See Also:
-
waitPeerExclusiveLock
Try to acquire the exclusive lock on the specified peer.- Parameters:
procedure- the procedure trying to acquire the lockpeerId- peer to lock- Returns:
- true if the procedure has to wait for the peer to be available
- See Also:
-
wakePeerExclusiveLock
Wake the procedures waiting for the specified peer- Parameters:
procedure- the procedure releasing the lockpeerId- the peer that has the exclusive lock- See Also:
-
waitMetaExclusiveLock
Deprecated.only used forRecoverMetaProcedure. Should be removed along withRecoverMetaProcedure.Try to acquire the exclusive lock on meta.- Parameters:
procedure- the procedure trying to acquire the lock- Returns:
- true if the procedure has to wait for meta to be available
- See Also:
-
wakeMetaExclusiveLock
Deprecated.only used forRecoverMetaProcedure. Should be removed along withRecoverMetaProcedure.Wake the procedures waiting for meta.- Parameters:
procedure- the procedure releasing the lock- See Also:
-
waitGlobalExclusiveLock
Try to acquire the share lock on global.- Parameters:
procedure- the procedure trying to acquire the lock- Returns:
- true if the procedure has to wait for global to be available
- See Also:
-
wakeGlobalExclusiveLock
Wake the procedures waiting for global.- Parameters:
procedure- the procedure releasing the lock- See Also:
-
dumpLocks
For debugging. Expensive.- Throws:
IOException
-
serverBucketToString
private void serverBucketToString(org.apache.commons.lang3.builder.ToStringBuilder builder, String queueName, Queue<?> queue) -
toString
- Overrides:
toStringin classAbstractProcedureScheduler
-
RecoverMetaProcedure.