aerospike.rs

Overview

This file provides an implementation of a key-value store interface for Aerospike, a distributed NoSQL database. It defines the AerospikeStore struct, which manages interaction with the Aerospike cluster, including reading, writing, and batch operations on records. The implementation includes robust write retry logic, read/write metrics collection, and optional debug statistics for database operations. The store supports splitting large values via the SplitValueStore wrapper, facilitating storage of large data blobs with a configurable chunk size.


Constants


Structs and Traits

AerospikeStore

A cloneable struct encapsulating an Aerospike client and associated policies for reads, writes, and batch operations. It optionally holds metrics for block production and debug statistics.

Fields

Methods

new(socket_address: String, metrics: Option<BlockProductionMetrics>) -> anyhow::Result<SplitValueStore<AerospikeStore>>

Creates a new AerospikeStore instance connected to the provided Aerospike cluster socket address. It initializes default client, read, write, and batch policies, sets up metrics if provided, and wraps the store in a SplitValueStore with a chunk size of 1MB - 16KB (1,048,576 - 16,384 bytes).

Parameters
Returns
Usage Example
let store = AerospikeStore::new("127.0.0.1:3000".to_string(), None)?;

put_until_success(&self, key: &Key, bins: &[Bin], object_type: &'static str)

Attempts to write the given bins to Aerospike under the specified key repeatedly until the operation succeeds. On failure, logs the error, reports metrics, and sleeps for a predefined interval before retrying.

Parameters
Implementation Details

Trait Implementation: KeyValueStore for AerospikeStore

Implements the KeyValueStore trait to provide Aerospike-based persistent storage operations.

Methods

get(&self, key: &Key, values: &Bins, label: &'static str) -> anyhow::Result<Option<ValueMap>>

Retrieves a record from Aerospike by key and requested bins.

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

Writes bins to Aerospike under the specified key.

Parameters
batch_get(&self, gets: Vec<(Key, Bins)>, _label: &'static str) -> anyhow::Result<Vec<Option<ValueMap>>>

Performs batch retrieval of multiple records.

Parameters
Debug Methods (only compiled with debug assertions)

Stats (Debug Only)

A struct to track the number of Aerospike database reads and writes using atomic counters. Used for debugging and testing purposes.

Fields

Methods


Important Implementation Details


Interaction with Other System Components


Mermaid Diagram: AerospikeStore Structure and Relationships

classDiagram
class AerospikeStore {
-client: Arc<Client>
-rpolicy: ReadPolicy
-wpolicy: WritePolicy
-bpolicy: BatchPolicy
-metrics: Option<BlockProductionMetrics>
+new()
+put_until_success()
+get()
+put()
+batch_get()
}
class SplitValueStore {
+new()
}
class Stats {
-db_reads: AtomicUsize
-db_writes: AtomicUsize
+inc_reads()
+inc_writes()
+db_reads()
+db_writes()
}
AerospikeStore o-- Client : uses
AerospikeStore o-- BlockProductionMetrics : optionally uses
AerospikeStore o-- Stats : debug only
AerospikeStore --> SplitValueStore : wrapped by

This diagram illustrates the core components and their relationships within the file. The AerospikeStore relies on the Aerospike Client for database operations, optionally reports metrics, and tracks debug statistics if enabled. It is wrapped by SplitValueStore to handle large value chunking.