Module riak_ensemble_lease

This module is used by riak_ensemble_peer to keep track of an established leader lease.

Description

This module is used by riak_ensemble_peer to keep track of an established leader lease. The leader is responsible for periodically refreshing its lease, otherwise the lease will timeout.

Using a time-based lease in a distributed system is not without issue. This module does its best to address these concerns as follows:

1. This module uses Erlang based timeouts to trigger lease expiration. Erlang uses time correction to attempt to occur for clock issues, as discussed here: http://www.erlang.org/doc/apps/erts/time_correction.html

2. In addition to Erlang time, this module also double checks the lease against the OS monotonic clock. The monotonic clock is not affected by the user/NTP changing the system clock, and is designed to always move forward (although, virtualization sometimes affects this guarantee).

Likewise, riak_ensemble is designed such that the lease and leader refresh are much smaller than the follower timeout. All of these factors, along with riak_ensemble being designed to maintain strong leadership (unlike other systems such as Raft) make the use of leader leases safe in practice. As a reminder, Google is also known to use leader leases it its paxos implementation as discussed in their "Paxos Made Live" paper.

Of course, users that do not trust leader leases can always set the trust_lease application variable to false, causing riak_ensemble to ignore leader leases and always perform full quorum operations.

Data Types

lease_ref()

lease_ref() = {pid(), ets:tid()}

Function Index

check_lease/1
init/2
lease/2
loop/2
start_link/0
unlease/1

Function Details

check_lease/1

check_lease(X1::lease_ref()) -> boolean()

init/2

init(Parent, Ref) -> any()

lease/2

lease(X1::lease_ref(), Duration::timeout()) -> ok

loop/2

loop(T, Timeout) -> any()

start_link/0

start_link() -> {ok, lease_ref()}

unlease/1

unlease(X1::lease_ref()) -> ok


Generated by EDoc