pub struct MessageLog {
    pub open_segment_max_offset: u64,
    /* private fields */
}

Fields§

§open_segment_max_offset: u64

Implementations§

source§

impl MessageLog

source

pub fn open(path: impl AsRef<Path>) -> Result<Self, OpenError>

source

pub fn options() -> OpenOptions

source

pub fn append(&mut self, message: impl AsRef<[u8]>) -> Result<()>

source

pub fn flush(&mut self) -> Result<()>

source

pub fn sync_all(&mut self) -> Result<()>

source

pub fn size(&self) -> u64

source

pub fn max_segment_size(&self) -> u64

source

pub fn total_segments(&self) -> usize

Total number of segments currently comprising the log.

Equivalent to self.segments().count(), but more efficient.

source

pub fn get_root(&self) -> PathBuf

source

pub fn segments(&self) -> Segments

Obtains an iterator over all segments in the log, in the order they were created.

The iterator represents a snapshot of the log at the time this method is called. That is, segments created after the method returns will not appear in the iteration. The last segment yielded by the iterator may be incomplete (i.e. still be appended to).

See also: MessageLog::segments_from

source

pub fn segments_from(&self, offset: u64) -> Segments

Obtains an iterator over all segments containing messages equal to or newer than offset.

offset counts all messages (not: bytes) in the log, starting from zero.

Note that the first segment yielded by the iterator may contain messages with an offset smaller than the argument, as segments do not currently support slicing.

If offset is larger than the offset of any message already written to the log, an empty iterator is returned.

The iterator represents a snapshot of the log at the time this method is called. That is, segments created after the method returns will not appear in the iteration. The last segment yielded by the iterator may be incomplete (i.e. still be appended to).

source

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

Truncate the log to message offset offset.

This method destructively modifies the on-disk log!

After reset_to returns successfully, the message offset will be the last message in the log. That is:

  • reset_to(0) will leave exactly zero messages in the log
  • reset_to(1) will leave exactly one message in the log
  • reset_to(n) will leave min(n, open_segment_max_offset) messages in the log

Segments with an offset range greater than offset will be removed. Note that this may interfere with readers which operate on a snapshot of the internal state of MessageLog (i.e. the Segments iterator).

Setting the new offset (i.e. self.open_segment_max_offset) is not atomic, because MessageLog operates on multiple segment files internally.

For example, the given offset may require some number of segment files at the end of the log to be deleted. Deleting a file could fail, in which case this method returns an error. The new offset in this case will be the max offset of the segment which could not be deleted, but potentially be greater than offset.

However, file operations (unlink, ftruncate) are guaranteed to be atomic, to the extent required by POSIX.

Trait Implementations§

source§

impl Debug for MessageLog

source§

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

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

impl Drop for MessageLog

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more