pub struct ConcurrentMvcc { /* private fields */ }Expand description
Manager for concurrent MVCC operations
Coordinates:
- Reader registration (lock-free)
- Writer locking (single-writer)
- Version store access
- Garbage collection
The MVCC header (writer_lock, current_ts, current_epoch) is stored in a memory-mapped file so that AtomicU32/AtomicU64 CAS operations work correctly across independent OS processes. Without mmap, each process would have its own copy of these atomics, making cross-process coordination impossible.
Implementations§
Source§impl ConcurrentMvcc
impl ConcurrentMvcc
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Open or create MVCC manager with shared memory-mapped metadata
The metadata file (.mvcc_metadata) is mmap’d so that the writer_lock, current_ts, and reader slots are shared across all processes that open the same database. This enables true cross-process atomic coordination.
Sourcepub fn allocate_timestamp(&self) -> HlcTimestamp
pub fn allocate_timestamp(&self) -> HlcTimestamp
Allocate next timestamp
Sourcepub fn current_timestamp(&self) -> HlcTimestamp
pub fn current_timestamp(&self) -> HlcTimestamp
Get current timestamp without advancing
Sourcepub fn current_epoch(&self) -> u64
pub fn current_epoch(&self) -> u64
Get current epoch
Sourcepub fn register_reader(&self) -> Result<usize>
pub fn register_reader(&self) -> Result<usize>
Register as active reader
Returns slot index on success.
Must call unregister_reader() when done.
Sourcepub fn unregister_reader(&self, slot_idx: usize)
pub fn unregister_reader(&self, slot_idx: usize)
Unregister as reader
Sourcepub fn try_acquire_writer(&self) -> Result<WriterGuard<'_>>
pub fn try_acquire_writer(&self) -> Result<WriterGuard<'_>>
Try to acquire writer lock
Returns WriterGuard on success, which releases lock on drop.
Sourcepub fn acquire_writer(&self, timeout: Duration) -> Result<WriterGuard<'_>>
pub fn acquire_writer(&self, timeout: Duration) -> Result<WriterGuard<'_>>
Acquire writer lock with timeout
Sourcepub fn version_store(&self) -> &VersionStore
pub fn version_store(&self) -> &VersionStore
Get version store
Sourcepub fn min_active_snapshot(&self) -> u64
pub fn min_active_snapshot(&self) -> u64
Calculate minimum visible snapshot across all readers
Sourcepub fn min_active_epoch(&self) -> u32
pub fn min_active_epoch(&self) -> u32
Calculate minimum active epoch across all readers
Sourcepub fn run_gc(&self) -> usize
pub fn run_gc(&self) -> usize
Run garbage collection
Should be called periodically (e.g., every 1000 commits).
Sourcepub fn should_run_gc(&self) -> bool
pub fn should_run_gc(&self) -> bool
Check if GC should run (based on commit count)
Sourcepub fn cleanup_stale_readers(&self) -> usize
pub fn cleanup_stale_readers(&self) -> usize
Clean up stale readers (from crashed processes)
Sourcepub fn advance_epoch(&self) -> u64
pub fn advance_epoch(&self) -> u64
Advance epoch (called on recovery)
Trait Implementations§
Source§impl Drop for ConcurrentMvcc
impl Drop for ConcurrentMvcc
impl Send for ConcurrentMvcc
impl Sync for ConcurrentMvcc
Auto Trait Implementations§
impl !Freeze for ConcurrentMvcc
impl !RefUnwindSafe for ConcurrentMvcc
impl Unpin for ConcurrentMvcc
impl UnsafeUnpin for ConcurrentMvcc
impl UnwindSafe for ConcurrentMvcc
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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