partisan_plumtree_backend (partisan v5.0.2)

View Source

This modules implements a server that realises the partisan_plumtree_broadcast_handler behaviour in order to diseminate heartbeat messages. Partisan uses these heartbeat messages to stimulate the Epidemic Broadcast Tree construction.

The server will schedule the sending of a hearbeat` message periodically using the `broadcast_heartbeat_interval` option. Notice that this handler does not perform AAE Exchanges, as we will always have a periodic heartbeat. For that reason, the implementation of the <a docgen-rel="seemfa" docgen-href="partisan_plumtree_broadcast_handler#exchange/1" href="partisan_plumtree_broadcast_handler.html#exchange-1"><code>partisan_plumtree_broadcast_handler:exchange/1</code></a> callback always returns `ignore.

Summary

Functions

Returns the channel to be used when broadcasting a message on behalf of this handler.

Returns from the broadcast message the identifier and the payload. In this case a tuple where both arguments have the broadcast message timestamp. These messages are used by Partisan as a stimulus for the Epidemic Broadcast Tree (Plumtree) construction.

Returns ignore`. This is because we dont need to worry about reliable delivery: we always know we'll have another heartbeat message to further repair during the next interval.

Given a message identifier and a clock, return a given message.

Use the clock on the object to determine if this message is stale or not. A message is stale if the received message is causually newer than an existing one. If the message is missing or if the context does not represent an ancestor of message, false is returned. Otherwise, true is returned.

Perform a merge of an incoming object with an object in the local datastore.

Same as start_link([]).

Start and link to calling process.

Returns all the timestamps.

Types

broadcast_id/0

-type broadcast_id() :: timestamp().

broadcast_message/0

-type broadcast_message() :: #broadcast{timestamp :: timestamp()}.

broadcast_payload/0

-type broadcast_payload() :: timestamp().

state/0

-type state() :: #state{node :: node(), epoch :: integer(), monotonic :: non_neg_integer()}.

timestamp/0

-type timestamp() :: {Node :: node(), Epoch :: integer(), Monotonic :: integer()}.

Functions

broadcast_channel()

-spec broadcast_channel() -> partisan:channel().

Returns the channel to be used when broadcasting a message on behalf of this handler.

broadcast_data(Broadcast)

-spec broadcast_data(broadcast_message()) -> {broadcast_id(), broadcast_payload()}.

Returns from the broadcast message the identifier and the payload. In this case a tuple where both arguments have the broadcast message timestamp. These messages are used by Partisan as a stimulus for the Epidemic Broadcast Tree (Plumtree) construction.

code_change(OldVsn, State, Extra)

-spec code_change(term() | {down, term()}, state(), term()) -> {ok, state()}.

exchange(Peer)

-spec exchange(node()) -> {ok, pid()} | {error, any()} | ignore.

Returns ignore`. This is because we dont need to worry about reliable delivery: we always know we'll have another heartbeat message to further repair during the next interval.

extract_log_type_and_payload(Message)

graft(Timestamp)

-spec graft(broadcast_id()) -> stale | {ok, broadcast_payload()} | {error, {not_found, timestamp()}}.

Given a message identifier and a clock, return a given message.

handle_call(Event, From, State)

-spec handle_call(term(), {pid(), term()}, state()) -> {reply, term(), state()}.

handle_cast(Event, State)

-spec handle_cast(term(), state()) -> {noreply, state()}.

handle_info(Event, State)

init(_)

-spec init([]) -> {ok, state()}.

is_stale(_)

-spec is_stale(broadcast_id()) -> boolean().

Use the clock on the object to determine if this message is stale or not. A message is stale if the received message is causually newer than an existing one. If the message is missing or if the context does not represent an ancestor of message, false is returned. Otherwise, true is returned.

merge(Timestamp, _)

-spec merge(broadcast_id(), broadcast_payload()) -> boolean().

Perform a merge of an incoming object with an object in the local datastore.

start_link()

-spec start_link() -> {ok, pid()} | ignore | {error, term()}.

Same as start_link([]).

start_link(Opts)

-spec start_link(list()) -> {ok, pid()} | ignore | {error, term()}.

Start and link to calling process.

terminate(Reason, State)

-spec terminate(term(), state()) -> term().

timestamps()

-spec timestamps() -> [timestamp()].

Returns all the timestamps.

Notice this can copy a lot of data from the ets table to the calling process.

In case partisan_config:get(broadcast) returns false, this function returns an empty list.