@InterfaceAudience.Private public class MasterProcedureScheduler extends AbstractProcedureScheduler
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.
AbstractProcedureScheduler.push(Procedure, boolean, boolean)
: A push will add a Queue back to run-queue
when:
AbstractProcedureScheduler.poll(long)
: A poll will remove a Queue from run-queue when:
Modifier and Type | Field and Description |
---|---|
private SchemaLocking |
locking |
private static org.slf4j.Logger |
LOG |
private static AvlUtil.AvlKeyComparator<MetaQueue> |
META_QUEUE_KEY_COMPARATOR |
private MetaQueue |
metaMap |
private FairQueue<TableName> |
metaRunQueue |
private static AvlUtil.AvlKeyComparator<PeerQueue> |
PEER_QUEUE_KEY_COMPARATOR |
private PeerQueue |
peerMap |
private FairQueue<String> |
peerRunQueue |
private static AvlUtil.AvlKeyComparator<ServerQueue> |
SERVER_QUEUE_KEY_COMPARATOR |
private ServerQueue[] |
serverBuckets |
private FairQueue<ServerName> |
serverRunQueue |
private static AvlUtil.AvlKeyComparator<TableQueue> |
TABLE_QUEUE_KEY_COMPARATOR |
private TableQueue |
tableMap |
private FairQueue<TableName> |
tableRunQueue |
Constructor and Description |
---|
MasterProcedureScheduler(Function<Long,Procedure<?>> procedureRetriever) |
Modifier and Type | Method and Description |
---|---|
private static <T extends Comparable<T>> |
addToRunQueue(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>> |
clear(TNode treeMap,
FairQueue<T> fairq,
AvlUtil.AvlKeyComparator<TNode> comparator) |
private void |
clearQueue() |
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>> |
doAdd(FairQueue<T> fairq,
Queue<T> queue,
Procedure<?> proc,
boolean addFront) |
private <T extends Comparable<T>> |
doPoll(FairQueue<T> fairq) |
String |
dumpLocks()
For debugging.
|
protected void |
enqueue(Procedure proc,
boolean addFront)
Add the procedure to the queue.
|
private static int |
getBucketIndex(Object[] buckets,
int hashCode) |
LockedResource |
getLockResource(LockedResourceType resourceType,
String resourceName) |
List<LockedResource> |
getLocks()
List lock queues.
|
private MetaQueue |
getMetaQueue() |
private static String |
getPeerId(Procedure<?> proc) |
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 <T extends Comparable<T>> |
isLockReady(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 |
queueHasRunnables()
Returns true if there are procedures available to process.
|
protected int |
queueSize()
Returns the number of elements in this queue.
|
private int |
queueSize(Queue<?> head) |
private static <T extends Comparable<T>> |
removeFromRunQueue(FairQueue<T> fairq,
Queue<T> queue,
Supplier<String> reason) |
private void |
removePeerQueue(String peerId) |
private void |
removeServerQueue(ServerName serverName) |
private void |
removeTableQueue(TableName tableName) |
private static boolean |
requirePeerExclusiveLock(PeerProcedureInterface proc) |
private void |
tryCleanupPeerQueue(String peerId,
Procedure procedure) |
private void |
tryCleanupServerQueue(ServerName serverName,
Procedure<?> proc) |
boolean |
waitMetaExclusiveLock(Procedure<?> procedure)
Deprecated.
only used for
RecoverMetaProcedure . Should be removed along with
RecoverMetaProcedure . |
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... regionInfo)
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 |
wakeMetaExclusiveLock(Procedure<?> procedure)
Deprecated.
only used for
RecoverMetaProcedure . Should be removed along with
RecoverMetaProcedure . |
void |
wakeNamespaceExclusiveLock(Procedure<?> procedure,
String namespace)
Wake the procedures waiting for the specified namespace
|
void |
wakePeerExclusiveLock(Procedure<?> procedure,
String peerId)
Wake the procedures waiting for the specified peer
|
void |
wakeRegion(Procedure<?> procedure,
RegionInfo regionInfo)
Wake the procedures waiting for the specified region
|
void |
wakeRegions(Procedure<?> procedure,
TableName table,
RegionInfo... regionInfo)
Wake the procedures waiting for the specified regions
|
void |
wakeServerExclusiveLock(Procedure<?> procedure,
ServerName serverName)
Wake the procedures waiting for the specified server
|
void |
wakeTableExclusiveLock(Procedure<?> procedure,
TableName table)
Wake the procedures waiting for the specified table
|
void |
wakeTableSharedLock(Procedure<?> procedure,
TableName table)
Wake the procedures waiting for the specified table
|
void |
yield(Procedure proc)
The procedure can't run at the moment.
|
addBack, addBack, addFront, addFront, addFront, getNullPollCalls, getPollCalls, hasRunnables, poll, poll, poll, push, schedLock, schedUnlock, signalAll, size, start, stop, waitProcedure, wakePollIfNeeded, wakeProcedure, wakeWaitingProcedures
private static final org.slf4j.Logger LOG
private static final AvlUtil.AvlKeyComparator<ServerQueue> SERVER_QUEUE_KEY_COMPARATOR
private static final AvlUtil.AvlKeyComparator<TableQueue> TABLE_QUEUE_KEY_COMPARATOR
private static final AvlUtil.AvlKeyComparator<PeerQueue> PEER_QUEUE_KEY_COMPARATOR
private static final AvlUtil.AvlKeyComparator<MetaQueue> META_QUEUE_KEY_COMPARATOR
private final FairQueue<ServerName> serverRunQueue
private final FairQueue<TableName> tableRunQueue
private final FairQueue<String> peerRunQueue
private final FairQueue<TableName> metaRunQueue
private final ServerQueue[] serverBuckets
private TableQueue tableMap
private final SchemaLocking locking
public MasterProcedureScheduler(Function<Long,Procedure<?>> procedureRetriever)
public void yield(Procedure proc)
ProcedureScheduler
proc
- the Procedure to add back to the listprotected void enqueue(Procedure proc, boolean addFront)
AbstractProcedureScheduler
enqueue
in class AbstractProcedureScheduler
proc
- the Procedure to addaddFront
- true if the item should be added to the front of the queueprivate <T extends Comparable<T>> void doAdd(FairQueue<T> fairq, Queue<T> queue, Procedure<?> proc, boolean addFront)
protected boolean queueHasRunnables()
AbstractProcedureScheduler
queueHasRunnables
in class AbstractProcedureScheduler
protected Procedure dequeue()
AbstractProcedureScheduler
dequeue
in class AbstractProcedureScheduler
private <T extends Comparable<T>> boolean isLockReady(Procedure<?> proc, Queue<T> rq)
private <T extends Comparable<T>> Procedure<?> doPoll(FairQueue<T> fairq)
public List<LockedResource> getLocks()
ProcedureScheduler
public LockedResource getLockResource(LockedResourceType resourceType, String resourceName)
LockedResource
for resource of specified type & name. null if resource is not
locked.public void clear()
ProcedureScheduler
ProcedureExecutor
resets its own state and calls clear() on scheduler.private void clearQueue()
private <T extends Comparable<T>,TNode extends Queue<T>> void clear(TNode treeMap, FairQueue<T> fairq, AvlUtil.AvlKeyComparator<TNode> comparator)
protected int queueSize()
AbstractProcedureScheduler
queueSize
in class AbstractProcedureScheduler
public void completionCleanup(Procedure proc)
ProcedureScheduler
proc
- the Procedure that completed the execution.private static <T extends Comparable<T>> void addToRunQueue(FairQueue<T> fairq, Queue<T> queue, Supplier<String> reason)
private static <T extends Comparable<T>> void removeFromRunQueue(FairQueue<T> fairq, Queue<T> queue, Supplier<String> reason)
private TableQueue getTableQueue(TableName tableName)
private void removeTableQueue(TableName tableName)
private static boolean isTableProcedure(Procedure<?> proc)
private static TableName getTableName(Procedure<?> proc)
private ServerQueue getServerQueue(ServerName serverName, ServerProcedureInterface proc)
private void removeServerQueue(ServerName serverName)
private void tryCleanupServerQueue(ServerName serverName, Procedure<?> proc)
private static int getBucketIndex(Object[] buckets, int hashCode)
private static boolean isServerProcedure(Procedure<?> proc)
private static ServerName getServerName(Procedure<?> proc)
private PeerQueue getPeerQueue(String peerId)
private void removePeerQueue(String peerId)
private void tryCleanupPeerQueue(String peerId, Procedure procedure)
private static boolean isPeerProcedure(Procedure<?> proc)
private MetaQueue getMetaQueue()
private static boolean isMetaProcedure(Procedure<?> proc)
private void logLockedResource(LockedResourceType resourceType, String resourceName)
public boolean waitTableExclusiveLock(Procedure<?> procedure, TableName table)
procedure
- the procedure trying to acquire the locktable
- Table to lockpublic void wakeTableExclusiveLock(Procedure<?> procedure, TableName table)
procedure
- the procedure releasing the locktable
- the name of the table that has the exclusive lockpublic boolean waitTableSharedLock(Procedure<?> procedure, TableName table)
procedure
- the procedure trying to acquire the locktable
- Table to lockprivate TableQueue waitTableQueueSharedLock(Procedure<?> procedure, TableName table)
public void wakeTableSharedLock(Procedure<?> procedure, TableName table)
procedure
- the procedure releasing the locktable
- the name of the table that has the shared lockboolean markTableAsDeleted(TableName table, Procedure<?> procedure)
table
- the name of the table that should be marked as deletedprocedure
- the procedure that is removing the tablepublic boolean waitRegion(Procedure<?> procedure, RegionInfo regionInfo)
procedure
- the procedure trying to acquire the lock on the regionregionInfo
- the region we are trying to lockpublic boolean waitRegions(Procedure<?> procedure, TableName table, RegionInfo... regionInfo)
procedure
- the procedure trying to acquire the lock on the regionstable
- the table name of the regions we are trying to lockregionInfo
- the list of regions we are trying to lockpublic void wakeRegion(Procedure<?> procedure, RegionInfo regionInfo)
procedure
- the procedure that was holding the regionregionInfo
- the region the procedure was holdingpublic void wakeRegions(Procedure<?> procedure, TableName table, RegionInfo... regionInfo)
procedure
- the procedure that was holding the regionsregionInfo
- the list of regions the procedure was holdingpublic boolean waitNamespaceExclusiveLock(Procedure<?> procedure, String namespace)
procedure
- the procedure trying to acquire the locknamespace
- Namespace to lockwakeNamespaceExclusiveLock(Procedure,String)
public void wakeNamespaceExclusiveLock(Procedure<?> procedure, String namespace)
procedure
- the procedure releasing the locknamespace
- the namespace that has the exclusive lockwaitNamespaceExclusiveLock(Procedure,String)
public boolean waitServerExclusiveLock(Procedure<?> procedure, ServerName serverName)
procedure
- the procedure trying to acquire the lockserverName
- Server to lockwakeServerExclusiveLock(Procedure,ServerName)
public void wakeServerExclusiveLock(Procedure<?> procedure, ServerName serverName)
procedure
- the procedure releasing the lockserverName
- the server that has the exclusive lockwaitServerExclusiveLock(Procedure,ServerName)
private static boolean requirePeerExclusiveLock(PeerProcedureInterface proc)
public boolean waitPeerExclusiveLock(Procedure<?> procedure, String peerId)
procedure
- the procedure trying to acquire the lockpeerId
- peer to lockwakePeerExclusiveLock(Procedure, String)
public void wakePeerExclusiveLock(Procedure<?> procedure, String peerId)
procedure
- the procedure releasing the lockpeerId
- the peer that has the exclusive lockwaitPeerExclusiveLock(Procedure, String)
@Deprecated public boolean waitMetaExclusiveLock(Procedure<?> procedure)
RecoverMetaProcedure
. Should be removed along with
RecoverMetaProcedure
.procedure
- the procedure trying to acquire the lockwakeMetaExclusiveLock(Procedure)
@Deprecated public void wakeMetaExclusiveLock(Procedure<?> procedure)
RecoverMetaProcedure
. Should be removed along with
RecoverMetaProcedure
.procedure
- the procedure releasing the lockwaitMetaExclusiveLock(Procedure)
public String dumpLocks() throws IOException
IOException
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.