Repo

Trait Repo 

Source
pub trait Repo: Clone {
    type SegmentWriter: SegmentWriter + 'static;
    type SegmentReader: SegmentReader + 'static;

    // Required methods
    fn create_segment(&self, offset: u64) -> Result<Self::SegmentWriter>;
    fn open_segment_reader(&self, offset: u64) -> Result<Self::SegmentReader>;
    fn open_segment_writer(&self, offset: u64) -> Result<Self::SegmentWriter>;
    fn remove_segment(&self, offset: u64) -> Result<()>;
    fn compress_segment(&self, offset: u64) -> Result<()>;
    fn existing_offsets(&self) -> Result<Vec<u64>>;

    // Provided methods
    fn create_offset_index(
        &self,
        _offset: TxOffset,
        _cap: u64,
    ) -> Result<TxOffsetIndexMut> { ... }
    fn remove_offset_index(&self, _offset: TxOffset) -> Result<()> { ... }
    fn get_offset_index(&self, _offset: TxOffset) -> Result<TxOffsetIndex> { ... }
}
Expand description

A repository of log segments.

This is mainly an internal trait to allow testing against an in-memory representation.

Required Associated Types§

Source

type SegmentWriter: SegmentWriter + 'static

The type of log segments managed by this repo, which must behave like a file.

Source

type SegmentReader: SegmentReader + 'static

Required Methods§

Source

fn create_segment(&self, offset: u64) -> Result<Self::SegmentWriter>

Create a new segment with the minimum transaction offset offset.

This must create the segment atomically, and return io::ErrorKind::AlreadyExists if the segment already exists.

It is permissible, however, to successfully return the new segment if it is completely empty (i.e. create_segment_writer did not previously succeed in writing the segment header).

Source

fn open_segment_reader(&self, offset: u64) -> Result<Self::SegmentReader>

Open an existing segment at the minimum transaction offset offset.

Must return io::ErrorKind::NotFound if a segment with the given offset does not exist.

The method does not guarantee that the segment is non-empty – this case will be caught by open_segment_reader.

Source

fn open_segment_writer(&self, offset: u64) -> Result<Self::SegmentWriter>

Open an existing segment at the minimum transaction offset offset.

Must return io::ErrorKind::NotFound if a segment with the given offset does not exist.

The method does not guarantee that the segment is non-empty – this case will be caught by resume_segment_writer.

Source

fn remove_segment(&self, offset: u64) -> Result<()>

Remove the segment at the minimum transaction offset offset.

Return io::ErrorKind::NotFound if no such segment exists.

Source

fn compress_segment(&self, offset: u64) -> Result<()>

Compress a segment in storage, marking it as immutable.

Source

fn existing_offsets(&self) -> Result<Vec<u64>>

Traverse all segments in this repository and return list of their offsets, sorted in ascending order.

Provided Methods§

Source

fn create_offset_index( &self, _offset: TxOffset, _cap: u64, ) -> Result<TxOffsetIndexMut>

Create TxOffsetIndexMut for the given offset or open it if already exist. The cap parameter is the maximum number of entries in the index.

Source

fn remove_offset_index(&self, _offset: TxOffset) -> Result<()>

Remove TxOffsetIndexMut named with offset.

Source

fn get_offset_index(&self, _offset: TxOffset) -> Result<TxOffsetIndex>

Get TxOffsetIndex for the given offset.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: Repo> Repo for &T

Source§

fn remove_offset_index(&self, offset: TxOffset) -> Result<()>

Remove TxOffsetIndexMut named with offset.

Source§

fn get_offset_index(&self, offset: TxOffset) -> Result<TxOffsetIndex>

Get TxOffsetIndex for the given offset.

Source§

type SegmentWriter = <T as Repo>::SegmentWriter

Source§

type SegmentReader = <T as Repo>::SegmentReader

Source§

fn create_segment(&self, offset: u64) -> Result<Self::SegmentWriter>

Source§

fn open_segment_reader(&self, offset: u64) -> Result<Self::SegmentReader>

Source§

fn open_segment_writer(&self, offset: u64) -> Result<Self::SegmentWriter>

Source§

fn remove_segment(&self, offset: u64) -> Result<()>

Source§

fn compress_segment(&self, offset: u64) -> Result<()>

Source§

fn existing_offsets(&self) -> Result<Vec<u64>>

Source§

fn create_offset_index( &self, offset: TxOffset, cap: u64, ) -> Result<TxOffsetIndexMut>

Implementors§