Locker
Provides Elixir API to locker Erlang library as well as some utilities that make using locker easier.
Locker is a distributed, de-centralized, consistent in-memory
key-value store written in Erlang by a company called Wooga. The
locker Erlang project can be found from
https://github.com/wooga/locker
.
This module provides pretty much direct mapping of the locker API
for Elixir as well as some useful mix-in classes for creating long
running locker registered processes. See Locker.Server
and
Locker.Fsm
. It also provides a process registry,
Locker.Registry
, that can be used using e.g., GenServer
‘s
{:via, module, term}
API.
Summary
Functions
Read the value
for the given key
Extends the lease on given key
and value
Provides a lag metric for the cluster
Tries to acquire the lock
Execute a dirty read on the master. Same caveats as for
dirty_read/1
Releases the lock on given key
. The value
needs to match to the
locked value
Sets the primaries and replicas for the given cluster. Assumes no failures
Sets the desired write quorum for the given cluster
Callback implementation for c::application.start/2
Some internal stats
Tries to update the lock. The update only happens if an
existing value of the lock corresponds to the given value
within the
w
number of master nodes
Waits for the key to become available on the local node. If a value
is already available, returns immediately, otherwise it will return
within the timeout
. In case of timeout, the caller might get a reply
anyway if it sent at the same time as the timeout
Waits for the key to be released
Types
reply :: {:ok, pos_integer, pos_integer, pos_integer}
Functions
Specs
dirty_read(any) :: {:ok, any} | {:error, :not_found}
Read the value
for the given key
.
A dirty read does not create a read-quorum so consistency is not guaranteed. The value is read directly from a local ETS-table, so the performance should be very high.
Specs
extend_lease(any, any, pos_integer) ::
reply |
{:error, :no_quorum}
Extends the lease on given key
and value
.
Specs
lock(any, any, pos_integer, pos_integer) ::
reply |
{:error, :no_quorum}
Tries to acquire the lock.
Specs
master_dirty_read(any) ::
{:ok, any} |
{:error, :not_found}
Execute a dirty read on the master. Same caveats as for
dirty_read/1
.
Specs
release(any, any, pos_integer) ::
reply |
{:error, :no_quorum}
Releases the lock on given key
. The value
needs to match to the
locked value.
Specs
set_nodes([atom], [atom], [atom] | []) :: :ok
Sets the primaries and replicas for the given cluster. Assumes no failures.
Specs
set_w([atom], pos_integer) :: :ok
Sets the desired write quorum for the given cluster.
Specs
update(any, any, pos_integer, pos_integer) ::
reply |
{:error, :no_quorum}
Tries to update the lock. The update only happens if an
existing value of the lock corresponds to the given value
within the
w
number of master nodes.
Specs
wait_for(any, pos_integer) :: {:ok, any}
Waits for the key to become available on the local node. If a value
is already available, returns immediately, otherwise it will return
within the timeout
. In case of timeout, the caller might get a reply
anyway if it sent at the same time as the timeout.