fs.rs

Overview

The fs.rs file implements a filesystem-backed key-value storage system through the FsStore struct, which conforms to the KeyValueStore trait. It serializes and deserializes Aerospike data types to and from the local filesystem, storing each record as a separate file within a specified directory. This approach enables persistent storage of key-value pairs on disk, leveraging Rust's type system and serialization libraries for safe and efficient data handling.

The file also contains serialization helper enums (SerdeValue and SerdeFloatValue) that convert between Aerospike's internal Value types and their serializable counterparts, facilitating the persistence process.


Structs and Enums

FsStore

Represents a filesystem-based key-value store.

Fields

Methods

new(data_dir: impl Into<PathBuf>) -> anyhow::Result<Self>

Creates a new FsStore, ensuring the data directory exists by creating it if necessary.

persist(tmp: NamedTempFile, path: &Path) -> anyhow::Result<()>

Attempts to atomically persist a temporary file to the target path.

key_path(&self, key: &Key) -> PathBuf

Generates the full filesystem path for a given Aerospike Key.


Trait Implementation: KeyValueStore for FsStore

This implementation integrates FsStore into the system as a backend for key-value operations.

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

Retrieves the value map associated with a key.

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

Stores or updates the value map for a key.

db_reads() and db_writes() (Debug-only)

Stub methods intended to track database read and write counts during debug builds. Currently unimplemented (todo!()).


Serialization Helper Enums

SerdeFloatValue

An enum to serialize and deserialize Aerospike's FloatValue (which can be either F32 or F64).

SerdeValue

An enum representing all possible Aerospike Value variants in a serializable form.


Important Implementation Details


Interactions with Other Modules


Visual Diagram

classDiagram
class FsStore {
-data_dir: PathBuf
+new()
-persist()
-key_path()
+get()
+put()
+db_reads()
+db_writes()
}
class SerdeFloatValue {
<<enum>>
+F32
+F64
}
class SerdeValue {
<<enum>>
+Nil
+Bool
+Int
+UInt
+Float
+String
+Blob
+List
+HashMap
+OrderedMap
+GeoJSON
+HLL
}
FsStore ..|> KeyValueStore
FsStore o-- NamedTempFile : uses
FsStore o-- PathBuf : uses
FsStore ..> SerdeValue : serializes/deserializes
SerdeValue ..> SerdeFloatValue : contains
SerdeValue <--> Value : conversion
SerdeFloatValue <--> FloatValue : conversion

Summary of Key Relationships