Struct Engine

Source
pub struct Engine<F = DefaultFileSystem, P = FilePipeLog<F>>
where F: FileSystem, P: PipeLog,
{ /* private fields */ }

Implementations§

Source§

impl Engine<DefaultFileSystem, FilePipeLog<DefaultFileSystem>>

Source§

impl<F> Engine<F, FilePipeLog<F>>
where F: FileSystem,

Source

pub fn open_with_file_system( cfg: Config, file_system: Arc<F>, ) -> Result<Engine<F, FilePipeLog<F>>>

Source

pub fn open_with( cfg: Config, file_system: Arc<F>, listeners: Vec<Arc<dyn EventListener>>, ) -> Result<Engine<F, FilePipeLog<F>>>

Source§

impl<F, P> Engine<F, P>
where F: FileSystem, P: PipeLog,

Source

pub fn write(&self, log_batch: &mut LogBatch, sync: bool) -> Result<usize>

Writes the content of log_batch into the engine and returns written bytes. If sync is true, the write will be followed by a call to fdatasync on the log file.

Source

pub fn sync(&self) -> Result<()>

Synchronizes the Raft engine.

Source

pub fn get_message<S: Message>( &self, region_id: u64, key: &[u8], ) -> Result<Option<S>>

Source

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

Source

pub fn scan_messages<S, C>( &self, region_id: u64, start_key: Option<&[u8]>, end_key: Option<&[u8]>, reverse: bool, callback: C, ) -> Result<()>
where S: Message, C: FnMut(&[u8], S) -> bool,

Iterates over [start_key, end_key) range of Raft Group key-values and yields messages of the required type. Unparsable items are skipped.

Source

pub fn scan_raw_messages<C>( &self, region_id: u64, start_key: Option<&[u8]>, end_key: Option<&[u8]>, reverse: bool, callback: C, ) -> Result<()>
where C: FnMut(&[u8], &[u8]) -> bool,

Iterates over [start_key, end_key) range of Raft Group key-values and yields all key value pairs as bytes.

Source

pub fn get_entry<M: MessageExt>( &self, region_id: u64, log_idx: u64, ) -> Result<Option<M::Entry>>

Source

pub fn purge_expired_files(&self) -> Result<Vec<u64>>

Purges expired logs files and returns a set of Raft group ids that need to be compacted.

Source

pub fn fetch_entries_to<M: MessageExt>( &self, region_id: u64, begin: u64, end: u64, max_size: Option<usize>, vec: &mut Vec<M::Entry>, ) -> Result<usize>

Returns count of fetched entries.

Source

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

Source

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

Source

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

Deletes log entries before index in the specified Raft group. Returns the number of deleted entries.

Source

pub fn raft_groups(&self) -> Vec<u64>

Source

pub fn is_empty(&self) -> bool

Returns true if the engine contains no Raft Group. Empty Raft Group that isn’t cleaned is counted as well.

Source

pub fn file_span(&self, queue: LogQueue) -> (u64, u64)

Returns the sequence number range of active log files in the specific log queue. For testing only.

Source

pub fn get_used_size(&self) -> usize

Source

pub fn path(&self) -> &str

Source

pub fn purge_manager(&self) -> &PurgeManager<P>

Source§

impl Engine<DefaultFileSystem, FilePipeLog<DefaultFileSystem>>

Source

pub fn consistency_check(path: &Path) -> Result<Vec<(u64, u64)>>

Source

pub fn unsafe_repair( path: &Path, queue: Option<LogQueue>, script: String, ) -> Result<()>

Source

pub fn dump(path: &Path) -> Result<LogItemReader<DefaultFileSystem>>

Source§

impl<F> Engine<F, FilePipeLog<F>>
where F: FileSystem,

Source

pub fn consistency_check_with_file_system( path: &Path, file_system: Arc<F>, ) -> Result<Vec<(u64, u64)>>

Returns a list of corrupted Raft groups, including their ids and last valid log index. Head or tail corruption cannot be detected.

Source

pub fn unsafe_repair_with_file_system( path: &Path, queue: Option<LogQueue>, script: String, file_system: Arc<F>, ) -> Result<()>

Source

pub fn dump_with_file_system( path: &Path, file_system: Arc<F>, ) -> Result<LogItemReader<F>>

Dumps all operations.

Source§

impl<F: FileSystem> Engine<F, FilePipeLog<F>>

Source

pub fn fork<T: AsRef<Path>>( source: &Config, fs: Arc<F>, target: T, ) -> Result<CopyDetails, String>

Make a copy from source to target. source should exists but target shouldn’t. And source shouldn’t be opened, otherwise data corruption can happen.

symlink will be used if possbile, otherwise copy will be used instead. Generally all inactive log files will be symlinked, but the last active one will be copied.

After the copy is made both of 2 engines can be started and run at the same time.

It reports errors if the source instance

  • is specified with enable_log_recycle = true. source and target can share log files, so log file reusing can cause data corruption.
  • is specified with recovery_mode = TolerateAnyCorruption, in which case symlink can’t be use. Users should consider to copy the instance directly.

Trait Implementations§

Source§

impl<F, P> Drop for Engine<F, P>
where F: FileSystem, P: PipeLog,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<F = DefaultFileSystem, P = DualPipes<F>> !Freeze for Engine<F, P>

§

impl<F = DefaultFileSystem, P = DualPipes<F>> !RefUnwindSafe for Engine<F, P>

§

impl<F, P> Send for Engine<F, P>
where P: Sync + Send,

§

impl<F, P> Sync for Engine<F, P>
where P: Sync + Send,

§

impl<F, P> Unpin for Engine<F, P>
where F: Unpin,

§

impl<F = DefaultFileSystem, P = DualPipes<F>> !UnwindSafe for Engine<F, P>

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