mod.rs

Overview

This file defines the ActionLockStorage struct, which provides a persistent key-value storage interface specialized for storing and retrieving serialized data blobs. It uses an underlying KeyValueStore trait object to abstract the actual storage mechanism, enabling flexibility in storage backend implementations. The primary use case of this module is to handle cross-action locks or similar data structures serialized as binary blobs, stored under a namespace and set prefix.

Structs and Implementations

ActionLockStorage

A storage wrapper around a generic key-value store focused on managing serialized blobs under a specified Aerospike namespace and set prefix.

Fields

Methods

new(store: impl KeyValueStore + 'static, set_prefix: &str) -> Self

Creates a new ActionLockStorage instance wrapping the given key-value store and using the specified set prefix.

let mem_store = MemStore::new();
let storage = ActionLockStorage::new(mem_store, "my_set");
mem() -> Self

A convenience constructor that creates an ActionLockStorage instance backed by an in-memory store (MemStore) with the set prefix "mem".

let storage = ActionLockStorage::mem();
message_key(&self, hash: &str) -> Key

Generates an Aerospike key for a given string hash, using the configured namespace and set prefix.

read_blob<T: for<'de> Deserialize<'de>>(&self, path: &str) -> anyhow::Result<Option<T>>

Reads and deserializes a blob value from the store given a key path.

let maybe_lock: Option<MyLockStruct> = storage.read_blob("lock_key")?;
if let Some(lock) = maybe_lock {
    // Use the lock data
}
write_blob<T: Serialize>(&self, path: &str, data: T, until_success: bool) -> anyhow::Result<()>

Serializes and writes a data blob to the key-value store.

storage.write_blob("lock_key", my_lock_data, true)?;

Important Implementation Details

Interaction with Other System Components

File Structure and Workflow Diagram

flowchart TD
A[ActionLockStorage] --> B[store: KeyValueStore]
A --> C[set_prefix: String]
A --> D["new()"]
A --> E["mem()"]
A --> F["message_key()"]
A --> G["read_blob()"]
A --> H["write_blob()"]
G --> I[Deserialize blob via bincode]
H --> J[Serialize data via bincode]
D --> B
E --> B

This diagram illustrates the main components and methods of the ActionLockStorage struct, highlighting how it composes a key-value store and exposes methods to read and write serialized blobs keyed by a message key constructed from the set prefix. Serialization and deserialization are key workflows encapsulated in write_blob and read_blob methods respectively.