Class Procedure
- All Implemented Interfaces:
Callable<Void>
,ForeignExceptionListener
All procedures first attempt to reach a barrier point with the sendGlobalBarrierStart()
method. The procedure contacts all members and waits for all subprocedures to execute
Subprocedure.acquireBarrier()
to acquire its local piece of the global barrier and then
send acquisition info back to the coordinator. If all acquisitions at subprocedures succeed, the
coordinator then will call sendGlobalBarrierReached()
. This notifies members to execute
the Subprocedure.insideBarrier()
method. The procedure is blocked until all
Subprocedure.insideBarrier()
executions complete at the members. When
Subprocedure.insideBarrier()
completes at each member, the member sends notification to the
coordinator. Once all members complete, the coordinator calls
sendGlobalBarrierComplete()
.
If errors are encountered remotely, they are forwarded to the coordinator, and
Subprocedure.cleanup(Exception)
is called.
Each Procedure and each Subprocedure enforces a time limit on the execution time. If the time
limit expires before the procedure completes the TimeoutExceptionInjector
will trigger an
ForeignException
to abort the procedure. This is particularly useful for situations when
running a distributed Subprocedure
so participants can avoid blocking for extreme amounts
of time if one of the participants fails or takes a really long time (e.g. GC pause).
Users should generally not directly create or subclass instances of this. They are created for
them implicitly via
ProcedureCoordinator.startProcedure(ForeignExceptionDispatcher, String, byte[], List)
}
-
Field Summary
Modifier and TypeFieldDescription(package private) final CountDownLatch
latch for waiting until all members have acquire in barrier stateprivate final byte[]
(package private) final CountDownLatch
latch for waiting until a procedure has completedprivate ProcedureCoordinator
private final Object
lock to prevent nodes from acquiring and then releasing before we can track themprivate static final org.slf4j.Logger
private final ForeignExceptionDispatcher
monitor to check for errorsprivate final String
(package private) final CountDownLatch
latch for waiting until all members have executed and released their in barrier stateprotected final TimeoutExceptionInjector
protected final long
frequency to check for errors (ms) -
Constructor Summary
ConstructorDescriptionProcedure
(ProcedureCoordinator coord, long wakeFreq, long timeout, String procName, byte[] args, List<String> expectedMembers) Create a procedure.Procedure
(ProcedureCoordinator coord, ForeignExceptionDispatcher monitor, long wakeFreq, long timeout, String procName, byte[] args, List<String> expectedMembers) Creates a procedure. -
Method Summary
Modifier and TypeMethodDescriptionvoid
barrierAcquiredByMember
(String member) Call back triggered by an individual member upon successful local barrier acquisitionvoid
barrierReleasedByMember
(String member, byte[] dataFromMember) Call back triggered by a individual member upon successful local in-barrier execution and releasefinal Void
call()
This call is the main execution thread of the barriered procedure.Get the ForeignExceptionDispatchergetName()
Returns String of the procedure members both trying to enter the barrier and already in barrierboolean
Check if the entire procedure has globally completed, or has been aborted.void
A callback that handles incoming ForeignExceptions.void
Sends a message to members that allSubprocedure.insideBarrier()
calls have completed.void
Sends a message to all members that the global barrier condition has been satisfied.void
Sends a message to Members to create a newSubprocedure
for this Procedure and execute theSubprocedure.acquireBarrier()
step.void
Waits until the entire procedure has globally completed, or has been aborted.Waits until the entire procedure has globally completed, or has been aborted.static void
waitForLatch
(CountDownLatch latch, ForeignExceptionSnare monitor, long wakeFrequency, String latchDescription) Wait for latch to count to zero, ignoring any spurious wake-ups, but waking periodically to check for errors
-
Field Details
-
LOG
-
procName
-
args
-
acquiredBarrierLatch
latch for waiting until all members have acquire in barrier state -
releasedBarrierLatch
latch for waiting until all members have executed and released their in barrier state -
completedLatch
latch for waiting until a procedure has completed -
monitor
monitor to check for errors -
wakeFrequency
frequency to check for errors (ms) -
timeoutInjector
-
joinBarrierLock
lock to prevent nodes from acquiring and then releasing before we can track them -
acquiringMembers
-
inBarrierMembers
-
dataFromFinishedMembers
-
coord
-
-
Constructor Details
-
Procedure
public Procedure(ProcedureCoordinator coord, ForeignExceptionDispatcher monitor, long wakeFreq, long timeout, String procName, byte[] args, List<String> expectedMembers) Creates a procedure. (FOR TESTING)Procedure
state to be run by aProcedureCoordinator
.- Parameters:
coord
- coordinator to call back to for general errors (e.g.ProcedureCoordinator.rpcConnectionFailure(String, IOException)
).monitor
- error monitor to check for external errorswakeFreq
- frequency to check for errors while waitingtimeout
- amount of time to allow the procedure to run before cancellingprocName
- name of the procedure instanceargs
- argument data associated with the procedure instanceexpectedMembers
- names of the expected members
-
Procedure
public Procedure(ProcedureCoordinator coord, long wakeFreq, long timeout, String procName, byte[] args, List<String> expectedMembers) Create a procedure. Users should generally not directly create instances of this. They are created them implicitly viaProcedureCoordinator.createProcedure(ForeignExceptionDispatcher, String, byte[], List)
}- Parameters:
coord
- coordinator to call back to for general errors (e.g.ProcedureCoordinator.rpcConnectionFailure(String, IOException)
).wakeFreq
- frequency to check for errors while waitingtimeout
- amount of time to allow the procedure to run before cancellingprocName
- name of the procedure instanceargs
- argument data associated with the procedure instanceexpectedMembers
- names of the expected members
-
-
Method Details
-
getName
-
getStatus
Returns String of the procedure members both trying to enter the barrier and already in barrier -
getErrorMonitor
Get the ForeignExceptionDispatcher- Returns:
- the Procedure's monitor.
-
call
This call is the main execution thread of the barriered procedure. It sends messages and essentially blocks until all procedure members acquire or later complete but periodically checks for foreign exceptions. -
sendGlobalBarrierStart
Sends a message to Members to create a newSubprocedure
for this Procedure and execute theSubprocedure.acquireBarrier()
step.- Throws:
ForeignException
-
sendGlobalBarrierReached
Sends a message to all members that the global barrier condition has been satisfied. This should only be executed after all members have completed itsSubprocedure.acquireBarrier()
call successfully. This triggers the memberSubprocedure.insideBarrier()
method.- Throws:
ForeignException
-
sendGlobalBarrierComplete
Sends a message to members that allSubprocedure.insideBarrier()
calls have completed. After this executes, the coordinator can assume that any state resources about this barrier procedure state has been released. -
barrierAcquiredByMember
Call back triggered by an individual member upon successful local barrier acquisition -
barrierReleasedByMember
Call back triggered by a individual member upon successful local in-barrier execution and release -
waitForCompleted
Waits until the entire procedure has globally completed, or has been aborted. If an exception is thrown the procedure may or not have run cleanup to trigger the completion latch yet.- Throws:
ForeignException
InterruptedException
-
waitForCompletedWithRet
public HashMap<String,byte[]> waitForCompletedWithRet() throws ForeignException, InterruptedExceptionWaits until the entire procedure has globally completed, or has been aborted. If an exception is thrown the procedure may or not have run cleanup to trigger the completion latch yet.- Returns:
- data returned from procedure members upon successfully completing subprocedure.
- Throws:
ForeignException
InterruptedException
-
isCompleted
Check if the entire procedure has globally completed, or has been aborted.- Throws:
ForeignException
-
receive
A callback that handles incoming ForeignExceptions.- Specified by:
receive
in interfaceForeignExceptionListener
- Parameters:
e
- exception causing the error. Implementations must accept and handle null here.
-
waitForLatch
public static void waitForLatch(CountDownLatch latch, ForeignExceptionSnare monitor, long wakeFrequency, String latchDescription) throws ForeignException, InterruptedException Wait for latch to count to zero, ignoring any spurious wake-ups, but waking periodically to check for errors- Parameters:
latch
- latch to wait onmonitor
- monitor to check for errors while waitingwakeFrequency
- frequency to wake up and check for errors (inTimeUnit.MILLISECONDS
)latchDescription
- description of the latch, for logging- Throws:
ForeignException
- type of error the monitor can throw, if the task failsInterruptedException
- if we are interrupted while waiting on latch
-