Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed May 25, 2023
1 parent 40bcaca commit 712a164
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
20 changes: 14 additions & 6 deletions doc/configuration/internal-databases.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Internal databases for MongooseIM.
Internal databases are used to cluster MongooseIM nodes, and to replicate session list data between them.

Mnesia is a legacy way to cluster MongooseIM nodes. It is also could be used to store data, but we recommend
Mnesia is a legacy way to cluster MongooseIM nodes. It is also could be used to store persistent data, but we recommend
to use RDBMS databases instead because of scalability and stability reasons.

CETS is a new way to cluster MongooseIM nodes. It is used to replicate session list data between MongooseIM nodes.
CETS is a new way to cluster MongooseIM nodes.
CETS needs to know a list of nodes for the node discovery. There are two ways to get a list of nodes:

- A text file with a list of nodes on each line. It is useful when there is an external script to make this file based on
Expand All @@ -21,7 +21,15 @@ Section example:
[internal_databases.cets]
backend = "rdbms"
cluster_name = "mongooseim"
nodelist_file = "cets_disco.txt"
```

or

```toml
[internal_databases]
[internal_databases.cets]
backend = "file"
node_list_file = "cets_disco.txt"
```

To enable just CETS, define only `internal_databases.cets` section:
Expand Down Expand Up @@ -49,11 +57,11 @@ Namespace for the cluster. Only nodes with the same cluster name would be discov
* **Default:** `"mongooseim"`
* **Example:** `cluster_name = "mongooseim"`

### `internal_databases.cets.nodelist_file`
### `internal_databases.cets.node_list_file`

File to read a list of nodes from. Relative to the MongooseIM's release directory. This option is for the file backend.
Required, if `backend = "file"`.

* **Syntax:** path.
* **Default:** not specified.
* **Example:** `nodelist_file = "/etc/mim_nodes.txt"`
* **Example:** `node_list_file = "/etc/mim_nodes.txt"`
2 changes: 1 addition & 1 deletion rel/mim1.vars-toml.config
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{hosts, "\"localhost\", \"anonymous.localhost\", \"localhost.bis\""}.
{host_types, "\"test type\", \"dummy auth\", \"anonymous\""}.
{default_server_domain, "\"localhost\""}.
{cluster_name, "mim_main"}.
{cluster_name, "mim"}.

{mod_amp, ""}.
{host_config,
Expand Down
2 changes: 1 addition & 1 deletion rel/mim2.vars-toml.config
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{hosts, "\"localhost\", \"anonymous.localhost\", \"localhost.bis\""}.
{host_types, "\"test type\", \"dummy auth\""}.
{default_server_domain, "\"localhost\""}.
{cluster_name, "mim_main"}.
{cluster_name, "mim"}.
{s2s_addr, "[[s2s.address]]
host = \"localhost2\"
ip_address = \"127.0.0.1\""}.
Expand Down
2 changes: 1 addition & 1 deletion rel/mim3.vars-toml.config
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

{hosts, "\"localhost\", \"anonymous.localhost\", \"localhost.bis\""}.
{default_server_domain, "\"localhost\""}.
{cluster_name, "mim_main"}.
{cluster_name, "mim"}.

{s2s_addr, "[[s2s.address]]
host = \"localhost2\"
Expand Down
12 changes: 4 additions & 8 deletions src/config/mongoose_config_spec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,7 @@ internal_databases() ->
#section{items = Items,
format_items = map,
wrap = global_config,
include = always,
defaults = #{}}.
include = always}.

%% path: internal_databases.*.*
internal_database_cets() ->
Expand All @@ -443,18 +442,15 @@ internal_database_cets() ->
validate = {enum, [file, rdbms]}},
<<"cluster_name">> => #option{type = atom, validate = non_empty},
%% Relative to the release directory (or an absolute name)
<<"nodelist_file">> => #option{type = string,
validate = filename}
<<"node_list_file">> => #option{type = string,
validate = filename}
},
defaults = #{<<"backend">> => rdbms, <<"cluster_name">> => mongooseim}
}.

%% path: internal_databases.*.*
internal_database_mnesia() ->
#section{
items = #{},
defaults = #{}
}.
#section{}.

%% path: outgoing_pools
outgoing_pools() ->
Expand Down
8 changes: 4 additions & 4 deletions src/ejabberd_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ cets_specs(disabled) ->
cets_specs(#{backend := DiscoBackend, cluster_name := ClusterName} = Opts) ->
DiscoFile =
case {DiscoBackend, Opts} of
{file, #{nodelist_file := NodeFile}} ->
{file, #{node_list_file := NodeFile}} ->
NodeFile;
{file, _} ->
?LOG_CRITICAL(#{what => nodelist_file_option_is_required,
text => <<"Specify internal_databases.cets.nodelist_file option">>}),
error(nodelist_file_option_is_required);
?LOG_CRITICAL(#{what => node_list_file_option_is_required,
text => <<"Specify internal_databases.cets.node_list_file option">>}),
error(node_list_file_option_is_required);
_ ->
undefined
end,
Expand Down
2 changes: 1 addition & 1 deletion src/mongoose_cets_discovery_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ get_nodes(State = #{cluster_name := ClusterName, node_name_to_insert := Node}) -
insert(ClusterName, Node),
try mongoose_rdbms:execute_successfully(global, cets_disco_select, [ClusterName]) of
{selected, Rows} ->
Nodes = [binary_to_atom(X, latin1) || {X} <- Rows, X =/= <<>>],
Nodes = [binary_to_atom(X) || {X} <- Rows, X =/= <<>>],
{{ok, Nodes}, State}
catch Class:Reason:Stacktrace ->
?LOG_ERROR(#{
Expand Down
4 changes: 2 additions & 2 deletions test/config_parser_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ test_fast_tls_server(P, T) ->
internal_database_cets(_Config) ->
CetsEnabled = #{<<"internal_databases">> => #{<<"cets">> => #{}}},
CetsFile = #{<<"internal_databases">> => #{<<"cets">> =>
#{<<"backend">> => <<"file">>, <<"nodelist_file">> => <<"/dev/null">>}}},
#{<<"backend">> => <<"file">>, <<"node_list_file">> => <<"/dev/null">>}}},
%% No internal_databases section means an empty list of databases
?cfg([internal_databases], #{}, #{}), % default
%% Empty internal_databases could be configured explicitly
Expand All @@ -1219,7 +1219,7 @@ internal_database_cets(_Config) ->
#{<<"internal_databases">> => #{<<"cets">> => #{<<"cluster_name">> => <<"test">>}}}),

?cfg([internal_databases, cets, cluster_name], mongooseim, CetsEnabled),
?cfg([internal_databases, cets, nodelist_file], "/dev/null", CetsFile),
?cfg([internal_databases, cets, node_list_file], "/dev/null", CetsFile),
%% If only mnesia section is defined, CETS section is not included
?cfg([internal_databases], #{mnesia => #{}},
#{<<"internal_databases">> => #{<<"mnesia">> => #{}}}),
Expand Down

0 comments on commit 712a164

Please sign in to comment.