Просмотр исходного кода

chore: add cluster_rpc_opts() type in emqx_config

zhongwencool 1 год назад
Родитель
Сommit
7c02e1979e
3 измененных файлов с 23 добавлено и 7 удалено
  1. 14 2
      apps/emqx/src/emqx.erl
  2. 2 0
      apps/emqx/src/emqx_config.erl
  3. 7 5
      apps/emqx/src/emqx_config_handler.erl

+ 14 - 2
apps/emqx/src/emqx.erl

@@ -200,6 +200,12 @@ get_raw_config(KeyPath, Default) ->
 update_config(KeyPath, UpdateReq) ->
     update_config(KeyPath, UpdateReq, #{}, #{}).
 
+-spec update_config(
+    emqx_utils_maps:config_key_path(),
+    emqx_config:update_request(),
+    emqx_config:cluster_rpc_opts()
+) ->
+    {ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
 update_config(KeyPath, UpdateReq, Opts) ->
     update_config(KeyPath, UpdateReq, Opts, #{}).
 
@@ -207,7 +213,7 @@ update_config(KeyPath, UpdateReq, Opts) ->
     emqx_utils_maps:config_key_path(),
     emqx_config:update_request(),
     emqx_config:update_opts(),
-    map()
+    emqx_config:cluster_rpc_opts()
 ) ->
     {ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
 update_config([RootName | _] = KeyPath, UpdateReq, Opts, ClusterRpcOpts) ->
@@ -228,7 +234,9 @@ remove_config(KeyPath) ->
 remove_config([_RootName | _] = KeyPath, Opts) ->
     remove_config(KeyPath, Opts, #{}).
 
--spec remove_config(emqx_utils_maps:config_key_path(), emqx_config:update_opts(), map()) ->
+-spec remove_config(
+    emqx_utils_maps:config_key_path(), emqx_config:update_opts(), emqx_config:cluster_rpc_opts()
+) ->
     {ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
 remove_config([RootName | _] = KeyPath, Opts, ClusterRpcOpts) ->
     emqx_config_handler:update_config(
@@ -243,6 +251,10 @@ remove_config([RootName | _] = KeyPath, Opts, ClusterRpcOpts) ->
 reset_config([RootName | SubKeys] = KeyPath, Opts) ->
     reset_config([RootName | SubKeys] = KeyPath, Opts, #{}).
 
+-spec reset_config(
+    emqx_utils_maps:config_key_path(), emqx_config:update_opts(), emqx_config:cluster_rpc_opts()
+) ->
+    {ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
 reset_config([RootName | SubKeys] = KeyPath, Opts, ClusterRpcOpts) ->
     case emqx_config:get_default_value(KeyPath) of
         {ok, Default} ->

+ 2 - 0
apps/emqx/src/emqx_config.erl

@@ -118,6 +118,7 @@
     config/0,
     app_envs/0,
     update_opts/0,
+    cluster_rpc_opts/0,
     update_cmd/0,
     update_args/0,
     update_error/0,
@@ -147,6 +148,7 @@
     raw_config => emqx_config:raw_config(),
     post_config_update => #{module() => any()}
 }.
+-type cluster_rpc_opts() :: #{kind => ?KIND_INITIATE | ?KIND_REPLICATE}.
 
 %% raw_config() is the config that is NOT parsed and translated by hocon schema
 -type raw_config() :: #{binary() => term()} | list() | undefined.

+ 7 - 5
apps/emqx/src/emqx_config_handler.erl

@@ -52,7 +52,6 @@
 -define(WKEY, '?').
 
 -type handler_name() :: module().
--type cluster_rpc_opts() :: map().
 
 -optional_callbacks([
     pre_config_update/3,
@@ -91,11 +90,14 @@
     ok | {ok, Result :: any()} | {error, Reason :: term()}.
 
 -callback pre_config_update(
-    [atom()], emqx_config:update_request(), emqx_config:raw_config(), cluster_rpc_opts()
+    [atom()], emqx_config:update_request(), emqx_config:raw_config(), emqx_config:cluster_rpc_opts()
 ) ->
     ok | {ok, emqx_config:update_request()} | {error, term()}.
 -callback propagated_pre_config_update(
-    [binary()], emqx_config:update_request(), emqx_config:raw_config(), cluster_rpc_opts()
+    [binary()],
+    emqx_config:update_request(),
+    emqx_config:raw_config(),
+    emqx_config:cluster_rpc_opts()
 ) ->
     ok | {ok, emqx_config:update_request()} | {error, term()}.
 
@@ -105,7 +107,7 @@
     emqx_config:config(),
     emqx_config:config(),
     emqx_config:app_envs(),
-    cluster_rpc_opts()
+    emqx_config:cluster_rpc_opts()
 ) ->
     ok | {ok, Result :: any()} | {error, Reason :: term()}.
 
@@ -115,7 +117,7 @@
     emqx_config:config(),
     emqx_config:config(),
     emqx_config:app_envs(),
-    cluster_rpc_opts()
+    emqx_config:cluster_rpc_opts()
 ) ->
     ok | {ok, Result :: any()} | {error, Reason :: term()}.