Copyright © 2023 Anuar Alfetahe
Version: 0.2.0
Authors: Anuar Alfetahe (anuar.alfetahe@gmail.com).
Elector is an Erlang application that automatically detects all nodes inside the distributed Erlang cluster and chooses the leader node. The elections are started automatically when the Elector application is started or when a node joins or leaves the cluster. Elector also allows you to run pre- and post-election hooks that will be triggered when the election process is started and finished.
The default election strategy is to choose the node with the highest runtime.
Add {:elector, "~> 2.0"}` under the deps in the `mix.exs` file:
```
defp deps do
[
{:elector, "~> 1.0"}
]
end
''
elector
under the extra_applications in the mix.exs
file:
def application do [ extra_applications: [:elector], mod: {MyApp, []} ] end
Add elector
to the deps in the rebar.config
file: {deps, [{elector, {"elector", "0.2.0"}]}.
Next add elector` to the `applications` list in the `myapp.app.src
file: {applications, [elector]}.
Elixir: :elector.elect_sync()
or :elector.elect()
Erlang: elector:elect_sync()
or elector:elect()
> alias :elector, as Elector > Elector.get_leader() {:ok, :example_node}
> elector:get_leader(). {ok, example_node}
See the elector
module for more.
election_delay
- The delay in milliseconds before the new election starts. This value is used automatic election is triggered either by node join/leave or startup. Default value is 1 second(1000).
sync_start
- If true the election will start synchronously on start up. Set it false
if start up should be async. Default is true
.
strategy_module
- The module that is used for the election strategy implementation. Default is runtime_high_strategy
which chooses the node with the highest runtime. Available options are: runtime_high_strategy` and `runtime_low_strategy
. Feel free to write your own strategy module that implements the strategy_behaviour
module.
pre_election_hooks
- A list of hooks/function calls that will be triggered before the node is starting the election. Expects a list of tuples with the following format: {Module, Function, Args}
. Default is []
.
post_election_hooks
- A list of hooks/function calls that will be triggered after the election process. Expects a list of tuples with the following format: {Module, Function, Args}
. Default is []
.
startup_hooks_enabled
- If true the pre_election_hooks
and post_election_hooks
will be triggered on startup. Default is true
.
quorum_size
- The number of nodes(including the local node) that should be available in the cluster before the election process is started. Default is 1
. Do not set it to 0
as it will disable the election process, leave 1 if you want to run the election process even if there is only one node in the cluster.
Generated by EDoc