Skip to main content

EmbeddedKernelStore

Struct EmbeddedKernelStore 

Source
pub struct EmbeddedKernelStore { /* private fields */ }
Expand description

Every kernel persistence port on one local store.

The engine behind it is chosen when the data directory is created and hidden behind the storage seam (historical ADR-018): SQLite for every store this binary can open. Cloning is cheap (shared engine handle). Commits are fsync-durable, so each successful port write survives kill -9; a crash mid-transaction loses only the in-flight transaction.

Implementations§

Source§

impl EmbeddedKernelStore

Source

pub async fn migrate_data_dir<F>( source_dir: &Path, destination_dir: &Path, derive: F, ) -> Result<(EmbeddedKernelStore, StoreMigrationReceipt), PortError>

Compatibility entry point. No current layout requires migration.

Source

pub async fn migrate_data_dir_to<F>( source_dir: &Path, destination_dir: &Path, destination_engine: StorageEngine, _derive: F, ) -> Result<(EmbeddedKernelStore, StoreMigrationReceipt), PortError>

Compatibility entry point with an explicit destination engine.

Source

pub async fn open_or_migrate_data_dir<F>( source_dir: &Path, destination_dir: &Path, derive: F, ) -> Result<(EmbeddedKernelStore, Option<StoreMigrationReceipt>), PortError>

Reopen a completed destination or apply the compatibility migration.

Source

pub async fn open_or_migrate_data_dir_to<F>( source_dir: &Path, destination_dir: &Path, destination_engine: StorageEngine, derive: F, ) -> Result<(EmbeddedKernelStore, Option<StoreMigrationReceipt>), PortError>

Reopen a completed destination or apply the compatibility migration.

Source

pub async fn migration_receipt( &self, ) -> Result<Option<StoreMigrationReceipt>, PortError>

A historical receipt stored by the migration that produced this store.

Source§

impl EmbeddedKernelStore

Source

pub fn export_bundle_blocking(&self) -> Result<String, PortError>

Synchronous export for already-blocking operational paths such as Doctor. Async application paths should use Self::export_bundle.

Source

pub async fn export_bundle(&self) -> Result<String, PortError>

Serializes the full event log as a JSON-Lines bundle: one header line followed by one event per line, in sequence order.

Source

pub async fn export_bundle_for_abouts( &self, requested_abouts: &[String], ) -> Result<String, PortError>

Serializes only events rooted at one of requested_abouts.

Abouts are opaque routing identifiers: matching is exact, with no trimming, case folding, prefix expansion or other normalisation. The filtered stream keeps the store’s event order and each aggregate’s recorded revisions, then receives bundle-local positions starting at one. A missing requested about is refused before callers can create a destination file.

Source

pub fn export_bundle_excluding_abouts_blocking( &self, excluded_abouts: &[String], ) -> Result<String, PortError>

Serializes every event except those rooted at one of excluded_abouts.

The mirror of Self::export_bundle_for_abouts, for the caller that knows what does not belong in a bundle rather than what does. A store holds content it did not author — a synced guide, say — and a bundle that is meant to carry authored memory has to be able to leave it out without first enumerating everything else. An excluded about that is absent is not an error: exclusion asks for a stream without something, and a store that never had it already satisfies that.

Abouts are opaque: matching is exact, with no trimming, case folding or prefix expansion.

Source

pub async fn export_bundle_excluding_abouts( &self, excluded_abouts: &[String], ) -> Result<String, PortError>

Source

pub async fn export_named_bundle( &self, snapshot_id: &str, ) -> Result<String, PortError>

Exports the same complete stream with a human-selected snapshot id. The id is metadata, not a filename: callers may store the bundle in git, an artifact store, or anywhere else without changing what it identifies.

Source

pub async fn import_bundle<F>( &self, bundle: &str, derive: F, ) -> Result<ImportReport, PortError>

Replays a bundle into this store. Fail-fast rules: the store must be empty (no merge semantics in v1 — ADR-011 rationale applies), the header must match supported formats, and every event must reproduce exactly the revision it was exported with.

Source§

impl EmbeddedKernelStore

Source

pub async fn rebuild_projections<F>( &self, derive: F, ) -> Result<ProjectionRebuildReport, PortError>

Drops every projection table and rebuilds them by replaying the event log in sequence order — the recovery and migration story in one.

The mutation derivation is injected so this adapter stays free of application-layer dependencies; the composition root passes kmp_application::projection_mutations_for_context_event. The whole rebuild is one transaction: a crash mid-rebuild leaves the previous projections intact.

Source§

impl EmbeddedKernelStore

Source

pub fn open(data_dir: &Path) -> Result<EmbeddedKernelStore, PortError>

Opens (or initializes) the store inside data_dir, applying the ADR-012 fail-fast rules before touching the engine. A fresh directory gets the default engine; an existing one opens with the engine it was created with.

Source

pub fn open_with_engine( data_dir: &Path, engine: StorageEngine, ) -> Result<EmbeddedKernelStore, PortError>

open with the engine chosen: a fresh directory is created for SQLite, and an existing one must already be engine — a store is never reinterpreted as another engine’s.

Source

pub fn engine_of(data_dir: &Path) -> Result<StorageEngine, PortError>

The engine a data directory was created with, without opening it.

Source

pub async fn event_log_stats(&self) -> Result<(u64, u64), PortError>

Number of events in the append-only log and the highest sequence — audit surface used by recovery checks and operational tooling.

Source

pub fn compact_data_dir(data_dir: &Path) -> Result<bool, PortError>

Compacts the store file in place, reclaiming free pages left by past transactions (e.g. after a projection rebuild). Requires exclusive access: call it with no other store handle open on the same data directory.

Trait Implementations§

Source§

impl Clone for EmbeddedKernelStore

Source§

fn clone(&self) -> EmbeddedKernelStore

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ContextEventStore for EmbeddedKernelStore

Source§

async fn append( &self, event: ContextUpdatedEvent, expected_revision: u64, ) -> Result<u64, PortError>

Append an event. Fails with PortError::Conflict if expected_revision does not match the current revision for this (root_node_id, role) aggregate.
Source§

async fn current_revision( &self, root_node_id: &str, role: &str, ) -> Result<u64, PortError>

Returns the current revision for the aggregate, or 0 if no events exist.
Source§

async fn current_content_hash( &self, root_node_id: &str, role: &str, ) -> Result<Option<String>, PortError>

Returns the content hash of the last accepted event, or None if no events exist.
Source§

async fn find_by_idempotency_key( &self, key: &str, ) -> Result<Option<IdempotentOutcome>, PortError>

Checks if an event with this idempotency key was already accepted.
Source§

impl Debug for EmbeddedKernelStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl GraphNeighborhoodReader for EmbeddedKernelStore

Source§

async fn load_neighborhood( &self, root_node_id: &str, depth: u32, ) -> Result<Option<NodeNeighborhood>, PortError>

Source§

async fn load_scoped_neighborhood( &self, request: &NeighborhoodRequest, ) -> Result<Option<NodeNeighborhood>, PortError>

Loads a neighbourhood already narrowed by the axes the caller resolved. Read more
Source§

async fn load_context_path( &self, root_node_id: &str, target_node_id: &str, subtree_depth: u32, ) -> Result<Option<ContextPathNeighborhood>, PortError>

Source§

impl MemoryAboutIndexReader for EmbeddedKernelStore

Source§

impl NodeDetailReader for EmbeddedKernelStore

Source§

impl NodeRelationshipReader for EmbeddedKernelStore

Source§

impl ProcessedEventStore for EmbeddedKernelStore

Source§

async fn has_processed( &self, consumer_name: &str, event_id: &str, ) -> Result<bool, PortError>

Source§

async fn record_processed( &self, consumer_name: &str, event_id: &str, ) -> Result<(), PortError>

Source§

impl ProjectionCheckpointStore for EmbeddedKernelStore

Source§

async fn load_checkpoint( &self, consumer_name: &str, stream_name: &str, ) -> Result<Option<ProjectionCheckpoint>, PortError>

Source§

async fn save_checkpoint( &self, checkpoint: ProjectionCheckpoint, ) -> Result<(), PortError>

Source§

impl ProjectionWriter for EmbeddedKernelStore

Source§

async fn apply_mutations( &self, mutations: Vec<ProjectionMutation>, ) -> Result<(), PortError>

Source§

impl SnapshotStore for EmbeddedKernelStore

Source§

async fn save_bundle_with_options( &self, bundle: &KmpBundle, options: SnapshotSaveOptions, ) -> Result<(), PortError>

Source§

fn save_bundle( &self, bundle: &KmpBundle, ) -> impl Future<Output = Result<(), PortError>> + Send

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more