Skip to main content

DirectFileRing

Struct DirectFileRing 

Source
pub struct DirectFileRing { /* private fields */ }
Expand description

Non-mmap positioned-I/O ring with page-cache bypass.

Implementations§

Source§

impl DirectFileRing

Source

pub fn create( base_path: impl AsRef<Path>, capacity: usize, ) -> Result<Self, DirectFileError>

Obtain the ring at base_path over three files: {base}.directfile.data.bin (the slot array, unbuffered), {base}.directfile.head.bin (head counter, MMF), {base}.directfile.tail.bin (tail counter, MMF). Initializes them only where they do not yet exist, and otherwise attaches with queued slots and both counters in place. The data file carries no header, so capacity is checked against its exact byte size; a different capacity is a LayoutMismatch. reset reinitializes.

Source

pub fn reset( base_path: impl AsRef<Path>, capacity: usize, ) -> Result<Self, DirectFileError>

Truncate the three files at base_path and initialize an empty ring, discarding queued slots live peers hold. For a caller that knows it owns the base path.

Source

pub fn open( base_path: impl AsRef<Path>, expected_capacity: usize, ) -> Result<Self, DirectFileError>

Open an existing ring at base_path (a second process).

Source

pub fn capacity(&self) -> usize

Capacity in slots.

Source

pub fn head(&self) -> u64

Current head index.

Source

pub fn tail(&self) -> u64

Current tail index.

Source

pub fn try_push(&self, payload: &[u8]) -> Result<(), DirectFileError>

Push a payload: copy it into a page-aligned buffer and write it at the head’s slot offset with the page cache bypassed. Returns Err(Full) when head - tail == capacity.

Source

pub fn try_pop(&self, out: &mut [u8]) -> Result<usize, DirectFileError>

Pop the oldest payload: read the tail’s slot into a page-aligned buffer (page cache bypassed), copy the relevant bytes to out, and advance the tail.

Trait Implementations§

Source§

impl Drop for DirectFileRing

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for DirectFileRing

Source§

impl Sync for DirectFileRing

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.