pub struct WriteBufferManager { /* private fields */ }Expand description
Write Buffer Manager for coordinating memory across memtables
Implements jj.md Task 2: Write Buffer Manager with Global Memory Coordination
§Algorithm
total_buffer_memory = active_memtable.size + Σ(immutable_memtables[i].size)
on_write(bytes):
if total_buffer_memory + bytes > hard_limit:
block_until(total_buffer_memory < soft_limit)
if total_buffer_memory > soft_limit:
trigger_flush(largest_immutable_memtable)
total_buffer_memory += bytes
on_flush_complete(memtable):
total_buffer_memory -= memtable.size
signal_blocked_writers()Implementations§
Source§impl WriteBufferManager
impl WriteBufferManager
Sourcepub fn new(buffer_limit: u64) -> Self
pub fn new(buffer_limit: u64) -> Self
Create a new write buffer manager
§Arguments
buffer_limit- Maximum total memory for write buffers (bytes)
Sourcepub fn with_limits(
buffer_limit: u64,
soft_limit_ratio: f64,
hard_limit_ratio: f64,
) -> Self
pub fn with_limits( buffer_limit: u64, soft_limit_ratio: f64, hard_limit_ratio: f64, ) -> Self
Create with custom soft/hard limits
Sourcepub fn reserve_memory(&self, bytes: u64) -> bool
pub fn reserve_memory(&self, bytes: u64) -> bool
Reserve memory for a write operation
May block if hard limit is exceeded, waiting for flushes to complete. Returns true if flush should be triggered (soft limit exceeded).
Sourcepub fn release_memory(&self, bytes: u64)
pub fn release_memory(&self, bytes: u64)
Release memory after flush completes
Signals any blocked writers to retry.
Sourcepub fn memory_usage(&self) -> u64
pub fn memory_usage(&self) -> u64
Get current buffer memory usage
Sourcepub fn usage_percent(&self) -> f64
pub fn usage_percent(&self) -> f64
Get usage as percentage of limit
Sourcepub fn is_under_pressure(&self) -> bool
pub fn is_under_pressure(&self) -> bool
Check if under soft limit pressure
Sourcepub fn stats(&self) -> &WriteBufferStats
pub fn stats(&self) -> &WriteBufferStats
Get statistics
Auto Trait Implementations§
impl !Freeze for WriteBufferManager
impl !RefUnwindSafe for WriteBufferManager
impl Send for WriteBufferManager
impl Sync for WriteBufferManager
impl Unpin for WriteBufferManager
impl UnsafeUnpin for WriteBufferManager
impl UnwindSafe for WriteBufferManager
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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