فهرست منبع

Merge pull request #8056 from thalesmg/move-db-config

chore(config): move db configs under cluster/node keys
Zaiming (Stone) Shi 3 سال پیش
والد
کامیت
d249c2c22e

+ 4 - 4
.ci/docker-compose-file/docker-compose-emqx-cluster-mnesia.override.yaml

@@ -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"

+ 5 - 5
.ci/docker-compose-file/docker-compose-emqx-cluster-rlog.override.yaml

@@ -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"

+ 3 - 4
.github/workflows/code_style_check.yaml

@@ -10,12 +10,12 @@ jobs:
       - uses: actions/checkout@v2
         with:
           fetch-depth: 1000
-      - name: Check line-break at EOF
-        run: |
-          ./scripts/check-nl-at-eof.sh
       - name: Work around https://github.com/actions/checkout/issues/766
         run: |
           git config --global --add safe.directory "$GITHUB_WORKSPACE"
+      - name: Check line-break at EOF
+        run: |
+          ./scripts/check-nl-at-eof.sh
       - name: Check Elixir code formatting
         run: |
           mix format --check-formatted
@@ -27,4 +27,3 @@ jobs:
       - name: Run elvis check
         run: |
           ./scripts/elvis-check.sh $GITHUB_BASE_REF
-

+ 21 - 26
apps/emqx_conf/etc/emqx_conf.conf

@@ -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
 ##==================================================================

+ 13 - 23
apps/emqx_conf/src/emqx_conf_schema.erl

@@ -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") ->

+ 4 - 4
bin/emqx

@@ -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
 

+ 2 - 2
bin/emqx.cmd

@@ -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"