Interface IProjectionCheckpointStore
- Namespace
- Stratara.Abstractions.Projections
- Assembly
- Stratara.Abstractions.dll
Reads and writes the position a store-reading consumer resumes after, one per consumer and partition. A position is only meaningful to the reader that produced it, so every read names the reader it expects and a checkpoint written under another reader is refused rather than misread.
public interface IProjectionCheckpointStore
- Extension Methods
Methods
AdvanceAsync(string, int, string, long, long, CancellationToken)
Advances a position from the one its writer last saw — the verb a reader writes with after it applied a batch.
Task AdvanceAsync(string projection, int partition, string reader, long from, long to, CancellationToken cancellationToken = default)
Parameters
projectionstringThe consumer, by the name the framework gives it.
partitionintThe partition.
readerstringThe name of the reader whose position this is.
fromlongThe position the writer last read or wrote;
0where it found none.tolongThe position to resume after.
cancellationTokenCancellationTokenPropagated to the store.
Returns
- Task
A task that completes when the position is stored.
Remarks
The default replaces the position through SetAsync(string, int, string, long, CancellationToken) and checks nothing. A store that overrides it refuses a write that finds another position or another reader, so that an activation which outlived its successor neither rewinds nor overtakes what the successor wrote; the refused reader reads the checkpoint again. A rebuild and a full replay rely on that refusal as well: a reader that applied facts while it should have been paused, and still holds the position it reached before the read model was emptied, is refused once the rebuild returns the checkpoint to the beginning, and reads those facts again. Under the unguarded default such a reader writes its position over the beginning and the read model lacks the facts it applied before it was emptied, so a store used with a rebuild or a replay should override this method; the framework's store does.
Exceptions
- InvalidOperationException
The stored position is not
from, or the checkpoint was written under a different reader.
CreateAsync(string, int, string, long, CancellationToken)
Stores a position only where the consumer has no checkpoint in the partition, and never replaces one — the verb a store-reading saga's first checkpoint is written with, so that two readers starting together agree on it.
Task<bool> CreateAsync(string projection, int partition, string reader, long position, CancellationToken cancellationToken = default)
Parameters
projectionstringThe consumer, by the name the framework gives it.
partitionintThe partition.
readerstringThe name of the reader whose position this is.
positionlongThe position to resume after.
cancellationTokenCancellationTokenPropagated to the store.
Returns
Exceptions
- NotSupportedException
The store does not implement this member; the default does not.
FindAsync(string, int, string, CancellationToken)
Returns the stored position, or null where the consumer has no checkpoint in the partition —
unlike GetAsync(string, int, string, CancellationToken), which answers 0 for a missing checkpoint and for one at the beginning alike.
Store-reading sagas need the difference: a saga without a checkpoint starts where the host's other sagas read,
one at the beginning has not yet applied its first entry.
Task<long?> FindAsync(string projection, int partition, string reader, CancellationToken cancellationToken = default)
Parameters
projectionstringThe consumer, by the name the framework gives it.
partitionintThe partition.
readerstringThe name of the reader whose positions are expected.
cancellationTokenCancellationTokenPropagated to the store.
Returns
Exceptions
- InvalidOperationException
A checkpoint exists but was written under a different reader.
- NotSupportedException
The store does not implement this member; the default does not.
GetAsync(string, int, string, CancellationToken)
Returns the stored position, or 0 where none exists.
Task<long> GetAsync(string projection, int partition, string reader, CancellationToken cancellationToken = default)
Parameters
projectionstringThe consumer, by the name the framework gives it.
partitionintThe partition.
readerstringThe name of the reader whose positions are expected.
cancellationTokenCancellationTokenPropagated to the store.
Returns
Exceptions
- InvalidOperationException
A checkpoint exists but was written under a different reader.
ResetAsync(string, int, string, CancellationToken)
Returns a position to the beginning — the verb a rebuild and a full replay write with.
Task ResetAsync(string projection, int partition, string reader, CancellationToken cancellationToken = default)
Parameters
projectionstringThe consumer, by the name the framework gives it.
partitionintThe partition.
readerstringThe name of the reader the consumer will read under from now on.
cancellationTokenCancellationTokenPropagated to the store.
Returns
- Task
A task that completes when the checkpoint is at the beginning.
Remarks
The beginning means the same under every reader and every partition count, so a store that refuses a write under another reader's name accepts this one and takes the row over: it is how a deployment whose reader or partition count changed rebuilds without being stopped. The default writes through SetAsync(string, int, string, long, CancellationToken) and therefore takes nothing over — a store that guards the reader's name overrides this, as the framework's does.
SetAsync(string, int, string, long, CancellationToken)
Stores a position, replacing the previous one — the verb a rebuild, a reset or a seeding writes with.
Task SetAsync(string projection, int partition, string reader, long position, CancellationToken cancellationToken = default)
Parameters
projectionstringThe consumer, by the name the framework gives it.
partitionintThe partition.
readerstringThe name of the reader whose position this is.
positionlongThe position to resume after.
cancellationTokenCancellationTokenPropagated to the store.
Returns
- Task
A task that completes when the position is stored.