Table of Contents

Interface IEventStoreVersionProbe

Namespace
Excalibur.EventSourcing
Assembly
Excalibur.EventSourcing.Abstractions.dll

Optional IEventStore capability that reports the highest event version held for a stream, without loading the stream.

public interface IEventStoreVersionProbe

Remarks

This exists to resolve one ambiguity the read surface cannot express. When an aggregate is rehydrated from a snapshot, the events after the snapshot are loaded; an empty result means either that the snapshot is already at the head of the stream -- the normal and common case -- or that the stream stops below the snapshot, so the snapshot describes a state the events can no longer account for. Both return zero rows, and nothing in that result distinguishes them.

Implement this only where the answer is cheap -- an indexed maximum over the stream's version column, not a scan of the events themselves. A store that cannot answer cheaply should not implement it: the capability is resolved through GetService(Type) on IEventStore, so a store that does not provide it simply is not probed, and the load behaves exactly as it does without this capability. There is no third state and no obligation on any provider.

Resolve it through GetService(Type) rather than testing the store's type: a store is commonly reached through a decorator, and a type test reports the decorator's own interface list rather than the capabilities of the store beneath it. A decorator that cannot answer for the whole stream must not forward this capability -- a tiered store whose hot tier has been trimmed would otherwise report a maximum that omits the archived range and make a correctly-archived stream look truncated.

Methods

GetMaxVersionAsync(string, string, CancellationToken)

Gets the highest event version stored for the aggregate stream.

ValueTask<long> GetMaxVersionAsync(string aggregateId, string aggregateType, CancellationToken cancellationToken)

Parameters

aggregateId string

The aggregate identifier.

aggregateType string

The aggregate type name.

cancellationToken CancellationToken

Token to observe for cancellation.

Returns

ValueTask<long>

The highest version present in the stream, or -1 when the stream holds no events. Versions are zero-based, so a stream of n events reports n - 1.