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
impl EmbeddedKernelStore
Sourcepub async fn migrate_data_dir<F>(
source_dir: &Path,
destination_dir: &Path,
derive: F,
) -> Result<(Self, StoreMigrationReceipt), PortError>
pub async fn migrate_data_dir<F>( source_dir: &Path, destination_dir: &Path, derive: F, ) -> Result<(Self, 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.
Sourcepub async fn migrate_data_dir_to<F>(
source_dir: &Path,
destination_dir: &Path,
destination_engine: StorageEngine,
derive: F,
) -> Result<(Self, StoreMigrationReceipt), PortError>
pub async fn migrate_data_dir_to<F>( source_dir: &Path, destination_dir: &Path, destination_engine: StorageEngine, derive: F, ) -> Result<(Self, 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.
Sourcepub async fn open_or_migrate_data_dir<F>(
source_dir: &Path,
destination_dir: &Path,
derive: F,
) -> Result<(Self, Option<StoreMigrationReceipt>), PortError>
pub async fn open_or_migrate_data_dir<F>( source_dir: &Path, destination_dir: &Path, derive: F, ) -> Result<(Self, 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.
Sourcepub async fn open_or_migrate_data_dir_to<F>(
source_dir: &Path,
destination_dir: &Path,
destination_engine: StorageEngine,
derive: F,
) -> Result<(Self, Option<StoreMigrationReceipt>), PortError>
pub async fn open_or_migrate_data_dir_to<F>( source_dir: &Path, destination_dir: &Path, destination_engine: StorageEngine, derive: F, ) -> Result<(Self, 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.
Sourcepub async fn migration_receipt(
&self,
) -> Result<Option<StoreMigrationReceipt>, PortError>
pub async fn migration_receipt( &self, ) -> Result<Option<StoreMigrationReceipt>, PortError>
The receipt of the migration that produced this store, if any.
Source§impl EmbeddedKernelStore
impl EmbeddedKernelStore
Sourcepub async fn export_bundle(&self) -> Result<String, PortError>
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.
Sourcepub async fn import_bundle<F>(
&self,
bundle: &str,
derive: F,
) -> Result<ImportReport, PortError>
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
impl EmbeddedKernelStore
Sourcepub async fn rebuild_projections<F>(
&self,
derive: F,
) -> Result<ProjectionRebuildReport, PortError>
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
impl EmbeddedKernelStore
Sourcepub fn open(data_dir: &Path) -> Result<Self, PortError>
pub fn open(data_dir: &Path) -> Result<Self, 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.
Sourcepub fn open_with_engine(
data_dir: &Path,
engine: StorageEngine,
) -> Result<Self, PortError>
pub fn open_with_engine( data_dir: &Path, engine: StorageEngine, ) -> Result<Self, 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.
Sourcepub fn engine_of(data_dir: &Path) -> Result<StorageEngine, PortError>
pub fn engine_of(data_dir: &Path) -> Result<StorageEngine, PortError>
The engine a data directory was created with, without opening it.
Trait Implementations§
Source§impl Clone for EmbeddedKernelStore
impl Clone for EmbeddedKernelStore
Source§fn clone(&self) -> EmbeddedKernelStore
fn clone(&self) -> EmbeddedKernelStore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ContextEventStore for EmbeddedKernelStore
impl ContextEventStore for EmbeddedKernelStore
Source§async fn append(
&self,
event: ContextUpdatedEvent,
expected_revision: u64,
) -> Result<u64, PortError>
async fn append( &self, event: ContextUpdatedEvent, expected_revision: u64, ) -> Result<u64, PortError>
PortError::Conflict if
expected_revision does not match the current revision for this
(root_node_id, role) aggregate.