Struct Commit

Source
pub struct Commit {
    pub min_tx_offset: u64,
    pub epoch: u64,
    pub n: u16,
    pub records: Vec<u8>,
}
Expand description

Entry type of a crate::Commitlog.

Fields§

§min_tx_offset: u64

The offset of the first record in this commit.

The offset starts from zero and is counted from the beginning of the entire log.

§epoch: u64

The epoch within which the commit was created.

Indicates the monotonically increasing term number of the leader when the commitlog is being written to in a distributed deployment.

The default epoch is 0 (zero). It should be used when the log is written to by a single process.

Note, however, that an existing log may have a non-zero epoch. It is currently unspecified how a commitlog is transitioned between distributed and single-node deployment, wrt the epoch.

§n: u16

The number of records in the commit.

§records: Vec<u8>

A buffer of all records in the commit in serialized form.

Readers must bring their own crate::Decoder to interpret this buffer. n indicates how many records the buffer contains.

Implementations§

Source§

impl Commit

Source

pub const DEFAULT_EPOCH: u64 = 0u64

Source

pub const FRAMING_LEN: usize = 26usize

Source

pub const CHECKSUM_ALGORITHM: u8 = 0u8

Source

pub const CHECKSUM_LEN: usize = 4usize

Source

pub fn tx_range(&self) -> Range<u64>

The range of transaction offsets contained in this commit.

Source

pub fn encoded_len(&self) -> usize

Length in bytes of this commit when written to the log via Self::write.

Source

pub fn write<W: Write>(&self, out: W) -> Result<u32>

Serialize and write self to out.

Returns the crc32 checksum of the commit on success.

Source

pub fn decode<R: Read>(reader: R) -> Result<Option<Self>>

Attempt to read one Commit from the given Reader.

Returns None if the reader is already at EOF.

Verifies the checksum of the commit. If it doesn’t match, an error of kind io::ErrorKind::InvalidData with an inner error downcastable to ChecksumMismatch is returned.

To retain access to the checksum, use StoredCommit::decode.

Source

pub fn into_transactions<D: Decoder>( self, version: u8, from_offset: u64, de: &D, ) -> impl Iterator<Item = Result<Transaction<D::Record>, D::Error>> + '_

Convert self into an iterator yielding Transactions.

The supplied Decoder is responsible for extracting individual transactions from the records buffer.

version is the log format version of the current segment, and gets passed to Decoder::decode_record.

from_offset is the transaction offset within the current commit from which to start decoding. That is:

  • if the tx offset within the commit is smaller than from_offset, Decoder::skip_record is called.

    The iterator does not yield a value, unless skip_record returns an error.

  • if the tx offset within the commit is greater of equal to from_offset, Decoder::decode_record is called.

    The iterator yields the result of this call.

  • if from_offset doesn’t fall into the current commit, the iterator yields nothing.

Trait Implementations§

Source§

impl Clone for Commit

Source§

fn clone(&self) -> Commit

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Commit

Source§

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

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

impl Default for Commit

Source§

fn default() -> Commit

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Commit

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Commit> for Metadata

Source§

fn from(commit: Commit) -> Self

Converts to this type from the input type.
Source§

impl From<StoredCommit> for Commit

Source§

fn from(_: StoredCommit) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Commit

Source§

fn eq(&self, other: &Commit) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Commit

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Commit

Auto Trait Implementations§

§

impl Freeze for Commit

§

impl RefUnwindSafe for Commit

§

impl Send for Commit

§

impl Sync for Commit

§

impl Unpin for Commit

§

impl UnwindSafe for Commit

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,