@InterfaceAudience.Private public class Procedure extends Object implements 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)
}
Modifier and Type | Field and Description |
---|---|
(package private) CountDownLatch |
acquiredBarrierLatch
latch for waiting until all members have acquire in barrier state
|
private List<String> |
acquiringMembers |
private byte[] |
args |
(package private) CountDownLatch |
completedLatch
latch for waiting until a procedure has completed
|
private ProcedureCoordinator |
coord |
private HashMap<String,byte[]> |
dataFromFinishedMembers |
private List<String> |
inBarrierMembers |
private Object |
joinBarrierLock
lock to prevent nodes from acquiring and then releasing before we can track them
|
private static org.slf4j.Logger |
LOG |
private ForeignExceptionDispatcher |
monitor
monitor to check for errors
|
private String |
procName |
(package private) CountDownLatch |
releasedBarrierLatch
latch for waiting until all members have executed and released their in barrier state
|
protected TimeoutExceptionInjector |
timeoutInjector |
protected long |
wakeFrequency
frequency to check for errors (ms)
|
Constructor and Description |
---|
Procedure(ProcedureCoordinator coord,
ForeignExceptionDispatcher monitor,
long wakeFreq,
long timeout,
String procName,
byte[] args,
List<String> expectedMembers)
Creates a procedure.
|
Procedure(ProcedureCoordinator coord,
long wakeFreq,
long timeout,
String procName,
byte[] args,
List<String> expectedMembers)
Create a procedure.
|
Modifier and Type | Method and Description |
---|---|
void |
barrierAcquiredByMember(String member)
Call back triggered by an individual member upon successful local barrier acquisition n
|
void |
barrierReleasedByMember(String member,
byte[] dataFromMember)
Call back triggered by a individual member upon successful local in-barrier execution and
release nn
|
Void |
call()
This call is the main execution thread of the barriered procedure.
|
ForeignExceptionDispatcher |
getErrorMonitor()
Get the ForeignExceptionDispatcher
|
String |
getName() |
String |
getStatus()
Returns String of the procedure members both trying to enter the barrier and already in barrier
|
boolean |
isCompleted()
Check if the entire procedure has globally completed, or has been aborted.
|
void |
receive(ForeignException e)
A callback that handles incoming ForeignExceptions.
|
void |
sendGlobalBarrierComplete()
Sends a message to members that all
Subprocedure.insideBarrier() calls have completed. |
void |
sendGlobalBarrierReached()
Sends a message to all members that the global barrier condition has been satisfied.
|
void |
sendGlobalBarrierStart()
Sends a message to Members to create a new
Subprocedure for this Procedure and execute
the Subprocedure.acquireBarrier() step. |
void |
waitForCompleted()
Waits until the entire procedure has globally completed, or has been aborted.
|
HashMap<String,byte[]> |
waitForCompletedWithRet()
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
|
private static final org.slf4j.Logger LOG
private final byte[] args
final CountDownLatch acquiredBarrierLatch
final CountDownLatch releasedBarrierLatch
final CountDownLatch completedLatch
private final ForeignExceptionDispatcher monitor
protected final long wakeFrequency
protected final TimeoutExceptionInjector timeoutInjector
private final Object joinBarrierLock
private final List<String> acquiringMembers
private final List<String> inBarrierMembers
private final HashMap<String,byte[]> dataFromFinishedMembers
private ProcedureCoordinator coord
public Procedure(ProcedureCoordinator coord, ForeignExceptionDispatcher monitor, long wakeFreq, long timeout, String procName, byte[] args, List<String> expectedMembers)
Procedure
state to be run by a
ProcedureCoordinator
.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 memberspublic Procedure(ProcedureCoordinator coord, long wakeFreq, long timeout, String procName, byte[] args, List<String> expectedMembers)
ProcedureCoordinator.createProcedure(ForeignExceptionDispatcher, String, byte[], List)
}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 memberspublic String getStatus()
public ForeignExceptionDispatcher getErrorMonitor()
public final Void call()
public void sendGlobalBarrierStart() throws ForeignException
Subprocedure
for this Procedure and execute
the Subprocedure.acquireBarrier()
step. nForeignException
public void sendGlobalBarrierReached() throws ForeignException
Subprocedure.acquireBarrier()
call successfully. This triggers the member
Subprocedure.insideBarrier()
method. nForeignException
public void sendGlobalBarrierComplete()
Subprocedure.insideBarrier()
calls have completed.
After this executes, the coordinator can assume that any state resources about this barrier
procedure state has been released.public void barrierAcquiredByMember(String member)
public void barrierReleasedByMember(String member, byte[] dataFromMember)
public void waitForCompleted() throws ForeignException, InterruptedException
ForeignException
InterruptedException
public HashMap<String,byte[]> waitForCompletedWithRet() throws ForeignException, InterruptedException
ForeignException
InterruptedException
public boolean isCompleted() throws ForeignException
ForeignException
public void receive(ForeignException e)
receive
in interface ForeignExceptionListener
e
- exception causing the error. Implementations must accept and handle null here.public static void waitForLatch(CountDownLatch latch, ForeignExceptionSnare monitor, long wakeFrequency, String latchDescription) throws ForeignException, InterruptedException
latch
- latch to wait onmonitor
- monitor to check for errors while waitingwakeFrequency
- frequency to wake up and check for errors (in
TimeUnit.MILLISECONDS
)latchDescription
- description of the latch, for loggingForeignException
- type of error the monitor can throw, if the task failsInterruptedException
- if we are interrupted while waiting on latchCopyright © 2007–2020 The Apache Software Foundation. All rights reserved.