Generic

Struct Generic 

Source
pub struct Generic<R: Repo, T> { /* private fields */ }
Expand description

A commitlog generic over the storage backend as well as the type of records its Commits contain.

Implementations§

Source§

impl<R: Repo, T> Generic<R, T>

Source

pub fn open(repo: R, opts: Options) -> Result<Self>

Source

pub fn epoch(&self) -> u64

Get the current epoch.

See also: Commit::epoch.

Source

pub fn set_epoch(&mut self, epoch: u64) -> Result<Option<Committed>>

Update the current epoch.

Calls Self::commit to flush all data of the previous epoch, and returns the result.

Does nothing if the given epoch is equal to the current epoch.

§Errors

If epoch is smaller than the current epoch, an error of kind io::ErrorKind::InvalidInput is returned.

Also see Self::commit.

Source

pub fn commit(&mut self) -> Result<Option<Committed>>

Write the currently buffered data to storage and rotate segments as necessary.

Note that this does not imply that the data is durable, in particular when a filesystem storage backend is used. Call Self::sync to flush any OS buffers to stable storage.

§Errors

If an error occurs writing the data, the current Commit buffer is retained, but a new segment is created. Retrying in case of an Err return value thus will write the current data to that new segment.

If this fails, however, the next attempt to create a new segment will fail with io::ErrorKind::AlreadyExists. Encountering this error kind this means that something is seriously wrong underlying storage, and the caller should stop writing to the log.

Source

pub fn sync(&mut self)

Force the currently active segment to be flushed to storage.

Using a filesystem backend, this means to call fsync(2).

§Panics

As an fsync failure leaves a file in a more of less undefined state, this method panics in this case, thereby preventing any further writes to the log and forcing the user to re-read the state from disk.

Source

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

The last transaction offset written to disk, or None if nothing has been written yet.

Note that this does not imply durability: Self::sync may not have been called at this offset.

Source

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

The first transaction offset written to disk, or None if nothing has been written yet.

Source

pub fn commits_from(&self, offset: u64) -> Commits<R>

Source

pub fn reset(self) -> Result<Self>

Source

pub fn reset_to(self, offset: u64) -> Result<Self>

Source§

impl<R: Repo, T: Encode> Generic<R, T>

Source

pub fn append(&mut self, record: T) -> Result<(), T>

Source

pub fn transactions_from<'a, D>( &self, offset: u64, decoder: &'a D, ) -> impl Iterator<Item = Result<Transaction<T>, D::Error>> + 'a
where D: Decoder<Record = T>, D::Error: From<Traversal>, R: 'a, T: 'a,

Source

pub fn fold_transactions_from<D>( &self, offset: u64, decoder: D, ) -> Result<(), D::Error>
where D: Decoder, D::Error: From<Traversal>,

Trait Implementations§

Source§

impl<R: Debug + Repo, T: Debug> Debug for Generic<R, T>
where R::SegmentWriter: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<R: Repo, T> Drop for Generic<R, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<R, T> Freeze for Generic<R, T>
where R: Freeze, <R as Repo>::SegmentWriter: Freeze,

§

impl<R, T> RefUnwindSafe for Generic<R, T>

§

impl<R, T> Send for Generic<R, T>
where R: Send, T: Send,

§

impl<R, T> Sync for Generic<R, T>
where R: Sync, T: Sync,

§

impl<R, T> Unpin for Generic<R, T>
where R: Unpin, T: Unpin, <R as Repo>::SegmentWriter: Unpin,

§

impl<R, T> UnwindSafe for Generic<R, T>

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> Same for T

Source§

type Output = T

Should always be Self
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