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.

Source

Summary

dirty_read(key)

Read the value for the given key

extend_lease(key, value, lease_length \\ 2000)

Extends the lease on given key and value

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 dirty_read/1

release(key, value, timeout \\ 5000)

Releases the lock on given key. The value needs to match to the locked value

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 c::application.start/2

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 value within the w number of master nodes

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 timeout. In case of timeout, the caller might get a reply anyway if it sent at the same time as the timeout

wait_for_release(key, timeout \\ 5000)

Waits for the key to be released

Types

reply :: {:ok, pos_integer, pos_integer, pos_integer}

Functions

dirty_read(key)

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.

Source
extend_lease(key, value, lease_length \\ 2000)

Specs:

  • extend_lease(any, any, pos_integer) :: reply | {:error, :no_quorum}

Extends the lease on given key and value.

Source
lag()

Specs:

Provides a lag metric for the cluster.

Source
lock(key, value, lease_length \\ 2000, timeout \\ 5000)

Specs:

  • lock(any, any, pos_integer, pos_integer) :: reply | {:error, :no_quorum}

Tries to acquire the lock.

Source
master_dirty_read(key)

Specs:

  • master_dirty_read(any) :: {:ok, any} | {:error, :not_found}

Execute a dirty read on the master. Same caveats as for dirty_read/1.

Source
release(key, value, timeout \\ 5000)

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.

Source
set_nodes(cluster, primaries, replicas)

Specs:

  • set_nodes([atom], [atom], [atom] | []) :: :ok

Sets the primaries and replicas for the given cluster. Assumes no failures.

Source
set_w(cluster, w)

Specs:

  • set_w([atom], pos_integer) :: :ok

Sets the desired write quorum for the given cluster.

Source
start(type, args)

Callback implementation for c::application.start/2.

Source
summary()

Specs:

  • summary :: [write_locks: pos_integer, leases: pos_integer]

Some internal stats.

Source
update(key, value, new_value, timeout \\ 5000)

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.

Source
wait_for(key, timeout \\ 5000)

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.

Source
wait_for_release(key, timeout \\ 5000)

Specs:

  • wait_for_release(any, pos_integer) :: {:ok, any}

Waits for the key to be released.

Source