#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.segment_size: u64Size 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: RecoveryPolicyWhat to do with a corrupt tail on open. Default: RecoveryPolicy::Quarantine.
notify: boolCreate 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: boolDo 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 withMADV_POPULATE_WRITE, soappendrarely 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: boolLinux: 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: HelperCpusWhere 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
impl WriterConfig
Sourcepub const DEFAULT_SEGMENT_SIZE: u64
pub const DEFAULT_SEGMENT_SIZE: u64
Default segment size: 128 MiB.
Sourcepub fn segment_size(self, bytes: u64) -> Self
pub fn segment_size(self, bytes: u64) -> Self
Sets the size of new segment files. Checked by Writer::open.
Sourcepub fn retention(self, policy: Policy, action: Action) -> Self
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.
Sourcepub fn recovery(self, policy: RecoveryPolicy) -> Self
pub fn recovery(self, policy: RecoveryPolicy) -> Self
Sets the recovery policy.
Sourcepub fn notify(self, on: bool) -> Self
pub fn notify(self, on: bool) -> Self
Sets whether to wake blocked readers (see WriterConfig::notify).
Sourcepub fn prefault(self, on: bool) -> Self
pub fn prefault(self, on: bool) -> Self
Sets whether to do segment work in a background thread (see WriterConfig::prefault).
Sourcepub fn early_writeback(self, on: bool) -> Self
pub fn early_writeback(self, on: bool) -> Self
Sets whether to start write-back early on Linux (see WriterConfig::early_writeback).
Sourcepub fn helper_cpus(self, cpus: HelperCpus) -> Self
pub fn helper_cpus(self, cpus: HelperCpus) -> Self
Sets where the writer’s helper threads run (see HelperCpus).