Skip to main content

WriterConfig

Struct WriterConfig 

Source
#[non_exhaustive]
pub struct WriterConfig { pub segment_size: u64, pub recovery: RecoveryPolicy, pub notify: bool, pub prefault: bool, pub early_writeback: bool, pub helper_cpus: HelperCpus, pub retention: Option<(Policy, Action)>, }
Expand description

Writer settings. Construct with WriterConfig::default and the builder methods.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§segment_size: u64

Size of each new segment file in bytes. A multiple of 65,536, from 65,536 to 2^40. Default: 128 MiB. Existing segments keep the size they were created with.

§recovery: RecoveryPolicy

What to do with a corrupt tail on open. Default: RecoveryPolicy::Quarantine.

§notify: bool

Create a shared-memory wake-up region, named in the journal’s notify record, so that blocked readers wake up as soon as a record is published (ADRs 0017 and 0021), or, for Writer::append_batch, once the batch’s last record is, plus at each roll inside the batch (ADR 0041). Costs one atomic increment and one load per append (per batch for append_batch), plus a wake-up system call when readers are blocked. Default: true.

§prefault: bool

Do segment work in a background thread, off the writer’s thread. That thread never writes records.

  • Linux: a helper thread (tickertape-prefault) faults in the 256 KiB ahead of the write position with MADV_POPULATE_WRITE, so append rarely takes a page fault (ADR 0025). On kernels before 5.14 the helper stops on first use.
  • macOS: the helper keeps 8 MiB ahead with madvise(MADV_WILLNEED) (ADR 0020). Once the active segment is half full, a short-lived thread (tickertape-spare) also preallocates the next segment, so a roll only writes and links its header (ADR 0022). That spare isn’t used on Linux (ADR 0023).

Set to false for a writer that starts no threads, except the checkpoint thread that Writer::request_checkpoint starts; that also turns off WriterConfig::early_writeback. Default: true.

§early_writeback: bool

Linux: start the kernel’s write-back of the pages the writer has finished with, as it goes, so that a checkpoint finds little left to write (ADR 0038 → Early write-back). Applies only with WriterConfig::prefault on, which is the switch for the writer’s helper threads. A helper thread (tickertape-writeback) calls sync_file_range(SYNC_FILE_RANGE_WRITE) over the whole pages behind the write position each time it has moved 1 MiB, and over the rest of a segment when the writer rolls past it. That call only starts writing; it makes nothing durable: what is durable when is unchanged, and only a checkpoint promises it (docs/crash-contract.md). If the call fails with an I/O error, no later checkpoint of this writer succeeds (the error is returned by the next checkpoint, as a failed sync would be); if the filesystem does not support it, the helper stops. macOS: no effect (it has no call that starts write-back of a range without waiting for it). Default: true.

§helper_cpus: HelperCpus

Where the writer’s helper threads run: the checkpoint thread (tickertape-checkpoint), the prefault and write-back helpers (tickertape-prefault, tickertape-writeback) and the spare-segment thread (tickertape-spare). See HelperCpus. Default: HelperCpus::Process.

§retention: Option<(Policy, Action)>

Optional retention policy and action, run after open and successful checkpoints. Default: none.

Implementations§

Source§

impl WriterConfig

Source

pub const DEFAULT_SEGMENT_SIZE: u64

Default segment size: 128 MiB.

Source

pub fn segment_size(self, bytes: u64) -> Self

Sets the size of new segment files. Checked by Writer::open.

Source

pub fn retention(self, policy: Policy, action: Action) -> Self

Enables retention after open and every successful checkpoint. Failures are recorded by Writer::last_retention_error, without failing open, appends or checkpoints. The archive directory must already exist.

Source

pub fn recovery(self, policy: RecoveryPolicy) -> Self

Sets the recovery policy.

Source

pub fn notify(self, on: bool) -> Self

Sets whether to wake blocked readers (see WriterConfig::notify).

Source

pub fn prefault(self, on: bool) -> Self

Sets whether to do segment work in a background thread (see WriterConfig::prefault).

Source

pub fn early_writeback(self, on: bool) -> Self

Sets whether to start write-back early on Linux (see WriterConfig::early_writeback).

Source

pub fn helper_cpus(self, cpus: HelperCpus) -> Self

Sets where the writer’s helper threads run (see HelperCpus).

Trait Implementations§

Source§

impl Clone for WriterConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WriterConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WriterConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for WriterConfig

Source§

impl PartialEq for WriterConfig

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for WriterConfig

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.