Struct 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§

Source§

impl<A: AllocatorTrait> MemTable<A>

Source

pub fn merge_newer_neighbor(&mut self, rhs: &mut Self)

Merges with a newer neighbor MemTable.

This method is only used for recovery.

Source

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.

Source

pub fn get(&self, key: &[u8]) -> Option<Vec<u8>>

Returns value for a given key.

Source

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.

Source

pub fn delete(&mut self, key: &[u8])

Deletes a key value pair.

Source

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.

Source

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.

Source

pub fn get_entry(&self, index: u64) -> Option<EntryIndex>

Returns the log entry location for a given logical log index.

Source

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).

Source

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.

Source

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).

Source

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.

Source

pub fn compact_to(&mut self, index: u64) -> u64

Removes all entries with index smaller than index. Returns the number of deleted entries.

Source

pub fn apply_rewrite_atomic_group(&mut self, start: FileSeq, end: FileSeq)

Source

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.

Source

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.

Source

pub fn fetch_rewritten_entry_indexes( &self, vec_idx: &mut Vec<EntryIndex>, ) -> Result<()>

Pulls all rewrite entries to the provided buffer.

Source

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.

Source

pub fn fetch_rewritten_kvs(&self, vec: &mut Vec<(Vec<u8>, Vec<u8>)>)

Pulls all rewrite key value pairs to the provided buffer.

Source

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.

Source

pub fn has_at_least_some_entries_before( &self, gate: FileId, count: usize, ) -> bool

Source

pub fn region_id(&self) -> u64

Returns the region ID.

Source

pub fn first_index(&self) -> Option<u64>

Returns the log index of the first log entry.

Source

pub fn last_index(&self) -> Option<u64>

Returns the log index of the last log entry.

Trait Implementations§

Source§

impl<A: AllocatorTrait> Drop for MemTable<A>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V