durable.rs

Overview

This file defines the DurableStore enum, which serves as an abstraction layer over two types of persistent key-value stores: an in-memory store (MemStore) and an Aerospike-based distributed store (AerospikeStore). It provides a unified interface to perform common database operations like get, put, and batch_get, delegating the actual work to the underlying store implementations. This abstraction allows the rest of the system to switch between storage backends seamlessly without changing the code that interacts with the storage.

The file also implements the KeyValueStore trait for DurableStore, ensuring that the enum conforms to the expected interface for key-value operations.

Components

Enum: DurableStore

Methods on DurableStore

pub fn mem() -> DurableStore

pub fn aerospike(socket_address: String, metrics: Option<BlockProductionMetrics>) -> anyhow::Result<Self>

Trait Implementation: KeyValueStore for DurableStore

Implements the KeyValueStore trait to provide key-value storage operations by delegating to the underlying store variant.

Functions

fn get(&self, key: &Key, bins: &[&str], label: &'static str) -> anyhow::Result<Option<BinMap>>

fn put(&self, key: &Key, bins: &[Bin], until: bool, label: &'static str) -> anyhow::Result<()>

fn batch_get(&self, reads: Vec<BatchGet>) -> anyhow::Result<Vec<Option<BinMap>>>

Debug-only Functions (enabled under debug_assertions)

These methods are useful for monitoring and debugging database access patterns and are delegated to the underlying store.

Implementation Details and Algorithms

Interactions with Other Modules

Diagram: DurableStore Structure and Method Delegation

classDiagram
class DurableStore {
+mem()
+aerospike()
+get()
+put()
+batch_get()
+db_reads()
+db_writes()
}
class MemStore {
+get()
+put()
+batch_get()
+db_reads()
+db_writes()
}
class AerospikeStore {
+new()
+get()
+put()
+batch_get()
+db_reads()
+db_writes()
}
class SplitValueStore {
+new()
+get()
+put()
+batch_get()
+db_reads()
+db_writes()
}
DurableStore --> MemStore : Mem variant
DurableStore --> SplitValueStore : Aerospike variant
SplitValueStore --> AerospikeStore : wraps

This diagram illustrates the DurableStore enum holding either a MemStore or a SplitValueStore wrapping an AerospikeStore. The methods on DurableStore delegate calls to the respective methods on the contained store.