Struct Log

Source
#[repr(align(64))]
pub struct Log<'a, T>
where T: Sized + Clone,
{ /* private fields */ }
Expand description

A log of operations that is typically accessed by multiple Replica.

Operations can be added to the log by calling the append() method and providing a list of operations to be performed.

Operations already on the log can be executed by calling the exec() method and providing a replica-id along with a closure. Newly added operations since the replica last called exec() will be executed by invoking the supplied closure for each one of them.

Accepts one generic type parameter; T defines the type of operations and their arguments that will go on the log and would typically be an enum class.

This struct is aligned to 64 bytes optimizing cache access.\

§Note

As a client, typically there is no need to call any methods on the Log aside from new. Only in the rare circumstance someone would implement their own Replica would it be necessary to call any of the Log’s methods.

Implementations§

Source§

impl<'a, T> Log<'a, T>
where T: Sized + Clone,

Source

pub fn new<'b>(bytes: usize) -> Log<'b, T>

Constructs and returns a log of size bytes bytes. A size between 1-2 MiB usually works well in most cases.

§Example
use node_replication::Log;

// Operation type that will go onto the log.
#[derive(Clone)]
enum Operation {
    Read,
    Write(u64),
    Invalid,
}

// Creates a 1 Mega Byte sized log.
let l = Log::<Operation>::new(1 * 1024 * 1024);

This method also allocates memory for the log upfront. No further allocations will be performed once this method returns.

Trait Implementations§

Source§

impl<'a, T> Debug for Log<'a, T>
where T: Sized + Clone,

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T> Default for Log<'a, T>
where T: Sized + Clone,

Source§

fn default() -> Self

Default constructor for the shared log.

Source§

impl<'a, T> Drop for Log<'a, T>
where T: Sized + Clone,

Source§

fn drop(&mut self)

Destructor for the shared log.

Source§

impl<'a, T> Send for Log<'a, T>
where T: Sized + Clone,

The Log is Send. The *mut u8 (rawp) is never dereferenced.

Source§

impl<'a, T> Sync for Log<'a, T>
where T: Sized + Clone,

The Log is Sync. We know this because: head and tail are atomic variables, append() reserves entries using a CAS, and exec() does not concurrently mutate entries on the log.

Auto Trait Implementations§

§

impl<'a, T> !Freeze for Log<'a, T>

§

impl<'a, T> !RefUnwindSafe for Log<'a, T>

§

impl<'a, T> Unpin for Log<'a, T>

§

impl<'a, T> !UnwindSafe for Log<'a, T>

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.