Struct node_replication::Log [−][src]
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
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
The Log is Send. The *mut u8 (rawp
) is never dereferenced.
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.