Module eetcd_election

Data Types

campaign_ctx()

campaign_ctx() = #{campaign => map() | waiting_campaign_response, http2_pid => pid(), monitor_ref => reference(), stream_ref => reference()}

observe_ctx()

observe_ctx() = #{leader => map(), http2_pid => pid(), monitor_ref => reference(), stream_ref => reference()}

Function Index

campaign/1 Campaign waits to acquire leadership in an election, returning a LeaderKey representing the leadership if successful.
campaign/4
campaign_request/4campaign async to acquire leadership.
campaign_response/2handle campaign async response Etcd.CampaignResponse.
leader/1 Leader returns the current election proclamation, if any.
leader/2
new/1Creates a blank context for a request.
observe/3Observe streams election proclamations in-order as made by the election's elected leaders.
observe_stream/2handle observe stream Etcd.LeaderResponse.
proclaim/1 Proclaim updates the leader's posted value with a new value.
proclaim/3
resign/1 Resign releases election leadership so other campaigners may acquire leadership on the election.
resign/2
with_leader/2 leader describes the resources used for holding leadership of the election.
with_lease/2lease is the ID of the lease attached to leadership of the election.
with_name/2name is the election's identifier for the campaign.
with_timeout/2Timeout is an integer greater than zero which specifies how many milliseconds to wait for a reply, or the atom infinity to wait indefinitely.

Function Details

campaign/1

campaign(Ctx::context()) -> {ok, router_pb:'Etcd.CampaignResponse'()} | {error, eetcd_error()}

Campaign waits to acquire leadership in an election, returning a LeaderKey representing the leadership if successful. The LeaderKey can then be used to issue new values on the election, transactionally guard API requests on leadership still being held, and resign from the election.

1. base
eetcd_election:campaign(ConnName, Name, LeaseId, Value).
2. elixir
   :eetcd_election.new(connName)
   |> :eetcd_election.with_timeout(3000)
   |> :eetcd_election.with_name(name)
   |> :eetcd_election.with_lease(leaseId)
   |> :eetcd_election.with_value(Value)
   |> :eetcd_kv.campaign()
eetcd_election:with_name/2, eetcd_election:with_lease/2, eetcd_election:with_value/2, eetcd_election:with_timeout/2

campaign/4

campaign(Ctx::context() | name(), Name::binary(), LeaseId::integer(), Value::binary()) -> {ok, router_pb:'Etcd.CampaignResponse'()} | {error, eetcd_error()}

campaign_request/4

campaign_request(ConnName::name(), Name::binary(), LeaseId::integer(), Value::binary()) -> {ok, campaign_ctx()} | {error, eetcd_error()}

campaign async to acquire leadership. if there is already a leader, campaign/4 will be held(block) forever until timeout. the campaign_request/4 will return immediately, then your can use campaign_response/2 to handle Etcd.CampaignResponse`. gen_server example ``` init(Arg) -> ... {ok, CCtx} = eetcd_election:campaign_request(connName, Name, LeaderId, Value), ... handle_info(Msg, State=#{ctx := CCtx}) -> case eetcd_election:campaign_response(CCtx, Msg) of unknown -> do_handle_your_msg(Msg, State); {ok, #{campaign := Leader}} -> campaign_win(Leader); {error, Reason} -> campaign_error(Reason) end.''

campaign_response/2

campaign_response(CCtx::campaign_ctx(), Msg::term()) -> unknown | {ok, campaign_ctx()} | {error, eetcd_error()}

handle campaign async response Etcd.CampaignResponse.

leader/1

leader(Ctx::context()) -> {ok, router_pb:'Etcd.LeaderResponse'()} | {error, eetcd_error()}

Leader returns the current election proclamation, if any.

1. base
eetcd_election:leader(ConnName, Name).
2. elixir
   :eetcd_election.new(connName)
   |> :eetcd_election.with_name(name)
   |> :eetcd_kv.leader()
eetcd_election:with_name/2

leader/2

leader(Ctx::context() | name(), Name::binary()) -> {ok, router_pb:'Etcd.LeaderResponse'()} | {error, eetcd_error()}

new/1

new(Ctx::atom() | reference()) -> context()

Creates a blank context for a request.

observe/3

observe(ConnName::name(), Name::binary(), Timeout::timeout()) -> {ok, observe_ctx()} | {error, eetcd_error()}

Observe streams election proclamations in-order as made by the election's elected leaders. Timeout is an integer greater than zero which specifies how many milliseconds to wait for a leaders, or the atom infinity to wait indefinitely. If no leader is received within the specified time, the function call return 'election_no_leader'. and will streams election proclamations by order messages.

observe_stream/2

observe_stream(OCtx::observe_ctx(), Msg::term()) -> unknown | {ok, observe_ctx()} | {error, eetcd_error()}

handle observe stream Etcd.LeaderResponse.

proclaim/1

proclaim(Ctx::context()) -> {ok, router_pb:'Etcd.ProclaimResponse'()} | {error, eetcd_error()}

Proclaim updates the leader's posted value with a new value. Leader is the leadership hold on the election. Value is an update meant to overwrite the leader's current value.

1. base
eetcd_election:proclaim(ConnName, Leader, Value).
2. elixir
   :eetcd_election.new(connName)
   |> :eetcd_election.with_leader(name)
   |> :eetcd_election.with_value(Value)
   |> :eetcd_kv.proclaim()
eetcd_election:with_leader/2, eetcd_election:with_value/2

proclaim/3

proclaim(Ctx::context() | name(), Leader::map(), Value::binary()) -> {ok, router_pb:'Etcd.ProclaimResponse'()} | {error, eetcd_error()}

resign/1

resign(Ctx::context()) -> {ok, router_pb:'Etcd.ResignResponse'()} | {error, eetcd_error()}

Resign releases election leadership so other campaigners may acquire leadership on the election.

1. base
eetcd_election:resign(ConnName, Leader).
2. elixir
   :eetcd_election.new(connName)
   |> :eetcd_election.with_leader(Leader)
   |> :eetcd_kv.resign()
eetcd_election:with_leader/2

resign/2

resign(Ctx::context() | name(), Leader::binary()) -> {ok, router_pb:'Etcd.ResignResponse'()} | {error, eetcd_error()}

with_leader/2

with_leader(Ctx::context(), Leader::binary()) -> context()

leader describes the resources used for holding leadership of the election. It's a map return from CampaignResponse name is the election identifier that corresponds to the leadership key. key is an opaque key representing the ownership of the election. If the key is deleted, then leadership is lost. rev is the creation revision of the key. It can be used to test for ownership of an election during transactions by testing the key's creation revision matches rev. lease is the lease ID of the election leader.

with_lease/2

with_lease(Ctx::context(), LeaseID::pos_integer()) -> context()

lease is the ID of the lease attached to leadership of the election. If the lease expires or is revoked before resigning leadership, then the leadership is transferred to the next campaigner, if any.

with_name/2

with_name(Ctx::context(), Name::binary()) -> context()

name is the election's identifier for the campaign.

with_timeout/2

with_timeout(Ctx::context(), Timeout::pos_integer() | infinity) -> context()

Timeout is an integer greater than zero which specifies how many milliseconds to wait for a reply, or the atom infinity to wait indefinitely. Default value is 5000. If no reply is received within the specified time, the function call fails with {error, timeout}.


Generated by EDoc