pub struct MemTable<A: AllocatorTrait> { /* private fields */ }
Expand description
In-memory storage for Raft Groups.
Each Raft Group has its own MemTable
to store all key value pairs and the
file locations of all log entries.
Implementations§
Source§impl<A: AllocatorTrait> MemTable<A>
impl<A: AllocatorTrait> MemTable<A>
Sourcepub fn merge_newer_neighbor(&mut self, rhs: &mut Self)
pub fn merge_newer_neighbor(&mut self, rhs: &mut Self)
Merges with a newer neighbor MemTable
.
This method is only used for recovery.
Sourcepub fn merge_append_table(&mut self, rhs: &mut Self)
pub fn merge_append_table(&mut self, rhs: &mut Self)
Merges with a MemTable
that contains only append data. Assumes
self
contains all rewritten data of the same region.
This method is only used for recovery.
Sourcepub fn scan<F>(
&self,
start_key: Option<&[u8]>,
end_key: Option<&[u8]>,
reverse: bool,
f: F,
) -> Result<()>
pub fn scan<F>( &self, start_key: Option<&[u8]>, end_key: Option<&[u8]>, reverse: bool, f: F, ) -> Result<()>
Iterates over [start_key, end_key) range and yields all key value pairs as bytes.
Sourcepub fn put(&mut self, key: Vec<u8>, value: Vec<u8>, file_id: FileId)
pub fn put(&mut self, key: Vec<u8>, value: Vec<u8>, file_id: FileId)
Puts a key value pair that has been written to the specified file. The old value for this key will be deleted if exists.
Sourcepub fn rewrite_key(&mut self, key: Vec<u8>, gate: Option<FileSeq>, seq: FileSeq)
pub fn rewrite_key(&mut self, key: Vec<u8>, gate: Option<FileSeq>, seq: FileSeq)
Rewrites a key by marking its location to the seq
-th log file in
rewrite queue. No-op if the key does not exist.
When gate
is present, only append data no newer than it will be
rewritten.
Sourcepub fn get_entry(&self, index: u64) -> Option<EntryIndex>
pub fn get_entry(&self, index: u64) -> Option<EntryIndex>
Returns the log entry location for a given logical log index.
Sourcepub fn append(&mut self, entry_indexes: Vec<EntryIndex>)
pub fn append(&mut self, entry_indexes: Vec<EntryIndex>)
Appends some log entries from append queue. Existing entries newer than any of the incoming entries will be deleted silently. Assumes the provided entries have consecutive logical indexes.
§Panics
Panics if index of the first entry in entry_indexes
is greater than
largest existing index + 1 (hole).
Panics if incoming entries contains indexes that might be compacted before (overwrite history).
Sourcepub fn replay_append(&mut self, entry_indexes: Vec<EntryIndex>)
pub fn replay_append(&mut self, entry_indexes: Vec<EntryIndex>)
Appends some entries from append queue. Assumes this table has no rewrite data.
This method is only used for recovery.
Sourcepub fn rewrite(
&mut self,
rewrite_indexes: Vec<EntryIndex>,
gate: Option<FileSeq>,
)
pub fn rewrite( &mut self, rewrite_indexes: Vec<EntryIndex>, gate: Option<FileSeq>, )
Rewrites some entries by modifying their location.
When gate
is present, only append data no newer than it will be
rewritten.
§Panics
Panics if index of the first entry in rewrite_indexes
is greater than
largest existing rewritten index + 1 (hole).
Sourcepub fn replay_rewrite(&mut self, entry_indexes: Vec<EntryIndex>)
pub fn replay_rewrite(&mut self, entry_indexes: Vec<EntryIndex>)
Appends some entries from rewrite queue. Assumes this table has no append data.
This method is only used for recovery.
Sourcepub fn compact_to(&mut self, index: u64) -> u64
pub fn compact_to(&mut self, index: u64) -> u64
Removes all entries with index smaller than index
. Returns the number
of deleted entries.
pub fn apply_rewrite_atomic_group(&mut self, start: FileSeq, end: FileSeq)
Sourcepub fn fetch_entries_to(
&self,
begin: u64,
end: u64,
max_size: Option<usize>,
vec_idx: &mut Vec<EntryIndex>,
) -> Result<()>
pub fn fetch_entries_to( &self, begin: u64, end: u64, max_size: Option<usize>, vec_idx: &mut Vec<EntryIndex>, ) -> Result<()>
Pulls all entries between log index begin
and end
to the given
buffer. Returns error if any entry is missing.
When max_size
is present, stops pulling entries when the total size
reaches it.
Sourcepub fn fetch_entry_indexes_before(
&self,
gate: FileSeq,
vec_idx: &mut Vec<EntryIndex>,
) -> Result<()>
pub fn fetch_entry_indexes_before( &self, gate: FileSeq, vec_idx: &mut Vec<EntryIndex>, ) -> Result<()>
Pulls all append entries older than or equal to gate
, to the provided
buffer.
Sourcepub fn fetch_rewritten_entry_indexes(
&self,
vec_idx: &mut Vec<EntryIndex>,
) -> Result<()>
pub fn fetch_rewritten_entry_indexes( &self, vec_idx: &mut Vec<EntryIndex>, ) -> Result<()>
Pulls all rewrite entries to the provided buffer.
Sourcepub fn fetch_kvs_before(&self, gate: FileSeq, vec: &mut Vec<(Vec<u8>, Vec<u8>)>)
pub fn fetch_kvs_before(&self, gate: FileSeq, vec: &mut Vec<(Vec<u8>, Vec<u8>)>)
Pulls all key value pairs older than or equal to gate
, to the provided
buffer.
Sourcepub fn fetch_rewritten_kvs(&self, vec: &mut Vec<(Vec<u8>, Vec<u8>)>)
pub fn fetch_rewritten_kvs(&self, vec: &mut Vec<(Vec<u8>, Vec<u8>)>)
Pulls all rewrite key value pairs to the provided buffer.
Sourcepub fn min_file_seq(&self, queue: LogQueue) -> Option<FileSeq>
pub fn min_file_seq(&self, queue: LogQueue) -> Option<FileSeq>
Returns the smallest file sequence number of entries or key value pairs in this table.
pub fn has_at_least_some_entries_before( &self, gate: FileId, count: usize, ) -> bool
Sourcepub fn first_index(&self) -> Option<u64>
pub fn first_index(&self) -> Option<u64>
Returns the log index of the first log entry.
Sourcepub fn last_index(&self) -> Option<u64>
pub fn last_index(&self) -> Option<u64>
Returns the log index of the last log entry.
Trait Implementations§
Auto Trait Implementations§
impl<A> Freeze for MemTable<A>
impl<A> RefUnwindSafe for MemTable<A>where
A: RefUnwindSafe,
impl<A> Send for MemTable<A>
impl<A> Sync for MemTable<A>
impl<A> Unpin for MemTable<A>where
A: Unpin,
impl<A> UnwindSafe for MemTable<A>where
A: UnwindSafe,
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> 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