@InterfaceAudience.Private @InterfaceStability.Evolving public class ProcedureExecutor<TEnvironment> extends Object
Modifier and Type | Class and Description |
---|---|
private static class |
ProcedureExecutor.CompletedProcedureCleaner<TEnvironment>
Internal cleaner that removes the completed procedure results after a TTL.
|
static interface |
ProcedureExecutor.ProcedureExecutorListener |
private static class |
ProcedureExecutor.ProcedureTimeoutRetriever
Used by the TimeoutBlockingQueue to get the timeout interval of the procedure
|
static class |
ProcedureExecutor.Testing |
Modifier and Type | Field and Description |
---|---|
private AtomicInteger |
activeExecutorCount |
private ConcurrentHashMap<Long,ProcedureInfo> |
completed
Map the the procId returned by submitProcedure(), the Root-ProcID, to the ProcedureInfo.
|
private org.apache.hadoop.conf.Configuration |
conf |
private TEnvironment |
environment |
private AtomicLong |
lastProcId |
private CopyOnWriteArrayList<ProcedureExecutor.ProcedureExecutorListener> |
listeners |
private static org.apache.commons.logging.Log |
LOG |
private ConcurrentHashMap<NonceKey,Long> |
nonceKeysToProcIdsMap
Helper map to lookup whether the procedure already issued from the same client.
|
private ConcurrentHashMap<Long,Procedure> |
procedures
Helper map to lookup the live procedures by ID.
|
private ConcurrentHashMap<Long,RootProcedureState> |
rollbackStack
Map the the procId returned by submitProcedure(), the Root-ProcID, to the RootProcedureState.
|
private ProcedureRunnableSet |
runnables
Queue that contains runnable procedures.
|
private AtomicBoolean |
running |
private ProcedureStore |
store |
private ReentrantLock |
submitLock |
(package private) ProcedureExecutor.Testing |
testing |
private Thread[] |
threads |
private TimeoutBlockingQueue<Procedure> |
waitingTimeout
Timeout Queue that contains Procedures in a WAITING_TIMEOUT state
or periodic procedures.
|
Constructor and Description |
---|
ProcedureExecutor(org.apache.hadoop.conf.Configuration conf,
TEnvironment environment,
ProcedureStore store) |
ProcedureExecutor(org.apache.hadoop.conf.Configuration conf,
TEnvironment environment,
ProcedureStore store,
ProcedureRunnableSet runqueue) |
Modifier and Type | Method and Description |
---|---|
boolean |
abort(long procId)
Send an abort notification the specified procedure.
|
boolean |
abort(long procId,
boolean mayInterruptIfRunning)
Send an abort notification the specified procedure.
|
NonceKey |
createNonceKey(long nonceGroup,
long nonce)
Create a NoneKey from the specified nonceGroup and nonce.
|
private void |
execLoop()
Execution loop (N threads)
while the executor is in a running state,
fetch a procedure from the runnables queue and start the execution.
|
private void |
execLoop(Procedure proc) |
private void |
execProcedure(RootProcedureState procStack,
Procedure procedure)
Executes the specified procedure
- calls the doExecute() of the procedure
- if the procedure execution didn't fail (e.g.
|
private boolean |
executeRollback(long rootProcId,
RootProcedureState procStack)
Execute the rollback of the full procedure stack.
|
private boolean |
executeRollback(Procedure proc)
Execute the rollback of the procedure step.
|
int |
getActiveExecutorCount() |
TEnvironment |
getEnvironment() |
int |
getNumThreads() |
Procedure |
getProcedure(long procId) |
ProcedureInfo |
getResult(long procId) |
Pair<ProcedureInfo,Procedure> |
getResultOrProcedure(long procId) |
Map<Long,ProcedureInfo> |
getResults() |
private Long |
getRootProcedureId(Procedure proc) |
protected ProcedureRunnableSet |
getRunnableSet() |
ProcedureStore |
getStore() |
private void |
handleInterruptedException(Procedure proc,
InterruptedException e) |
boolean |
isFinished(long procId)
Return true if the procedure is finished.
|
boolean |
isProcedureOwner(long procId,
User user)
Check if the user is this procedure's owner
|
boolean |
isRunning() |
boolean |
isStarted(long procId)
Return true if the procedure is started.
|
void |
join() |
List<ProcedureInfo> |
listProcedures()
List procedures.
|
private void |
load(boolean abortOnCorruption) |
private void |
loadProcedures(ProcedureStore.ProcedureIterator procIter,
boolean abortOnCorruption) |
private long |
nextProcId() |
private void |
procedureFinished(Procedure proc) |
void |
registerListener(ProcedureExecutor.ProcedureExecutorListener listener) |
long |
registerNonce(NonceKey nonceKey)
Register a nonce for a procedure that is going to be submitted.
|
void |
removeResult(long procId)
Mark the specified completed procedure, as ready to remove.
|
private void |
sendProcedureAddedNotification(long procId) |
private void |
sendProcedureFinishedNotification(long procId) |
private void |
sendProcedureLoadedNotification(long procId) |
void |
setFailureResultForNonce(NonceKey nonceKey,
String procName,
User procOwner,
IOException exception)
If the failure failed before submitting it, we may want to give back the
same error to the requests with the same nonceKey.
|
void |
start(int numThreads,
boolean abortOnCorruption)
Start the procedure executor.
|
void |
stop() |
long |
submitProcedure(Procedure proc)
>>>>>>> ce33cf2...
|
long |
submitProcedure(Procedure proc,
NonceKey nonceKey)
Add a new root-procedure to the executor.
|
private void |
timeoutLoop() |
boolean |
unregisterListener(ProcedureExecutor.ProcedureExecutorListener listener) |
void |
unregisterNonceIfProcedureWasNotSubmitted(NonceKey nonceKey)
Remove the NonceKey if the procedure was not submitted to the executor.
|
private static final org.apache.commons.logging.Log LOG
ProcedureExecutor.Testing testing
private final ConcurrentHashMap<Long,ProcedureInfo> completed
private final ConcurrentHashMap<Long,RootProcedureState> rollbackStack
private final ConcurrentHashMap<Long,Procedure> procedures
private ConcurrentHashMap<NonceKey,Long> nonceKeysToProcIdsMap
private final TimeoutBlockingQueue<Procedure> waitingTimeout
private final ProcedureRunnableSet runnables
private final ReentrantLock submitLock
private final AtomicLong lastProcId
private final CopyOnWriteArrayList<ProcedureExecutor.ProcedureExecutorListener> listeners
private final AtomicInteger activeExecutorCount
private final AtomicBoolean running
private final TEnvironment environment
private final ProcedureStore store
private final org.apache.hadoop.conf.Configuration conf
private Thread[] threads
public ProcedureExecutor(org.apache.hadoop.conf.Configuration conf, TEnvironment environment, ProcedureStore store)
public ProcedureExecutor(org.apache.hadoop.conf.Configuration conf, TEnvironment environment, ProcedureStore store, ProcedureRunnableSet runqueue)
private void load(boolean abortOnCorruption) throws IOException
IOException
private void loadProcedures(ProcedureStore.ProcedureIterator procIter, boolean abortOnCorruption) throws IOException
IOException
public void start(int numThreads, boolean abortOnCorruption) throws IOException
numThreads
- number of threads available for procedure execution.abortOnCorruption
- true if you want to abort your service in case
a corrupted procedure is found on replay. otherwise false.IOException
public void stop()
public void join()
public boolean isRunning()
public int getNumThreads()
public int getActiveExecutorCount()
public TEnvironment getEnvironment()
public ProcedureStore getStore()
public void registerListener(ProcedureExecutor.ProcedureExecutorListener listener)
public boolean unregisterListener(ProcedureExecutor.ProcedureExecutorListener listener)
public List<ProcedureInfo> listProcedures()
public NonceKey createNonceKey(long nonceGroup, long nonce)
nonceGroup
- nonce
- public long registerNonce(NonceKey nonceKey)
nonceKey
- A unique identifier for this operation from the client or process.public void unregisterNonceIfProcedureWasNotSubmitted(NonceKey nonceKey)
nonceKey
- A unique identifier for this operation from the client or process.public void setFailureResultForNonce(NonceKey nonceKey, String procName, User procOwner, IOException exception)
nonceKey
- A unique identifier for this operation from the client or processprocName
- name of the procedure, used to inform the userprocOwner
- name of the owner of the procedure, used to inform the userexception
- the failure to report to the userpublic long submitProcedure(Procedure proc)
proc
- the new procedure to execute.public long submitProcedure(Procedure proc, NonceKey nonceKey)
proc
- the new procedure to execute.nonceKey
- the registered unique identifier for this operation from the client or process.public ProcedureInfo getResult(long procId)
public boolean isFinished(long procId)
procId
- the ID of the procedure to checkpublic boolean isStarted(long procId)
procId
- the ID of the procedure to checkpublic void removeResult(long procId)
procId
- the ID of the procedure to removepublic boolean abort(long procId)
procId
- the procedure to abortpublic boolean abort(long procId, boolean mayInterruptIfRunning)
procId
- the procedure to abortmayInterruptIfRunning
- if the proc completed at least one step, should it be aborted?public boolean isProcedureOwner(long procId, User user)
procId
- the target procedureuser
- the userpublic Map<Long,ProcedureInfo> getResults()
public Procedure getProcedure(long procId)
protected ProcedureRunnableSet getRunnableSet()
private void execLoop()
private void execLoop(Procedure proc)
private void timeoutLoop()
private boolean executeRollback(long rootProcId, RootProcedureState procStack)
private boolean executeRollback(Procedure proc)
private void execProcedure(RootProcedureState procStack, Procedure procedure)
private void handleInterruptedException(Procedure proc, InterruptedException e)
private void sendProcedureLoadedNotification(long procId)
private void sendProcedureAddedNotification(long procId)
private void sendProcedureFinishedNotification(long procId)
private long nextProcId()
private void procedureFinished(Procedure proc)
public Pair<ProcedureInfo,Procedure> getResultOrProcedure(long procId)
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.