chore(config): move db configs under cluster/node keys

This commit is contained in:
Thales Macedo Garitezi 2022-05-26 09:25:46 -03:00
parent e8d37a26da
commit d0c5de1da6
No known key found for this signature in database
GPG Key ID: DD279F8152A9B6DD
6 changed files with 49 additions and 64 deletions

View File

@ -14,8 +14,8 @@ services:
restart: on-failure
environment:
- "EMQX_HOST=node1.emqx.io"
- "EMQX_DB__BACKEND=mnesia"
- "EMQX_DB__ROLE=core"
- "EMQX_NODE__DB_BACKEND=mnesia"
- "EMQX_NODE__DB_ROLE=core"
emqx2:
<<: *default-emqx
@ -25,5 +25,5 @@ services:
restart: on-failure
environment:
- "EMQX_HOST=node2.emqx.io"
- "EMQX_DB__BACKEND=mnesia"
- "EMQX_DB__ROLE=core"
- "EMQX_NODE__DB_BACKEND=mnesia"
- "EMQX_NODE__DB_ROLE=core"

View File

@ -14,8 +14,8 @@ services:
restart: on-failure
environment:
- "EMQX_HOST=node1.emqx.io"
- "EMQX_DB__BACKEND=rlog"
- "EMQX_DB__ROLE=core"
- "EMQX_NODE__DB_BACKEND=rlog"
- "EMQX_NODE__DB_ROLE=core"
- "EMQX_CLUSTER__STATIC__SEEDS=[emqx@node1.emqx.io]"
- "EMQX_LISTENERS__TCP__DEFAULT__PROXY_PROTOCOL=false"
- "EMQX_LISTENERS__WS__DEFAULT__PROXY_PROTOCOL=false"
@ -28,9 +28,9 @@ services:
restart: on-failure
environment:
- "EMQX_HOST=node2.emqx.io"
- "EMQX_DB__BACKEND=rlog"
- "EMQX_DB__ROLE=replicant"
- "EMQX_DB__CORE_NODES=emqx@node1.emqx.io"
- "EMQX_NODE__DB_BACKEND=rlog"
- "EMQX_NODE__DB_ROLE=replicant"
- "EMQX_CLUSTER__CORE_NODES=emqx@node1.emqx.io"
- "EMQX_CLUSTER__STATIC__SEEDS=[emqx@node1.emqx.io]"
- "EMQX_LISTENERS__TCP__DEFAULT__PROXY_PROTOCOL=false"
- "EMQX_LISTENERS__WS__DEFAULT__PROXY_PROTOCOL=false"

View File

@ -100,6 +100,20 @@ node {
max_history = 100
cleanup_interval = 5m
}
## Database backend
##
## @doc node.db_backend
## ValueType: mnesia | rlog
## Default: rlog
db_backend = rlog
## RLOG role
##
## @doc node.db_role
## ValueType: core | replicant
## Default: core
db_role = core
}
##==================================================================
@ -142,6 +156,13 @@ cluster {
## Default: manual
discovery_strategy = manual
## Replicant core nodes
##
## @doc cluster.core_nodes
## ValueType: comma-separated node list
## Default: ""
core_nodes = ""
##----------------------------------------------------------------
## Cluster using static node list
##----------------------------------------------------------------
@ -311,32 +332,6 @@ cluster {
}
}
##==================================================================
## Internal database
##==================================================================
db {
## Database backend
##
## @doc db.backend
## ValueType: mnesia | rlog
## Default: rlog
backend = rlog
## RLOG role
##
## @doc db.role
## ValueType: core | replicant
## Default: core
role = core
## Replicant core nodes
##
## @doc db.core_nodes
## ValueType: comma-separated node list
## Default: ""
core_nodes = ""
}
##==================================================================
## Log
##==================================================================

View File

@ -93,11 +93,6 @@ roots() ->
sc(
ref("rpc"),
#{translate_to => ["gen_rpc"]}
)},
{"db",
sc(
ref("db"),
#{}
)}
] ++
emqx_schema:roots(medium) ++
@ -129,6 +124,16 @@ fields("cluster") ->
'readOnly' => true
}
)},
{"core_nodes",
sc(
emqx_schema:comma_separated_atoms(),
#{
mapping => "mria.core_nodes",
default => [],
'readOnly' => true,
desc => ?DESC(db_core_nodes)
}
)},
{"autoclean",
sc(
emqx_schema:duration(),
@ -509,11 +514,8 @@ fields("node") ->
sc(
ref("cluster_call"),
#{'readOnly' => true}
)}
];
fields("db") ->
[
{"backend",
)},
{"db_backend",
sc(
hoconsc:enum([mnesia, rlog]),
#{
@ -523,7 +525,7 @@ fields("db") ->
desc => ?DESC(db_backend)
}
)},
{"role",
{"db_role",
sc(
hoconsc:enum([core, replicant]),
#{
@ -533,16 +535,6 @@ fields("db") ->
desc => ?DESC(db_role)
}
)},
{"core_nodes",
sc(
emqx_schema:comma_separated_atoms(),
#{
mapping => "mria.core_nodes",
default => [],
'readOnly' => true,
desc => ?DESC(db_core_nodes)
}
)},
{"rpc_module",
sc(
hoconsc:enum([gen_rpc, rpc]),
@ -933,8 +925,6 @@ desc(cluster_k8s) ->
?DESC("desc_cluster_k8s");
desc("node") ->
?DESC("desc_node");
desc("db") ->
?DESC("desc_db");
desc("cluster_call") ->
?DESC("desc_cluster_call");
desc("rpc") ->

View File

@ -406,7 +406,7 @@ call_hocon() {
## Resolve boot configs in a batch
## This is because starting the Erlang beam with all modules loaded
## and parsing HOCON config + environment variables is a non-trivial task
CONF_KEYS=( 'node.data_dir' 'node.name' 'node.cookie' 'db.backend' )
CONF_KEYS=( 'node.data_dir' 'node.name' 'node.cookie' 'node.db_backend' )
if [ "$IS_ENTERPRISE" = 'yes' ]; then
CONF_KEYS+=( 'license.file' 'license.key' )
fi
@ -718,11 +718,11 @@ fi
## check if OTP version has mnesia_hook feature; if not, fallback to
## using Mnesia DB backend.
if [[ "$IS_BOOT_COMMAND" == 'yes' && "$(get_boot_config 'db.backend')" == "rlog" ]]; then
if [[ "$IS_BOOT_COMMAND" == 'yes' && "$(get_boot_config 'node.db_backend')" == "rlog" ]]; then
if ! (echo -e "$COMPATIBILITY_INFO" | grep -q 'MNESIA_OK'); then
echoerr "DB Backend is RLOG, but an incompatible OTP version has been detected. Falling back to using Mnesia DB backend."
export EMQX_DB__BACKEND=mnesia
export EMQX_DB__ROLE=core
export EMQX_NODE__DB_BACKEND=mnesia
export EMQX_NODE__DB_ROLE=core
fi
fi

View File

@ -64,8 +64,8 @@
@set node_type=-name
@set schema_mod=emqx_conf_schema
:: no advanced DB backend for Windows
@set EMQX_DB__BACKEND=mnesia
@set EMQX_DB__ROLE=core
@set EMQX_NODE__DB_BACKEND=mnesia
@set EMQX_NODE__DB_ROLE=core
@set conf_path="%etc_dir%\emqx.conf"