Struct AsyncJournalWriter
pub struct AsyncJournalWriter { /* private fields */ }Expand description
Journal writer that stamps events inline and writes to disk on a background thread.
The stamping work (seq assignment, hash chain, serialization) happens
synchronously in append() — only the write_all() and
sync_all() calls are moved off the hot path.
Implementations§
§impl AsyncJournalWriter
impl AsyncJournalWriter
pub fn new(
writer: JournalWriter,
batch_interval: Duration,
) -> Result<Self, JournalError>
pub fn new( writer: JournalWriter, batch_interval: Duration, ) -> Result<Self, JournalError>
Wrap a JournalWriter, spawning a background thread for disk I/O.
batch_interval controls how often the background thread calls
sync_all(). A shorter interval reduces data-at-risk on crash; a
longer interval improves throughput. Default: 100 ms.
pub fn with_defaults(writer: JournalWriter) -> Result<Self, JournalError>
pub fn with_defaults(writer: JournalWriter) -> Result<Self, JournalError>
Create with the default 100 ms batch interval.
pub fn append(
&mut self,
event: EngineEvent,
) -> Result<EngineEvent, JournalError>
pub fn append( &mut self, event: EngineEvent, ) -> Result<EngineEvent, JournalError>
Stamp the event inline and send the frame to the background writer.
Returns the stamped event (with seq, hash chain, etc. finalized). The disk write happens asynchronously on the background thread.
pub fn last_record_hash(&self) -> Option<&str>
pub fn last_record_hash(&self) -> Option<&str>
Return the last record hash.
pub fn shutdown(&mut self) -> Result<(), JournalError>
pub fn shutdown(&mut self) -> Result<(), JournalError>
Flush all pending writes, fsync, and join the background thread.
Any I/O error that occurred in the background thread is propagated.
After shutdown, append() will fail (channel disconnected).
pub fn into_inner(self) -> Result<JournalWriter, JournalError>
pub fn into_inner(self) -> Result<JournalWriter, JournalError>
Shutdown the background thread and return the inner JournalWriter.
After this call, the inner writer can be used for direct synchronous I/O (e.g. in tests or during shutdown verification). The stamper state (seq, hash chain) is preserved.