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↑
dirty_read(key) | Read the |
extend_lease(key, value, lease_length \\ 2000) | Extends the lease on given |
lag() | Provides a lag metric for the cluster |
lock(key, value, lease_length \\ 2000, timeout \\ 5000) | Tries to acquire the lock |
master_dirty_read(key) | Execute a dirty read on the master. Same caveats as for
|
release(key, value, timeout \\ 5000) | Releases the lock on given |
set_nodes(cluster, primaries, replicas) | Sets the primaries and replicas for the given cluster. Assumes no failures |
set_w(cluster, w) | Sets the desired write quorum for the given cluster |
start(type, args) | Callback implementation for |
summary() | Some internal stats |
update(key, value, new_value, timeout \\ 5000) | Tries to update the lock. The update only happens if an
existing value of the lock corresponds to the given |
wait_for(key, timeout \\ 5000) | 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 |
wait_for_release(key, timeout \\ 5000) | 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:
- lag :: {number, reply}
Provides a lag metric for the cluster.
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.
Callback implementation for c::application.start/2
.
Specs:
- summary :: [write_locks: pos_integer, leases: pos_integer]
Some internal stats.
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.
Specs:
- wait_for_release(any, pos_integer) :: {:ok, any}
Waits for the key to be released.