소스 검색

feat(mgmt): permit managing DS even if no DBs are configured

Andrew Mayorov 1 년 전
부모
커밋
0708a9877f

+ 10 - 1
apps/emqx_ds_builtin_raft/src/emqx_ds_builtin_raft_sup.erl

@@ -10,7 +10,7 @@
 -behaviour(supervisor).
 
 %% API:
--export([start_top/0, start_db/2, stop_db/1]).
+-export([start_top/0, start_db/2, stop_db/1, which_dbs/0]).
 -export([set_gvar/3, get_gvar/3, clean_gvars/1]).
 
 %% behavior callbacks:
@@ -64,6 +64,15 @@ stop_db(DB) ->
             ok
     end.
 
+-spec which_dbs() -> {ok, [emqx_ds:db()]} | {error, inactive}.
+which_dbs() ->
+    case whereis(?databases) of
+        Pid when is_pid(Pid) ->
+            [DB || {DB, _Child, _, _} <- supervisor:which_children(Pid)];
+        undefined ->
+            {error, inactive}
+    end.
+
 %% @doc Set a DB-global variable. Please don't abuse this API.
 -spec set_gvar(emqx_ds:db(), _Key, _Val) -> ok.
 set_gvar(DB, Key, Val) ->

+ 1 - 1
apps/emqx_ds_builtin_raft/src/emqx_ds_replication_layer.erl

@@ -106,7 +106,7 @@
 
 -type builtin_db_opts() ::
     #{
-        backend := builtin,
+        backend := builtin_raft,
         storage := emqx_ds_storage_layer:prototype(),
         n_shards => pos_integer(),
         n_sites => pos_integer(),

+ 1 - 1
apps/emqx_ds_builtin_raft/src/emqx_ds_replication_layer_meta.erl

@@ -351,7 +351,7 @@ forget_site(Site) ->
 %% DB API
 %%===============================================================================
 
--spec db_config(emqx_ds:db()) -> emqx_ds_replication_layer:builtin_db_opts().
+-spec db_config(emqx_ds:db()) -> emqx_ds_replication_layer:builtin_db_opts() | #{}.
 db_config(DB) ->
     case mnesia:dirty_read(?META_TAB, DB) of
         [#?META_TAB{db_props = Opts}] ->

+ 2 - 2
apps/emqx_management/src/emqx_mgmt_api_ds.erl

@@ -461,7 +461,7 @@ dbs() ->
 
 db_config(DB) ->
     case emqx_ds_replication_layer_meta:db_config(DB) of
-        Config = #{backend := builtin_raft} ->
+        Config = #{backend := _Builtin} ->
             Config;
         _ ->
             undefined
@@ -534,6 +534,6 @@ meta_result_to_binary({error, Err}) ->
     {error, iolist_to_binary(IOList)}.
 
 is_enabled() ->
-    [] =/= dbs().
+    emqx_ds_builtin_raft_sup:which_dbs() =/= {error, inactive}.
 
 -endif.