Skip to main content

Partition

Struct Partition 

Source
pub struct Partition { /* private fields */ }
Expand description

Single-partition log with its own writer task.

Owns one Log (segments + sparse index) and a single writer task that serializes all appends — the single-writer-per-partition invariant. Producers and consumers communicate with the writer via an mpsc inbox; the writer publishes the partition’s high-water-mark on a watch channel so consumers can wait for new data without polling.

Implementations§

Source§

impl Partition

Source

pub async fn open(dir: &Path, config: LogConfig) -> Result<Self>

Opens (or recovers) a partition rooted at dir and spawns its writer task. Usually called by Kafko rather than directly.

Source

pub async fn append(&self, record: Record) -> Result<u64>

Appends a single record and returns its assigned offset. Producers usually call this via Producer::send rather than directly.

Source

pub async fn append_batch(&self, records: Vec<Record>) -> Result<Vec<u64>>

Appends a batch of records as a single atomic unit and returns the assigned offsets in input order. The batch becomes visible at the partition’s high-water-mark together — consumers never observe a partial batch. Producers usually call this via Producer::send_batch rather than directly.

An empty input is a no-op that returns Ok(Vec::new()) without contacting the writer task.

Source

pub async fn read_record_at(&self, offset: u64) -> Result<Option<Record>>

Reads the record at offset, returning Ok(None) if offset is past the current high-water-mark. Consumers usually call this via Consumer::next_record rather than directly.

Source

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

Forces the active segment + index to be fsynced to disk. Resolves only after the kernel reports the syscall complete. Use this when you need a hard durability point without shutting the broker down.

Source

pub fn high_water_mark(&self) -> u64

Returns the offset of the next record this partition will assign — i.e., last_assigned_offset + 1, or 0 for an empty partition.

Source

pub fn watch_high_water_mark(&self) -> Receiver<u64>

Returns a watch::Receiver that updates whenever a new record is appended. Useful for building consumers or back-pressure logic without polling high_water_mark.

Source

pub async fn shutdown(self) -> Result<()>

Gracefully shuts the partition’s writer task down: drains the inbox, fsyncs the active segment + index, and exits. Resolves only after the final fsync completes. Usually called by Kafko::shutdown rather than directly.

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