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§
Sourcetype SegmentWriter: SegmentWriter + 'static
type SegmentWriter: SegmentWriter + 'static
The type of log segments managed by this repo, which must behave like a file.
type SegmentReader: SegmentReader + 'static
Required Methods§
Sourcefn create_segment(&self, offset: u64) -> Result<Self::SegmentWriter>
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).
Sourcefn open_segment_reader(&self, offset: u64) -> Result<Self::SegmentReader>
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.
Sourcefn open_segment_writer(&self, offset: u64) -> Result<Self::SegmentWriter>
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.
Sourcefn remove_segment(&self, offset: u64) -> Result<()>
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.
Sourcefn compress_segment(&self, offset: u64) -> Result<()>
fn compress_segment(&self, offset: u64) -> Result<()>
Compress a segment in storage, marking it as immutable.
Sourcefn existing_offsets(&self) -> Result<Vec<u64>>
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§
Sourcefn create_offset_index(
&self,
_offset: TxOffset,
_cap: u64,
) -> Result<TxOffsetIndexMut>
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.
Sourcefn remove_offset_index(&self, _offset: TxOffset) -> Result<()>
fn remove_offset_index(&self, _offset: TxOffset) -> Result<()>
Remove TxOffsetIndexMut named with offset.
Sourcefn get_offset_index(&self, _offset: TxOffset) -> Result<TxOffsetIndex>
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".
Implementations on Foreign Types§
Source§impl<T: Repo> Repo for &T
impl<T: Repo> Repo for &T
Source§fn remove_offset_index(&self, offset: TxOffset) -> Result<()>
fn remove_offset_index(&self, offset: TxOffset) -> Result<()>
Remove TxOffsetIndexMut named with offset.
Source§fn get_offset_index(&self, offset: TxOffset) -> Result<TxOffsetIndex>
fn get_offset_index(&self, offset: TxOffset) -> Result<TxOffsetIndex>
Get TxOffsetIndex for the given offset.