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
Modifier and TypeFieldDescriptionprivate static final AvlUtil.AvlKeyComparator<GlobalQueue>
private GlobalQueue
private final SchemaLocking
private static final org.slf4j.Logger
private static final AvlUtil.AvlKeyComparator<MetaQueue>
private MetaQueue
private static final AvlUtil.AvlKeyComparator<PeerQueue>
private PeerQueue
private static final AvlUtil.AvlKeyComparator<ServerQueue>
private final ServerQueue[]
private final FairQueue<ServerName>
private static final AvlUtil.AvlKeyComparator<TableQueue>
private TableQueue
private final Map<TableName,
TableProcedureWaitingQueue> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate static <T extends Comparable<T>>
voidaddToRunQueue
(FairQueue<T> fairq, Queue<T> queue, Supplier<String> reason) void
clear()
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 void
void
completionCleanup
(Procedure proc) The procedure in execution completed.protected Procedure
dequeue()
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 void
Add the procedure to the queue.private static int
getBucketIndex
(Object[] buckets, int hashCode) private static String
getGlobalId
(Procedure<?> proc) private GlobalQueue
getGlobalQueue
(String globalId) getLockResource
(LockedResourceType resourceType, String resourceName) getLocks()
List lock queues.private MetaQueue
private static String
private PeerQueue
getPeerQueue
(String peerId) private static ServerName
getServerName
(Procedure<?> proc) private ServerQueue
getServerQueue
(ServerName serverName, ServerProcedureInterface proc) private static TableName
getTableName
(Procedure<?> proc) private TableQueue
getTableQueue
(TableName tableName) private static boolean
isGlobalProcedure
(Procedure<?> proc) private <T extends Comparable<T>>
booleanisLockReady
(Procedure<?> proc, Queue<T> rq) private static boolean
isMetaProcedure
(Procedure<?> proc) private static boolean
isPeerProcedure
(Procedure<?> proc) private static boolean
isServerProcedure
(Procedure<?> proc) private static boolean
isTableProcedure
(Procedure<?> proc) private void
logLockedResource
(LockedResourceType resourceType, String resourceName) Get lock info for a resource of specified type and name and log details(package private) boolean
markTableAsDeleted
(TableName table, Procedure<?> procedure) Tries to remove the queue and the table-lock of the specified table.protected boolean
Returns true if there are procedures available to process.protected int
Returns the number of elements in this queue.private int
private static <T extends Comparable<T>>
voidremoveFromRunQueue
(FairQueue<T> fairq, Queue<T> queue, Supplier<String> reason) private void
removeGlobalQueue
(String globalId) private void
removePeerQueue
(String peerId) private void
removeServerQueue
(ServerName serverName) private void
removeTableQueue
(TableName tableName) private void
serverBucketToString
(org.apache.commons.lang3.builder.ToStringBuilder builder, String queueName, Queue<?> queue) private boolean
toString()
private void
tryCleanupGlobalQueue
(String globalId, Procedure<?> procedure) private void
tryCleanupPeerQueue
(String peerId, Procedure<?> procedure) private void
tryCleanupServerQueue
(ServerName serverName, Procedure<?> proc) boolean
waitGlobalExclusiveLock
(Procedure<?> procedure, String globalId) Try to acquire the share lock on global.boolean
waitMetaExclusiveLock
(Procedure<?> procedure) Deprecated.boolean
waitNamespaceExclusiveLock
(Procedure<?> procedure, String namespace) Suspend the procedure if the specified namespace is already locked.boolean
waitPeerExclusiveLock
(Procedure<?> procedure, String peerId) Try to acquire the exclusive lock on the specified peer.boolean
waitRegion
(Procedure<?> procedure, RegionInfo regionInfo) Suspend the procedure if the specified region is already locked.boolean
waitRegions
(Procedure<?> procedure, TableName table, RegionInfo... regionInfos) Suspend the procedure if the specified set of regions are already locked.boolean
waitServerExclusiveLock
(Procedure<?> procedure, ServerName serverName) Try to acquire the exclusive lock on the specified server.boolean
waitTableExclusiveLock
(Procedure<?> procedure, TableName table) Suspend the procedure if the specified table is already locked.private TableQueue
waitTableQueueSharedLock
(Procedure<?> procedure, TableName table) boolean
waitTableSharedLock
(Procedure<?> procedure, TableName table) Suspend the procedure if the specified table is already locked.void
wakeGlobalExclusiveLock
(Procedure<?> procedure, String globalId) Wake the procedures waiting for global.void
wakeMetaExclusiveLock
(Procedure<?> procedure) Deprecated.only used forRecoverMetaProcedure
.void
wakeNamespaceExclusiveLock
(Procedure<?> procedure, String namespace) Wake the procedures waiting for the specified namespacevoid
wakePeerExclusiveLock
(Procedure<?> procedure, String peerId) Wake the procedures waiting for the specified peervoid
wakeRegion
(Procedure<?> procedure, RegionInfo regionInfo) Wake the procedures waiting for the specified regionvoid
wakeRegions
(Procedure<?> procedure, TableName table, RegionInfo... regionInfos) Wake the procedures waiting for the specified regionsvoid
wakeServerExclusiveLock
(Procedure<?> procedure, ServerName serverName) Wake the procedures waiting for the specified servervoid
wakeTableExclusiveLock
(Procedure<?> procedure, TableName table) Wake the procedures waiting for the specified tablevoid
wakeTableSharedLock
(Procedure<?> procedure, TableName table) Wake the procedures waiting for the specified tablevoid
The 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:ProcedureScheduler
The 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:AbstractProcedureScheduler
Add the procedure to the queue. NOTE: this method is called with the sched lock held.- Specified by:
enqueue
in 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:AbstractProcedureScheduler
Returns true if there are procedures available to process. NOTE: this method is called with the sched lock held.- Specified by:
queueHasRunnables
in classAbstractProcedureScheduler
- Returns:
- true if there are procedures available to process, otherwise false.
-
dequeue
Description copied from class:AbstractProcedureScheduler
Fetch one Procedure from the queue NOTE: this method is called with the sched lock held.- Specified by:
dequeue
in classAbstractProcedureScheduler
- Returns:
- the Procedure to execute, or null if nothing is available.
-
isLockReady
-
doPoll
-
getLocks
Description copied from interface:ProcedureScheduler
List lock queues.- Returns:
- the locks
-
getLockResource
- Returns:
LockedResource
for resource of specified type & name. null if resource is not locked.
-
clear
Description copied from interface:ProcedureScheduler
Clear current state of scheduler such that it is equivalent to newly created scheduler. Used for testing failure and recovery. To emulate server crash/restart,ProcedureExecutor
resets 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:AbstractProcedureScheduler
Returns the number of elements in this queue. NOTE: this method is called with the sched lock held.- Specified by:
queueSize
in classAbstractProcedureScheduler
- Returns:
- the number of elements in this queue.
-
completionCleanup
Description copied from interface:ProcedureScheduler
The 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
-
isTableProcedure
-
getTableName
-
getServerQueue
-
removeServerQueue
-
tryCleanupServerQueue
-
getBucketIndex
-
isServerProcedure
-
getServerName
-
getPeerQueue
-
removePeerQueue
-
tryCleanupPeerQueue
-
isPeerProcedure
-
getPeerId
-
getMetaQueue
-
isMetaProcedure
-
getGlobalQueue
-
removeGlobalQueue
-
tryCleanupGlobalQueue
-
isGlobalProcedure
-
getGlobalId
-
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
-
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).
-
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:
toString
in classAbstractProcedureScheduler
-
RecoverMetaProcedure
.