ACKID
- Type of Ids to acknowledgepublic class AcknowledgeOnCheckpoint<ACKID extends Serializable> extends Object implements CheckpointListener, ListCheckpointed<AcknowledgeIdsForCheckpoint<ACKID>>
The mechanism for this source assumes that messages are identified by a unique ID. When messages are taken from the message queue, the message must not be dropped immediately from the external system, but must be retained until acknowledged. Messages that are not acknowledged within a certain time interval will be served again (to a different connection, established by the recovered source).
Note that this source can give no guarantees about message order in the case of failures, because messages that were retrieved but not yet acknowledged will be returned later again, after a set of messages that was not retrieved before the failure.
Internally, this class gathers the IDs of elements it emits. Per checkpoint, the IDs are stored and acknowledged when the checkpoint is complete. That way, no message is acknowledged unless it is certain that it has been successfully processed throughout the topology and the updates to any state caused by that message are persistent.
Constructor and Description |
---|
AcknowledgeOnCheckpoint(Acknowledger<ACKID> acknowledger) |
Modifier and Type | Method and Description |
---|---|
void |
addAcknowledgeId(ACKID id) |
void |
notifyCheckpointAborted(long checkpointId)
This method is called as a notification once a distributed checkpoint has been aborted.
|
void |
notifyCheckpointComplete(long checkpointId)
Notifies the listener that the checkpoint with the given
checkpointId completed and
was committed. |
int |
numberOfOutstandingAcknowledgements() |
void |
restoreState(List<AcknowledgeIdsForCheckpoint<ACKID>> state)
Restores the state of the function or operator to that of a previous checkpoint.
|
List<AcknowledgeIdsForCheckpoint<ACKID>> |
snapshotState(long checkpointId,
long timestamp)
Gets the current state of the function.
|
public AcknowledgeOnCheckpoint(Acknowledger<ACKID> acknowledger)
public void addAcknowledgeId(ACKID id)
public void notifyCheckpointComplete(long checkpointId)
CheckpointListener
checkpointId
completed and
was committed.
These notifications are "best effort", meaning they can sometimes be skipped. To behave
properly, implementers need to follow the "Checkpoint Subsuming Contract". Please see the
class-level JavaDocs
for details.
Please note that checkpoints may generally overlap, so you cannot assume that the notifyCheckpointComplete()
call is always for the latest prior checkpoint (or snapshot) that
was taken on the function/operator implementing this interface. It might be for a checkpoint
that was triggered earlier. Implementing the "Checkpoint Subsuming Contract" (see above)
properly handles this situation correctly as well.
Please note that throwing exceptions from this method will not cause the completed checkpoint to be revoked. Throwing exceptions will typically cause task/job failure and trigger recovery.
notifyCheckpointComplete
in interface CheckpointListener
checkpointId
- The ID of the checkpoint that has been completed.public void notifyCheckpointAborted(long checkpointId)
CheckpointListener
Important: The fact that a checkpoint has been aborted does NOT mean that the data
and artifacts produced between the previous checkpoint and the aborted checkpoint are to be
discarded. The expected behavior is as if this checkpoint was never triggered in the first
place, and the next successful checkpoint simply covers a longer time span. See the
"Checkpoint Subsuming Contract" in the class-level JavaDocs
for
details.
These notifications are "best effort", meaning they can sometimes be skipped.
This method is very rarely necessary to implement. The "best effort" guarantee, together with the fact that this method should not result in discarding any data (per the "Checkpoint Subsuming Contract") means it is mainly useful for earlier cleanups of auxiliary resources. One example is to pro-actively clear a local per-checkpoint state cache upon checkpoint failure.
notifyCheckpointAborted
in interface CheckpointListener
checkpointId
- The ID of the checkpoint that has been aborted.public List<AcknowledgeIdsForCheckpoint<ACKID>> snapshotState(long checkpointId, long timestamp)
ListCheckpointed
The returned list should contain one entry for redistributable unit of state. See the
class docs
for an illustration how list-style state redistribution
works.
As special case, the returned list may be null or empty (if the operator has no state) or it may contain a single element (if the operator state is indivisible).
snapshotState
in interface ListCheckpointed<AcknowledgeIdsForCheckpoint<ACKID extends Serializable>>
checkpointId
- The ID of the checkpoint - a unique and monotonously increasing value.timestamp
- The wall clock timestamp when the checkpoint was triggered by the master.public void restoreState(List<AcknowledgeIdsForCheckpoint<ACKID>> state)
ListCheckpointed
The given state list will contain all the sub states that this parallel instance of
the function needs to handle. Refer to the class docs
for an
illustration how list-style state redistribution works.
Important: When implementing this interface together with RichFunction
,
then the restoreState()
method is called before RichFunction.open(Configuration)
.
restoreState
in interface ListCheckpointed<AcknowledgeIdsForCheckpoint<ACKID extends Serializable>>
state
- The state to be restored as a list of atomic sub-states.public int numberOfOutstandingAcknowledgements()
Copyright © 2014–2023 The Apache Software Foundation. All rights reserved.