Skip to main content
Table of Contents

Interface ICommittedPositionReader

Namespace
Stratara.Abstractions.CommitOrder
Assembly
Stratara.Abstractions.dll

Reads the event store in commit order, one partition at a time. The promise that distinguishes it from a plain "after sequence number" read: no entry whose position is at or below the Position of a returned batch can still commit later. A reader that keeps that promise can be resumed from a stored position without ever skipping an entry.

public interface ICommittedPositionReader
Extension Methods

Remarks

What a position is depends on the implementation — a sequence number, a per-partition counter, a transaction id — and a stored position is only meaningful to the reader that produced it. A read that orders by sequence number alone does not keep the promise: a transaction can take the lower sequence number and commit after one that took a higher.

Properties

Name

The stable name positions are stored under. It names the ordering the positions belong to and the partition count they were written under, so a checkpoint is refused by a reader of another kind or under another count, and renaming a class changes nothing a checkpoint is keyed on.

string Name { get; }

Property Value

string

Methods

HeadAsync(int, CancellationToken)

Returns the head of partition: the position after which no entry committed at the time of the call exists, so that a consumer starting there reads exactly what commits afterwards. 0 on a partition without entries. The default walks the partition batch by batch from the beginning and returns the last position; a reader overrides it with one query where its store can answer directly.

Task<long> HeadAsync(int partition, CancellationToken cancellationToken = default)

Parameters

partition int

The partition, from 0 to the configured partition count − 1.

cancellationToken CancellationToken

Propagated to the store.

Returns

Task<long>

The position to store for a consumer that starts at the head.

Remarks

A reader whose positions come from the store's own transactions — the native reader on PostgreSQL — cannot count what a write transaction still open might yet commit before the entries it already sees, so its head is held back to what no open transaction can precede. Take a head while nothing appends, which is what seeding a deployment does; taken while writers run, it may fall behind what is committed, and a consumer seeded at it applies the entries in between once more.

ReadAfterAsync(int, long, int, CancellationToken)

Returns up to batchSize entries of partition that come after afterPosition in commit order, together with the position to resume from.

Task<CommittedBatch> ReadAfterAsync(int partition, long afterPosition, int batchSize, CancellationToken cancellationToken = default)

Parameters

partition int

The partition to read, from 0 to the configured partition count − 1.

afterPosition long

The position returned by the previous batch, or 0 to start from the beginning.

batchSize int

The maximum number of entries to return.

cancellationToken CancellationToken

Propagated to the store.

Returns

Task<CommittedBatch>

The entries in commit order, and the position to store; an empty batch keeps the position it was asked for.