Struct raft_engine::internals::MemTable
source · [−]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
sourceimpl<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<()>where
F: FnMut(&[u8], &[u8]) -> bool,
pub fn scan<F>(
&self,
start_key: Option<&[u8]>,
end_key: Option<&[u8]>,
reverse: bool,
f: F
) -> Result<()>where
F: FnMut(&[u8], &[u8]) -> bool,
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.
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> 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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more