Class CheckpointingProgressStrategy
java.lang.Object
io.axoniq.framework.messaging.eventstreaming.checkpoint.CheckpointingProgressStrategy
- All Implemented Interfaces:
SegmentProgressStrategy
@Internal
public final class CheckpointingProgressStrategy
extends Object
implements SegmentProgressStrategy
SegmentProgressStrategy that lets self-checkpointing Checkpointing units manage when their segment's
stored TrackingToken advances. The progress-persistence counterpart of the self-checkpointing protocol: it
collects the safe positions reported by the segment's participants, reconciles them to a single agreed token, and
persists that through the SegmentProgressContext.
It runs in one of two modes, fixed per processor at construction:
- Auto (
autoCheckpointing == true): at least one ordinary handler is co-located with the participants, so a checkpoint at the batch-end token is requested every batch and the participants are driven to cover it; they cannot defer the stored token. - Fully-deferred (
autoCheckpointing == false): every handler is a participant, so the stored token advances only on an explicitCheckpointTriggerrequest.
Internal API. This class is marked Internal: it is part of the self-checkpointing support, intended
primarily for internal and advanced use, and its shape may change in a minor or patch release.
- Since:
- 5.3.0
- Author:
- Allard Buijze
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCheckpointingProgressStrategy(SegmentProgressContext context, List<Checkpointing> participants, boolean autoCheckpointing) Constructs aCheckpointingProgressStrategybound to the givencontext. -
Method Summary
Modifier and TypeMethodDescriptionvoidcontributeBatchResources(ProcessingContext processingContext) Contributes per-batch resources tocontextbefore the batch is handled, for example a handle a handler may use to influence persistence (such as a checkpoint trigger).booleanIndicates whether the strategy has out-of-band work that requires a worker cycle even when no events are queued (for example, an asynchronous checkpoint request recorded between cycles).voidonAbort()Invoked when processing of the segment aborts, so the strategy can deactivate any out-of-band signal (for example, render a checkpoint trigger inert so a late request becomes a no-op).onBatchCommit(ProcessingContext processingContext) Decides which token (if any) to store for this cycle and persists it through the context.voidInvoked when the segment is claimed, before any events are handled.onSegmentReleased(ProcessingContext processingContext) Performs the final checkpoint for the segment being released: asks each participant to drain towardlastConsumedTokenthroughCheckpointing.onSegmentReleased(Segment, TrackingToken), thenreconcilestheir reported positions to a single agreed token and persists that within the givencontext(if it advances).
-
Constructor Details
-
CheckpointingProgressStrategy
public CheckpointingProgressStrategy(SegmentProgressContext context, List<Checkpointing> participants, boolean autoCheckpointing) Constructs aCheckpointingProgressStrategybound to the givencontext.- Parameters:
context- the work package's progress context to persist progress throughparticipants- the self-checkpointing units on this segment; must not be emptyautoCheckpointing-truewhen an ordinary handler is co-located (auto mode),falsewhen every handler is self-checkpointing (fully-deferred)
-
-
Method Details
-
contributeBatchResources
Description copied from interface:SegmentProgressStrategyContributes per-batch resources tocontextbefore the batch is handled, for example a handle a handler may use to influence persistence (such as a checkpoint trigger). Invoked only for non-empty batches, before invocation. Defaults to a no-op.- Specified by:
contributeBatchResourcesin interfaceSegmentProgressStrategy- Parameters:
processingContext- the processing context of the batch about to be handled
-
onBatchCommit
Decides which token (if any) to store for this cycle and persists it through the context.- Auto mode checkpoints at the batch-end token (
lastConsumedToken); a participant is therefore forced to cover it. - Fully-deferred mode stores only when a participant explicitly requested a checkpoint.
reconciledto a single agreed position before storing, so no participant is left ahead of the stored token. A store is skipped when nothing is to be checkpointed.- Specified by:
onBatchCommitin interfaceSegmentProgressStrategy- Parameters:
processingContext- the processing context whose transaction the store participates in- Returns:
- a
CompletableFuturecompleting when the cycle's persistence (if any) has been applied
- Auto mode checkpoints at the batch-end token (
-
hasPendingWork
public boolean hasPendingWork()Description copied from interface:SegmentProgressStrategyIndicates whether the strategy has out-of-band work that requires a worker cycle even when no events are queued (for example, an asynchronous checkpoint request recorded between cycles). Drives the post-cycle reschedule and lets an idle segment run a commit cycle. Strategies that act only within their batches never schedule out-of-band and returnfalse; this is deliberately not a throttle for idle catch-up stores, which are driven on the claim-extension beat.- Specified by:
hasPendingWorkin interfaceSegmentProgressStrategy- Returns:
trueif a worker cycle is needed for out-of-band work,falseotherwise
-
onSegmentClaimed
public void onSegmentClaimed()Description copied from interface:SegmentProgressStrategyInvoked when the segment is claimed, before any events are handled. Defaults to a no-op.- Specified by:
onSegmentClaimedin interfaceSegmentProgressStrategy
-
onSegmentReleased
Performs the final checkpoint for the segment being released: asks each participant to drain towardlastConsumedTokenthroughCheckpointing.onSegmentReleased(Segment, TrackingToken), thenreconcilestheir reported positions to a single agreed token and persists that within the givencontext(if it advances). Only when reconciliation cannot be reached (a lagging participant fails to cover the agreed position) does it fall back to persisting thelowerBoundof the reported tokens, so the claim can still be released and the uncovered tail is simply reprocessed on the next claim.- Specified by:
onSegmentReleasedin interfaceSegmentProgressStrategy- Parameters:
processingContext- the processing context whose transaction the final store participates in- Returns:
- a
CompletableFuturecompleting when the final persistence (if any) has been applied
-
onAbort
public void onAbort()Description copied from interface:SegmentProgressStrategyInvoked when processing of the segment aborts, so the strategy can deactivate any out-of-band signal (for example, render a checkpoint trigger inert so a late request becomes a no-op). Defaults to a no-op.- Specified by:
onAbortin interfaceSegmentProgressStrategy
-