pub struct LmdbStorage { /* private fields */ }Expand description
Content-addressed LMDB storage.
Uses heed (LMDB wrapper) for memory-mapped, transactional chunk storage.
Keys are 32-byte XorName addresses, values are raw chunk bytes.
Implementations§
Source§impl LmdbStorage
impl LmdbStorage
Sourcepub async fn new(config: LmdbStorageConfig) -> Result<Self>
pub async fn new(config: LmdbStorageConfig) -> Result<Self>
Create a new LMDB storage instance.
Opens (or creates) an LMDB environment at {root_dir}/chunks.mdb/.
When config.max_map_size is 0 (the default) the map size is derived
from the available disk space on the partition that hosts the database,
minus config.disk_reserve. This allows a node to use all available
storage without a fixed cap. If the operator adds more storage later
the map is resized on demand (see Self::put).
§Errors
Returns an error if the LMDB environment cannot be opened.
Sourcepub async fn put(&self, address: &XorName, content: &[u8]) -> Result<bool>
pub async fn put(&self, address: &XorName, content: &[u8]) -> Result<bool>
Store a chunk.
Before writing, verifies that available disk space exceeds the configured reserve. If the LMDB map is full but more disk space exists (e.g. the operator added storage), the map is resized automatically and the write is retried.
§Returns
Returns true if the chunk was newly stored, false if it already existed.
§Errors
Returns an error if the write fails, content doesn’t match address, or the disk is too full to accept new chunks.
Sourcepub fn stats(&self) -> StorageStats
pub fn stats(&self) -> StorageStats
Get storage statistics.
Sourcepub fn current_chunks(&self) -> Result<u64>
pub fn current_chunks(&self) -> Result<u64>
Return the number of chunks currently stored, queried from LMDB metadata.
This is an O(1) read of the B-tree page header — not a full scan.
§Errors
Returns an error if the LMDB read transaction fails.
Sourcepub fn compute_address(content: &[u8]) -> XorName
pub fn compute_address(content: &[u8]) -> XorName
Compute content address (BLAKE3 hash).
Sourcepub async fn all_keys(&self) -> Result<Vec<XorName>>
pub async fn all_keys(&self) -> Result<Vec<XorName>>
Return all stored record keys.
Iterates the LMDB database in a read transaction. Used by the replication subsystem for hint construction and audit sampling.
§Errors
Returns an error if the LMDB read transaction fails.
Auto Trait Implementations§
impl !Freeze for LmdbStorage
impl !RefUnwindSafe for LmdbStorage
impl Send for LmdbStorage
impl Sync for LmdbStorage
impl Unpin for LmdbStorage
impl UnsafeUnpin for LmdbStorage
impl !UnwindSafe for LmdbStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more