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 restart: on-failure
environment: environment:
- "EMQX_HOST=node1.emqx.io" - "EMQX_HOST=node1.emqx.io"
- "EMQX_DB__BACKEND=mnesia" - "EMQX_NODE__DB_BACKEND=mnesia"
- "EMQX_DB__ROLE=core" - "EMQX_NODE__DB_ROLE=core"
emqx2: emqx2:
<<: *default-emqx <<: *default-emqx
@ -25,5 +25,5 @@ services:
restart: on-failure restart: on-failure
environment: environment:
- "EMQX_HOST=node2.emqx.io" - "EMQX_HOST=node2.emqx.io"
- "EMQX_DB__BACKEND=mnesia" - "EMQX_NODE__DB_BACKEND=mnesia"
- "EMQX_DB__ROLE=core" - "EMQX_NODE__DB_ROLE=core"

View File

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

View File

@ -100,6 +100,20 @@ node {
max_history = 100 max_history = 100
cleanup_interval = 5m 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 ## Default: manual
discovery_strategy = manual discovery_strategy = manual
## Replicant core nodes
##
## @doc cluster.core_nodes
## ValueType: comma-separated node list
## Default: ""
core_nodes = ""
##---------------------------------------------------------------- ##----------------------------------------------------------------
## Cluster using static node list ## 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 ## Log
##================================================================== ##==================================================================

View File

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

View File

@ -406,7 +406,7 @@ call_hocon() {
## Resolve boot configs in a batch ## Resolve boot configs in a batch
## This is because starting the Erlang beam with all modules loaded ## This is because starting the Erlang beam with all modules loaded
## and parsing HOCON config + environment variables is a non-trivial task ## 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 if [ "$IS_ENTERPRISE" = 'yes' ]; then
CONF_KEYS+=( 'license.file' 'license.key' ) CONF_KEYS+=( 'license.file' 'license.key' )
fi fi
@ -718,11 +718,11 @@ fi
## check if OTP version has mnesia_hook feature; if not, fallback to ## check if OTP version has mnesia_hook feature; if not, fallback to
## using Mnesia DB backend. ## 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 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." 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_NODE__DB_BACKEND=mnesia
export EMQX_DB__ROLE=core export EMQX_NODE__DB_ROLE=core
fi fi
fi fi

View File

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