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
impl Partition
Sourcepub async fn open(dir: &Path, config: LogConfig) -> Result<Self>
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.
Sourcepub async fn append(&self, record: Record) -> Result<u64>
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.
Sourcepub async fn append_batch(&self, records: Vec<Record>) -> Result<Vec<u64>>
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.
Sourcepub async fn read_record_at(&self, offset: u64) -> Result<Option<Record>>
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.
Sourcepub async fn sync(&self) -> Result<()>
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.
Sourcepub fn high_water_mark(&self) -> u64
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.
Sourcepub fn watch_high_water_mark(&self) -> Receiver<u64>
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.
Sourcepub async fn shutdown(self) -> Result<()>
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.