pub struct OffsetMap(/* private fields */);
Expand description
Multi-dimensional cursor for event streams: an OffsetMap
describes the set of events
given by the event streams of each included source up to the associated Offset
.
All stream delivery modes supported by the Event Service respect the order of offsets of the events published by each single AX node. This order is consistent with the Lamport timestamp order because both numbers are assigned to published events in strictly monotonically increasing fashion, i.e. greater offset implies greater Lamport timestamp and vice versa.
Note that if the
OffsetMap
contains offset 42 for StreamId"abc.0"
it denotes that events with offsets 0 through 42 (inclusive) are included within theOffsetMap
.
A common usage pattern is to store the OffsetMap
describing the events already consumed
from an event stream together with the computation results from processing those events
(preferably within the same database transaction, if applicable). When restarting the
process, this OffsetMap
can be read and the stream can be resumed from where the process
left off previously.
§Arithmetics
OffsetMap
has a partial order: when the set of events described by one is a strict
subset of the set of events described by another, then one is said to be smaller than
the other. It may be that one OffsetMap
contains events that the other does not and vice
versa, in which case they are incomparable (partial_cmp
will return None
).
An event may be added into an OffsetMap
to denote that from the event’s stream all events
up to this one shall be included in the OffsetMap
.
The difference of two offset maps yields the number of events contained within the first but not within the second one (i.e. it counts the size of the difference set).
§Deserialization
An OffsetMap
only contains valid offsets (non-negative numbers), but during deserialization
negative values are tolerated and ignored. This is to keep compatibility with previously
documented API endpoints.
Implementations§
Source§impl OffsetMap
impl OffsetMap
Sourcepub fn empty() -> Self
pub fn empty() -> Self
The empty OffsetMap
is equivalent to the beginning of time, it does not contain any
event.
Sourcepub fn contains<T>(&self, event: &Event<T>) -> bool
pub fn contains<T>(&self, event: &Event<T>) -> bool
Check whether the given Event’s offset and source ID are contained within this OffsetMap
.
Sourcepub fn contains_stream(&self, stream: &StreamId) -> bool
pub fn contains_stream(&self, stream: &StreamId) -> bool
Check whether the given stream contributes to the set of events in this OffsetMap
Sourcepub fn offset(&self, stream: impl Into<StreamId>) -> OffsetOrMin
pub fn offset(&self, stream: impl Into<StreamId>) -> OffsetOrMin
Retrieve the offset stored for the given source
The returned value is OffsetOrMin::MIN
if nothing is stored for the given source.
Sourcepub fn get(&self, stream: impl Into<StreamId>) -> Option<Offset>
pub fn get(&self, stream: impl Into<StreamId>) -> Option<Offset>
Retrieves the offset stored for the given source
Sourcepub fn union_with(&mut self, other: &OffsetMap)
pub fn union_with(&mut self, other: &OffsetMap)
Merge the other OffsetMap into this one, taking the union of their event sets.
Sourcepub fn union(&self, other: &OffsetMap) -> OffsetMap
pub fn union(&self, other: &OffsetMap) -> OffsetMap
Compute the union of two sets of events described by OffsetMaps
Sourcepub fn intersection_with(&mut self, other: &OffsetMap)
pub fn intersection_with(&mut self, other: &OffsetMap)
Compute the intersection of two sets of events described by OffsetMaps
Sourcepub fn intersection(&self, other: &OffsetMap) -> OffsetMap
pub fn intersection(&self, other: &OffsetMap) -> OffsetMap
Compute the intersection of two sets of events described by OffsetMaps
pub fn into_inner(self) -> BTreeMap<StreamId, Offset>
Sourcepub fn streams(&self) -> impl Iterator<Item = StreamId> + '_
pub fn streams(&self) -> impl Iterator<Item = StreamId> + '_
An iterator over all streams that contribute events to this OffsetMap
Sourcepub fn stream_iter(&self) -> impl Iterator<Item = (StreamId, Offset)> + '_
pub fn stream_iter(&self) -> impl Iterator<Item = (StreamId, Offset)> + '_
An iterator over all streams that contribute events to this OffsetMap including their offset
Sourcepub fn update(
&mut self,
stream: impl Into<StreamId>,
offset: Offset,
) -> Option<OffsetOrMin>
pub fn update( &mut self, stream: impl Into<StreamId>, offset: Offset, ) -> Option<OffsetOrMin>
Update entry for source if the given offset is larger than the stored one and return the previous offset for this source
pub fn includes( &self, other: impl IntoIterator<Item = (StreamId, Offset)>, ) -> bool
Trait Implementations§
Source§impl<T> AddAssign<&Event<T>> for OffsetMap
impl<T> AddAssign<&Event<T>> for OffsetMap
Source§fn add_assign(&mut self, other: &Event<T>)
fn add_assign(&mut self, other: &Event<T>)
+=
operation. Read moreSource§impl AddAssign<&EventKey> for OffsetMap
impl AddAssign<&EventKey> for OffsetMap
Source§fn add_assign(&mut self, other: &EventKey)
fn add_assign(&mut self, other: &EventKey)
+=
operation. Read moreSource§impl BitAndAssign for OffsetMap
impl BitAndAssign for OffsetMap
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&=
operation. Read moreSource§impl BitOrAssign for OffsetMap
impl BitOrAssign for OffsetMap
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|=
operation. Read moreSource§impl<'de> Deserialize<'de> for OffsetMap
impl<'de> Deserialize<'de> for OffsetMap
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialOrd for OffsetMap
impl PartialOrd for OffsetMap
Source§impl<T> SubAssign<&Event<T>> for OffsetMap
impl<T> SubAssign<&Event<T>> for OffsetMap
Source§fn sub_assign(&mut self, other: &Event<T>)
fn sub_assign(&mut self, other: &Event<T>)
Ensure that the given event is no longer contained within this OffsetMap.
Source§impl SubAssign<&EventKey> for OffsetMap
impl SubAssign<&EventKey> for OffsetMap
Source§fn sub_assign(&mut self, other: &EventKey)
fn sub_assign(&mut self, other: &EventKey)
Ensure that the given event is no longer contained within this OffsetMap.