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 (ADR-018): redb by default, SQLite when asked for and compiled in. Cloning is cheap (shared engine handle). Commits are fsync-durable on both engines, 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>

Migrates source_dir into destination_dir and opens the result. The destination is created with the default engine.

derive is the projection derivation the composition root owns (kmp_application::projection_mutations_for_context_event), kept injected so this adapter stays free of the application layer.

Source

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

migrate_data_dir with the destination engine chosen. This is how a store changes engines (ADR-018): the event log is the source of truth and projections are derived, so a redb store becomes a SQLite store by replaying its history into a fresh SQLite directory — the same operation a format bump has always been. The source is not modified; the receipt records both formats.

Source

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

Migrate once, reopen afterwards: safe to call on every start.

A destination that already holds a store is opened as it is — the migration is not repeated, and the receipt (when there is one) says where that memory came from.

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>

open_or_migrate_data_dir with the destination engine chosen. The engine only matters on the call that migrates; a destination that already holds a store opens as whatever it is.

Source

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

The receipt of the migration that produced this store, if any.

Source§

impl EmbeddedKernelStore

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 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 engine, 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_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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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