Raft v0.2.1 Raft.LogStore behaviour

The LogStore module provides a behaviour and high-level api for interacting with the underlying database engine. All values are encoded and decoded using :erlang.term_to_binary and :erlang.binary_to_term before they’re stored.

Link to this section Summary

Functions

Closes the connection to the database

Deletes a range of logs inclusively

Used to destroy the data on disk. This is used for testing and development and is dangerous to run in production

Returns metadata and all the persisted logs. This is used for debugging and testing purposes only and should not be used in production

Gets a log at a specific index

Gets all metadata from the store

Determines if anything has been written to the log yet

Retrieves the last entry from the log. Returns :empty if the log is empty

Retrieves the last index thats been saved to stable storage. If the database is empty then 0 is returned

Opens a new or existing database at the given path

Gets all logs from starting index to end index inclusive

Store logs in the log store and returns the last index

Stores the metadata

Link to this section Types

Link to this type metadata()
metadata() :: Raft.Log.Metadata.t()

Link to this section Functions

Link to this function close(db)
close(db()) :: :ok

Closes the connection to the database

Link to this function delete_range(db, range)

Deletes a range of logs inclusively

Used to destroy the data on disk. This is used for testing and development and is dangerous to run in production.

Returns metadata and all the persisted logs. This is used for debugging and testing purposes only and should not be used in production.

Link to this function get_entry(db, index)
get_entry(db(), index()) :: {:ok, Raft.Log.Entry.t()} | {:error, :not_found}

Gets a log at a specific index.

Link to this function get_metadata(db)
get_metadata(db()) :: metadata()

Gets all metadata from the store.

Link to this function has_data?(db)
has_data?(db()) :: boolean()

Determines if anything has been written to the log yet.

Link to this function last_entry(db)
last_entry(db()) :: {:ok, Raft.Log.Entry.t()} | {:ok, :empty}

Retrieves the last entry from the log. Returns :empty if the log is empty.

Link to this function last_index(db)
last_index(db()) :: index()

Retrieves the last index thats been saved to stable storage. If the database is empty then 0 is returned.

Link to this function open(path)
open(path()) :: db()

Opens a new or existing database at the given path.

Link to this function slice(db, range)

Gets all logs from starting index to end index inclusive.

Link to this function store_entries(db, entries)
store_entries(db(), [Raft.Log.Entry.t()]) :: {:ok, index()}

Store logs in the log store and returns the last index.

Link to this function store_metadata(db, meta)
store_metadata(db(), metadata()) :: :ok

Stores the metadata.

Link to this section Callbacks

Link to this callback close(db)
close(db()) :: :ok | {:error, any()}
Link to this callback destroy(db)
destroy(db()) :: :ok | {:error, any()}
Link to this callback get_entry(db, key)
get_entry(db(), key()) :: {:ok, encoded()} | {:error, :not_found}
Link to this callback get_metadata(db)
get_metadata(db()) :: {:ok, encoded()} | {:error, :not_found}
Link to this callback last_entry(db)
last_entry(db()) :: {:ok, encoded()} | {:ok, :empty}
Link to this callback open(path)
open(path()) :: {:ok, db()} | {:error, any()}
Link to this callback store_entry(db, key, encoded)
store_entry(db(), key(), encoded()) :: :ok | {:error, any()}
Link to this callback store_metadata(db, encoded)
store_metadata(db(), encoded()) :: :ok | {:error, any()}