Struct MemoryIngestStore
pub struct MemoryIngestStore { /* private fields */ }memory only.Expand description
An in-memory EventStore that is also an
IngestStore.
It answers every event-store question as MemoryEventStore does over the
same rows, and ingests as the port’s documentation says: foreign events at
the tail with their origin identity and recorded time unchanged, a
re-delivery skipped by identity alone, compensation minted here only for a
group that landed something, and an unheld claim on this store’s own
identity refusing the whole call (SY-38).
Send + Sync, with one RwLock over the log and the set of identities it
holds, so the two never disagree. Every check runs before anything is
written, and the write is one critical section.
Positions are dense and start at 1. The specification permits gaps, so nothing may depend on that.
§Examples
A foreign event lands with the identity and the time its origin gave it, including a time before 1970:
use happenstance_core::{
Event, EventId, EventStore, Query, ReadOptions, RecordedAt, SequencePosition, StoreId,
collect,
};
use happenstance_sync::{IngestGroup, IngestStore, MemoryIngestStore, ReplicatedEvent};
let store = MemoryIngestStore::new();
let origin = StoreId::from_bytes([7; 16]);
let shipped = ReplicatedEvent::new(
EventId::new(origin, SequencePosition::new(4).ok_or("position zero")?),
RecordedAt::from_millis(-86_400_000),
Event::new("Shipped", &b"opaque"[..])?,
);
let ingested = store
.ingest(&[IngestGroup::new(core::slice::from_ref(&shipped), &[])])
.await?;
assert_eq!(ingested.appended, 1);
let log = collect(store.read(&Query::all(), ReadOptions::new())).await?;
let landed = log.first().ok_or("the log is empty")?;
assert_eq!(landed.id, shipped.id);
assert_eq!(landed.recorded_at, shipped.recorded_at);Implementations§
§impl MemoryIngestStore
impl MemoryIngestStore
pub fn new() -> Self
pub fn new() -> Self
An empty store with a fresh incarnation identifier.
pub fn with_store_id(store_id: StoreId) -> Self
pub fn with_store_id(store_id: StoreId) -> Self
An empty store with a caller-chosen incarnation, as
MemoryEventStore::with_store_id is.
pub fn snapshot(&self) -> Vec<SequencedEvent>
pub fn snapshot(&self) -> Vec<SequencedEvent>
Every event held, in position order.
Owned, because the lock is released before the caller looks at it.
Trait Implementations§
§impl Debug for MemoryIngestStore
impl Debug for MemoryIngestStore
§impl Default for MemoryIngestStore
impl Default for MemoryIngestStore
§impl SendEventStore for MemoryIngestStore
impl SendEventStore for MemoryIngestStore
§type Error = MemoryStoreError
type Error = MemoryStoreError
§fn read(
&self,
query: &Query,
options: ReadOptions,
) -> impl Stream<Item = Result<SequencedEvent, Self::Error>> + Send
fn read( &self, query: &Query, options: ReadOptions, ) -> impl Stream<Item = Result<SequencedEvent, Self::Error>> + Send
§async fn append(
&self,
events: &[Event],
condition: Option<&AppendCondition>,
) -> Result<SequencePosition, AppendError<Self::Error>>
async fn append( &self, events: &[Event], condition: Option<&AppendCondition>, ) -> Result<SequencePosition, AppendError<Self::Error>>
§impl SendIngestStore for MemoryIngestStore
impl SendIngestStore for MemoryIngestStore
§async fn store_id(&self) -> Result<StoreId, Self::Error>
async fn store_id(&self) -> Result<StoreId, Self::Error>
Never fails: the identity is held in memory.
§type Error = MemoryStoreError
type Error = MemoryStoreError
§async fn ingest(
&self,
groups: &[IngestGroup<'_>],
) -> Result<Ingested, IngestError<Self::Error>>
async fn ingest( &self, groups: &[IngestGroup<'_>], ) -> Result<Ingested, IngestError<Self::Error>>
§impl SendWriteGroupStore for MemoryIngestStore
Writers are serialised under the lock, so a group’s rows are contiguous and
a scan in position order meets each group whole, in ascending order of
their first positions.
impl SendWriteGroupStore for MemoryIngestStore
Writers are serialised under the lock, so a group’s rows are contiguous and a scan in position order meets each group whole, in ascending order of their first positions.
Its error is the one the shared GroupPageBuilder can raise, and the
only one: the builder checks the order rather than trusting it, and this
store states that check in its type rather than claiming it never fails.
§type Error = GroupOrderError
type Error = GroupOrderError
§async fn read_groups(
&self,
after: Option<SequencePosition>,
max_events: NonZeroUsize,
) -> Result<GroupPage, Self::Error>
async fn read_groups( &self, after: Option<SequencePosition>, max_events: NonZeroUsize, ) -> Result<GroupPage, Self::Error>
Auto Trait Implementations§
impl !Freeze for MemoryIngestStore
impl RefUnwindSafe for MemoryIngestStore
impl Send for MemoryIngestStore
impl Sync for MemoryIngestStore
impl Unpin for MemoryIngestStore
impl UnsafeUnpin for MemoryIngestStore
impl UnwindSafe for MemoryIngestStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<TraitVariantBlanketType> EventStore for TraitVariantBlanketTypewhere
TraitVariantBlanketType: SendEventStore,
impl<TraitVariantBlanketType> EventStore for TraitVariantBlanketTypewhere
TraitVariantBlanketType: SendEventStore,
Source§type Error = <TraitVariantBlanketType as SendEventStore>::Error
type Error = <TraitVariantBlanketType as SendEventStore>::Error
Source§fn read(
&self,
query: &Query,
options: ReadOptions,
) -> impl Stream<Item = Result<SequencedEvent, <TraitVariantBlanketType as EventStore>::Error>>
fn read( &self, query: &Query, options: ReadOptions, ) -> impl Stream<Item = Result<SequencedEvent, <TraitVariantBlanketType as EventStore>::Error>>
Source§async fn append(
&self,
events: &[Event],
condition: Option<&AppendCondition>,
) -> Result<SequencePosition, AppendError<<TraitVariantBlanketType as EventStore>::Error>>
async fn append( &self, events: &[Event], condition: Option<&AppendCondition>, ) -> Result<SequencePosition, AppendError<<TraitVariantBlanketType as EventStore>::Error>>
Source§async fn head(
&self,
) -> Result<Option<SequencePosition>, <TraitVariantBlanketType as EventStore>::Error>
async fn head( &self, ) -> Result<Option<SequencePosition>, <TraitVariantBlanketType as EventStore>::Error>
None when it
holds nothing. Read moreSource§async fn contains_event_id(
&self,
id: EventId,
) -> Result<bool, <TraitVariantBlanketType as EventStore>::Error>
async fn contains_event_id( &self, id: EventId, ) -> Result<bool, <TraitVariantBlanketType as EventStore>::Error>
id. Read more