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
impl Commit
pub const DEFAULT_EPOCH: u64 = 0u64
pub const FRAMING_LEN: usize = 26usize
pub const CHECKSUM_ALGORITHM: u8 = 0u8
pub const CHECKSUM_LEN: usize = 4usize
Sourcepub fn tx_range(&self) -> Range<u64>
pub fn tx_range(&self) -> Range<u64>
The range of transaction offsets contained in this commit.
Sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
Length in bytes of this commit when written to the log via Self::write
.
Sourcepub fn write<W: Write>(&self, out: W) -> Result<u32>
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.
Sourcepub fn decode<R: Read>(reader: R) -> Result<Option<Self>>
pub fn decode<R: Read>(reader: R) -> Result<Option<Self>>
Attempt to read one Commit
from the given Read
er.
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
.
Sourcepub fn into_transactions<D: Decoder>(
self,
version: u8,
from_offset: u64,
de: &D,
) -> impl Iterator<Item = Result<Transaction<D::Record>, D::Error>> + '_
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 Transaction
s.
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<'de> Deserialize<'de> for Commit
impl<'de> Deserialize<'de> for Commit
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<StoredCommit> for Commit
impl From<StoredCommit> for Commit
Source§fn from(_: StoredCommit) -> Self
fn from(_: StoredCommit) -> Self
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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