public abstract class AbstractPendingSetMasterTask<H extends AbstractPendingSetMasterStats<L,? extends AbstractSubtaskStats>,E,S extends AbstractPendingSetSubtask,L> extends AbstractMasterTask<H,E,S,L> implements INotifyOutcome<E,L>
The clients notify the AbstractPendingSetSubtask
as each operation
completes. The subtask notifies the master, which then clears the entry from
its #pendingMap
and also clears the entry from any other subtask that
had been tasked with the same work item (this permits subtasks to terminate
as soon as their work is complete regardless of which subtask actually
performed the work). The master will not terminate until all outstanding
asynchronous operations (the pending set) are complete.
Modifier and Type | Field and Description |
---|---|
protected static org.apache.log4j.Logger |
log
Log may be used to see just success/error reporting for the master
without the log information from the base class.
|
protected INotifyOutcome<E,L> |
masterProxy
A proxy for this class which is used by the client task to send
asynchronous notifications.
|
buffer, sinkIdleTimeoutNanos, sinkPollTimeoutNanos, src, stats
Constructor and Description |
---|
AbstractPendingSetMasterTask(AbstractDistributedFederation<?> fed,
H stats,
BlockingBuffer<E[]> buffer,
long sinkIdleTimeoutNanos,
long sinkPollTimeoutNanos) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
addPending(E e,
AbstractPendingSetSubtask sink,
L locator)
Add a work item to the pending set.
|
protected void |
didFail(E resource,
Throwable cause)
Hook provides notification if all outstanding work requests for the
resource have failed.
|
protected void |
didSucceed(E e)
Hook provides notification the first time work for the resource has been
successfully completed for any set of concurrent outstanding work
requests and may be extended if necessary.
|
void |
error(E resource,
L locator,
Throwable cause)
The resource is removed from the pending set for the sink associated with
that locator.
|
AbstractDistributedFederation<?> |
getFederation() |
protected abstract Map<E,Collection<L>> |
getPendingMap()
Return the pending map.
|
int |
getPendingSetSize() |
protected abstract Map<E,Collection<L>> |
newPendingMap()
Return a new pending map instance.
|
protected boolean |
nothingPending()
Extension hook for implementations where the clients accept work for
asynchronous processing and notify the master as work items completed
successfully or fail.
|
protected boolean |
removePending(E e,
L locator,
Throwable cause)
Remove a work item from the pending set.
|
void |
success(E e,
L locator)
The resource is removed from the
#pendingMap and the pending set
for each sink for which there is an outstanding request for that
resource. |
addToOutputBuffer, call, getBuffer, getRedirectQueueSize, getSink, getStats, handleChunk, mapOperationOverSubtasks, moveSinkToFinishedQueueAtomically, newSubtask, newSubtaskBuffer, notifySubtaskDone, redirectChunk, submitSubtask, willShutdown
halt, halted
protected static final transient org.apache.log4j.Logger log
protected final INotifyOutcome<E,L> masterProxy
public AbstractPendingSetMasterTask(AbstractDistributedFederation<?> fed, H stats, BlockingBuffer<E[]> buffer, long sinkIdleTimeoutNanos, long sinkPollTimeoutNanos)
stats
- buffer
- sinkIdleTimeoutNanos
- sinkPollTimeoutNanos
- public AbstractDistributedFederation<?> getFederation()
protected abstract Map<E,Collection<L>> getPendingMap()
protected final boolean nothingPending()
AbstractMasterTask
AbstractMasterTask
will not terminate
unless this method returns true
when queried while holding
the AbstractMasterTask.lock
. A true return indicates that there are no pending
work items. The default implementation returns true
.
The work perform by the client must be idempotent (it must be safe to re-perform the operation). Pending work items may be in an unknown state, the master may submit the same work item to multiple clients (where that is permitted by the locator semantics), the client task may fail before the work item is complete, and a failed client can cause work items associated with that client to be posted to another client.
To handle master termination, the pending set must track outstanding work items. Those work item should be removed from the pending set as soon as any client has successfully completed that work item (since the work is idempotent).
To handle client failure, the subtask must track the pending set for its
client. If the client dies, then the subtask must handle the client by
placing all pending work items for that client (including any in the
chunk for the current request) onto the AbstractMasterTask.redirectQueue
.
nothingPending
in class AbstractMasterTask<H extends AbstractPendingSetMasterStats<L,? extends AbstractSubtaskStats>,E,S extends AbstractPendingSetSubtask,L>
public final int getPendingSetSize()
protected boolean addPending(E e, AbstractPendingSetSubtask sink, L locator)
Note: This method is written such that a BigdataMap
could be used
as the implementation object. (The tuple is always updated by an insert
when its value's state is changed.)
e
- The work item.locator
- The locator of the subtask/client that will process that work
item.true
iff the pending set did not contain an entry
for that work item. Since entries are cleared from the map when
work is successfully complete or if all pending operations fail
for a work item, a true
return does not
conclusively indicate a new work item.protected boolean removePending(E e, L locator, Throwable cause)
Note: This method is written such that a BigdataMap
could be used
as the implementation object. (The tuple is always updated by an insert
when its value's state is changed.)
e
- The work item.locator
- The subtask / client locator.cause
- null
unless an error is being reported.true
iff the work item was cleared from the
pending set (present on entry but cleared on exit).protected abstract Map<E,Collection<L>> newPendingMap()
BigdataMap
may be used if sufficient RAM is not available.public final void success(E e, L locator)
#pendingMap
and the pending set
for each sink for which there is an outstanding request for that
resource. didSucceed(Object)
will be invoked the first time
a request succeeds for that resource.success
in interface INotifyOutcome<E,L>
e
- The resource identifier.locator
- The client locator.public final void error(E resource, L locator, Throwable cause)
#pendingMap
then the resource is removed from the pending
map as well. didFail(Object, Throwable)
will be invoked if no
requests remain for that resource in the #pendingMap
.error
in interface INotifyOutcome<E,L>
resource
- The resource identifier.locator
- The client locator.cause
- The exception.protected void didSucceed(E e)
protected void didFail(E resource, Throwable cause)
resource
- The resource.cause
- The exception.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.