Struct LockFreeLog

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

lock-free log-structured storage A sequential store which allows users to create reservations placed at known log offsets, used for writing persistent data structures that need to know where to find persisted bits in the future.

§Working with LockFreeLog

use rsdb::Log;

let log = rsdb::Config::default().log();
let first_offset = log.write(b"1".to_vec());
log.write(b"22".to_vec());
log.write(b"333".to_vec());

// stick an abort in the middle, which should not be returned
let res = log.reserve(b"never_gonna_hit_disk".to_vec());
res.abort();

log.write(b"4444".to_vec());
let last_offset = log.write(b"55555".to_vec());
log.make_stable(last_offset);
let mut iter = log.iter_from(first_offset);
assert_eq!(iter.next().unwrap().1, b"1".to_vec());
assert_eq!(iter.next().unwrap().1, b"22".to_vec());
assert_eq!(iter.next().unwrap().1, b"333".to_vec());
assert_eq!(iter.next().unwrap().1, b"4444".to_vec());
assert_eq!(iter.next().unwrap().1, b"55555".to_vec());
assert_eq!(iter.next(), None);

Implementations§

Source§

impl LockFreeLog

Source

pub fn start_system(config: Config) -> LockFreeLog

create new lock-free log

Source

pub fn flush(&self)

Flush the next io buffer.

Trait Implementations§

Source§

impl Drop for LockFreeLog

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Log for LockFreeLog

Source§

fn config(&self) -> &Config

return the config in use for this log

Source§

fn read(&self, id: u64) -> Result<LogRead>

read a buffer from the disk

Source§

fn stable_offset(&self) -> u64

returns the current stable offset written to disk

Source§

fn make_stable(&self, id: u64)

blocks until the specified id has been made stable on disk

Source§

fn punch_hole(&self, id: u64)

deallocates the data part of a log id

Source§

fn reserve(&self, buf: Vec<u8>) -> Reservation<'_>

Create a log offset reservation for a particular write, which may later be filled or canceled.
Source§

fn write(&self, buf: Vec<u8>) -> u64

Write a buffer to underlying storage.
Source§

fn iter_from(&self, id: u64) -> LogIter<'_, Self>

Return an iterator over the log, starting with a specified offset.
Source§

impl Send for LockFreeLog

Source§

impl Sync for LockFreeLog

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.