pub struct JournalWriter { /* private fields */ }Expand description
The background actor that owns the write path to a LocalBackend’s durable.db.
Construct it with JournalWriter::new (which also returns the handle), then drive it with
JournalWriter::run on a supervised task.
Implementations§
Source§impl JournalWriter
impl JournalWriter
Sourcepub fn new(
backend: Arc<LocalBackend>,
config: &DurableConfig,
) -> (Self, JournalWriterHandle)
pub fn new( backend: Arc<LocalBackend>, config: &DurableConfig, ) -> (Self, JournalWriterHandle)
Build the writer and its cloneable handle from a backend and the durable configuration.
The flush interval and ACK timeout are taken from config; the channel is bounded at the
spec capacity. Spawn JournalWriter::run to start processing.
§Examples
use std::sync::Arc;
use zeph_durable::{DurableConfig, LocalBackend, JournalWriter};
let backend = Arc::new(LocalBackend::open("durable.db", 1_048_576).await?);
backend.init().await?;
let (writer, handle) = JournalWriter::new(backend, &DurableConfig::default());
let task = tokio::spawn(writer.run());
// ... use `handle` to append; drop all handles to stop the writer ...Sourcepub async fn run(self)
pub async fn run(self)
Run the actor loop until every JournalWriterHandle is dropped.
On entry the writer reads MAX(seq) to resume from the last committed entry (FR-DE-12). It
then group-commits buffered entries on each flush tick (or when the batch fills), flushes
before every acked commit (INV-4), and emits a durable.journal.writer.queue_depth gauge per
commit cycle. When the channel closes it drains any remaining buffered entries and returns,
so the supervisor can restart it cleanly.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for JournalWriter
impl !UnwindSafe for JournalWriter
impl Freeze for JournalWriter
impl Send for JournalWriter
impl Sync for JournalWriter
impl Unpin for JournalWriter
impl UnsafeUnpin for JournalWriter
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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