fix(ds): Move DS backend supervision trees to their own apps
This commit is contained in:
parent
3d69ec496a
commit
9a58d71378
|
@ -5,7 +5,7 @@
|
||||||
{vsn, "0.1.0"},
|
{vsn, "0.1.0"},
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{applications, [kernel, stdlib, rocksdb, emqx_durable_storage, emqx_utils]},
|
{applications, [kernel, stdlib, gproc, mria, rocksdb, emqx_durable_storage, emqx_utils]},
|
||||||
{mod, {emqx_ds_builtin_local_app, []}},
|
{mod, {emqx_ds_builtin_local_app, []}},
|
||||||
{env, []}
|
{env, []}
|
||||||
]}.
|
]}.
|
||||||
|
|
|
@ -27,8 +27,7 @@
|
||||||
|
|
||||||
start(_StartType, _StartArgs) ->
|
start(_StartType, _StartArgs) ->
|
||||||
emqx_ds:register_backend(builtin_local, emqx_ds_builtin_local),
|
emqx_ds:register_backend(builtin_local, emqx_ds_builtin_local),
|
||||||
%% TODO: fixme
|
emqx_ds_builtin_local_sup:start_top().
|
||||||
{ok, self()}.
|
|
||||||
|
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
%% Internal exports
|
%% Internal exports
|
||||||
|
|
|
@ -43,10 +43,13 @@
|
||||||
%% API functions
|
%% API functions
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
|
|
||||||
|
-spec start_top() -> {ok, pid()}.
|
||||||
|
start_top() ->
|
||||||
|
supervisor:start_link({local, ?top}, ?MODULE, ?top).
|
||||||
|
|
||||||
-spec start_db(emqx_ds:db(), emqx_ds_builtin_local:db_opts()) ->
|
-spec start_db(emqx_ds:db(), emqx_ds_builtin_local:db_opts()) ->
|
||||||
supervisor:startchild_ret().
|
supervisor:startchild_ret().
|
||||||
start_db(DB, Opts) ->
|
start_db(DB, Opts) ->
|
||||||
ensure_top(),
|
|
||||||
ChildSpec = #{
|
ChildSpec = #{
|
||||||
id => DB,
|
id => DB,
|
||||||
start => {?databases, start_db, [DB, Opts]},
|
start => {?databases, start_db, [DB, Opts]},
|
||||||
|
@ -81,7 +84,6 @@ stop_db(DB) ->
|
||||||
%% Chidren are attached dynamically to this one.
|
%% Chidren are attached dynamically to this one.
|
||||||
init(?top) ->
|
init(?top) ->
|
||||||
%% Children:
|
%% Children:
|
||||||
MetricsWorker = emqx_ds_builtin_metrics:child_spec(),
|
|
||||||
MetadataServer = #{
|
MetadataServer = #{
|
||||||
id => metadata_server,
|
id => metadata_server,
|
||||||
start => {emqx_ds_builtin_local_meta, start_link, []},
|
start => {emqx_ds_builtin_local_meta, start_link, []},
|
||||||
|
@ -103,7 +105,7 @@ init(?top) ->
|
||||||
period => 1,
|
period => 1,
|
||||||
auto_shutdown => never
|
auto_shutdown => never
|
||||||
},
|
},
|
||||||
{ok, {SupFlags, [MetricsWorker, MetadataServer, DBsSup]}};
|
{ok, {SupFlags, [MetadataServer, DBsSup]}};
|
||||||
init(?databases) ->
|
init(?databases) ->
|
||||||
%% Children are added dynamically:
|
%% Children are added dynamically:
|
||||||
SupFlags = #{
|
SupFlags = #{
|
||||||
|
@ -117,17 +119,9 @@ init(?databases) ->
|
||||||
%% Internal exports
|
%% Internal exports
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
|
|
||||||
-spec start_top() -> {ok, pid()}.
|
|
||||||
start_top() ->
|
|
||||||
supervisor:start_link({local, ?top}, ?MODULE, ?top).
|
|
||||||
|
|
||||||
start_databases_sup() ->
|
start_databases_sup() ->
|
||||||
supervisor:start_link({local, ?databases}, ?MODULE, ?databases).
|
supervisor:start_link({local, ?databases}, ?MODULE, ?databases).
|
||||||
|
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
|
|
||||||
ensure_top() ->
|
|
||||||
{ok, _} = emqx_ds_sup:attach_backend(builtin_local, {?MODULE, start_top, []}),
|
|
||||||
ok.
|
|
||||||
|
|
|
@ -335,12 +335,12 @@ end_per_suite(Config) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
init_per_testcase(_TC, Config) ->
|
init_per_testcase(_TC, Config) ->
|
||||||
application:ensure_all_started(emqx_durable_storage),
|
application:ensure_all_started(emqx_ds_builtin_local),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_testcase(_TC, _Config) ->
|
end_per_testcase(_TC, _Config) ->
|
||||||
snabbkaffe:stop(),
|
snabbkaffe:stop(),
|
||||||
ok = application:stop(emqx_durable_storage),
|
ok = application:stop(emqx_ds_builtin_local),
|
||||||
mria:stop(),
|
mria:stop(),
|
||||||
_ = mnesia:delete_schema([node()]),
|
_ = mnesia:delete_schema([node()]),
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -8,4 +8,4 @@
|
||||||
|
|
||||||
start(_Type, _Args) ->
|
start(_Type, _Args) ->
|
||||||
emqx_ds:register_backend(builtin_raft, emqx_ds_replication_layer),
|
emqx_ds:register_backend(builtin_raft, emqx_ds_replication_layer),
|
||||||
{ok, self()}.
|
emqx_ds_builtin_raft_sup:start_top().
|
||||||
|
|
|
@ -10,14 +10,14 @@
|
||||||
-behaviour(supervisor).
|
-behaviour(supervisor).
|
||||||
|
|
||||||
%% API:
|
%% API:
|
||||||
-export([start_db/2, stop_db/1]).
|
-export([start_top/0, start_db/2, stop_db/1]).
|
||||||
-export([set_gvar/3, get_gvar/3, clean_gvars/1]).
|
-export([set_gvar/3, get_gvar/3, clean_gvars/1]).
|
||||||
|
|
||||||
%% behavior callbacks:
|
%% behavior callbacks:
|
||||||
-export([init/1]).
|
-export([init/1]).
|
||||||
|
|
||||||
%% internal exports:
|
%% internal exports:
|
||||||
-export([start_top/0, start_databases_sup/0]).
|
-export([start_databases_sup/0]).
|
||||||
|
|
||||||
-export_type([]).
|
-export_type([]).
|
||||||
|
|
||||||
|
@ -38,10 +38,13 @@
|
||||||
%% API functions
|
%% API functions
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
|
|
||||||
|
-spec start_top() -> {ok, pid()}.
|
||||||
|
start_top() ->
|
||||||
|
supervisor:start_link({local, ?top}, ?MODULE, ?top).
|
||||||
|
|
||||||
-spec start_db(emqx_ds:db(), emqx_ds_replication_layer:builtin_db_opts()) ->
|
-spec start_db(emqx_ds:db(), emqx_ds_replication_layer:builtin_db_opts()) ->
|
||||||
supervisor:startchild_ret().
|
supervisor:startchild_ret().
|
||||||
start_db(DB, Opts) ->
|
start_db(DB, Opts) ->
|
||||||
ensure_top(),
|
|
||||||
ChildSpec = #{
|
ChildSpec = #{
|
||||||
id => DB,
|
id => DB,
|
||||||
start => {emqx_ds_builtin_raft_db_sup, start_db, [DB, Opts]},
|
start => {emqx_ds_builtin_raft_db_sup, start_db, [DB, Opts]},
|
||||||
|
@ -96,7 +99,6 @@ clean_gvars(DB) ->
|
||||||
%% Chidren are attached dynamically to this one.
|
%% Chidren are attached dynamically to this one.
|
||||||
init(?top) ->
|
init(?top) ->
|
||||||
%% Children:
|
%% Children:
|
||||||
MetricsWorker = emqx_ds_builtin_metrics:child_spec(),
|
|
||||||
MetadataServer = #{
|
MetadataServer = #{
|
||||||
id => metadata_server,
|
id => metadata_server,
|
||||||
start => {emqx_ds_replication_layer_meta, start_link, []},
|
start => {emqx_ds_replication_layer_meta, start_link, []},
|
||||||
|
@ -119,7 +121,7 @@ init(?top) ->
|
||||||
period => 1,
|
period => 1,
|
||||||
auto_shutdown => never
|
auto_shutdown => never
|
||||||
},
|
},
|
||||||
{ok, {SupFlags, [MetricsWorker, MetadataServer, DBsSup]}};
|
{ok, {SupFlags, [MetadataServer, DBsSup]}};
|
||||||
init(?databases) ->
|
init(?databases) ->
|
||||||
%% Children are added dynamically:
|
%% Children are added dynamically:
|
||||||
SupFlags = #{
|
SupFlags = #{
|
||||||
|
@ -133,17 +135,9 @@ init(?databases) ->
|
||||||
%% Internal exports
|
%% Internal exports
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
|
|
||||||
-spec start_top() -> {ok, pid()}.
|
|
||||||
start_top() ->
|
|
||||||
supervisor:start_link({local, ?top}, ?MODULE, ?top).
|
|
||||||
|
|
||||||
start_databases_sup() ->
|
start_databases_sup() ->
|
||||||
supervisor:start_link({local, ?databases}, ?MODULE, ?databases).
|
supervisor:start_link({local, ?databases}, ?MODULE, ?databases).
|
||||||
|
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
|
|
||||||
ensure_top() ->
|
|
||||||
{ok, _} = emqx_ds_sup:attach_backend(builtin_raft, {?MODULE, start_top, []}),
|
|
||||||
ok.
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
-behaviour(supervisor).
|
-behaviour(supervisor).
|
||||||
|
|
||||||
%% API:
|
%% API:
|
||||||
-export([start_link/0, attach_backend/2]).
|
-export([start_link/0]).
|
||||||
-export([register_db/2, unregister_db/1, which_dbs/0]).
|
-export([register_db/2, unregister_db/1, which_dbs/0]).
|
||||||
|
|
||||||
%% behaviour callbacks:
|
%% behaviour callbacks:
|
||||||
|
@ -39,27 +39,6 @@
|
||||||
start_link() ->
|
start_link() ->
|
||||||
supervisor:start_link({local, ?SUP}, ?MODULE, top).
|
supervisor:start_link({local, ?SUP}, ?MODULE, top).
|
||||||
|
|
||||||
%% @doc Attach a child backend-specific supervisor to the top
|
|
||||||
%% application supervisor, if not yet present
|
|
||||||
-spec attach_backend(_BackendId, {module(), atom(), list()}) ->
|
|
||||||
{ok, pid()} | {error, _}.
|
|
||||||
attach_backend(Backend, Start) ->
|
|
||||||
Spec = #{
|
|
||||||
id => Backend,
|
|
||||||
start => Start,
|
|
||||||
significant => false,
|
|
||||||
shutdown => infinity,
|
|
||||||
type => supervisor
|
|
||||||
},
|
|
||||||
case supervisor:start_child(?SUP, Spec) of
|
|
||||||
{ok, Pid} ->
|
|
||||||
{ok, Pid};
|
|
||||||
{error, {already_started, Pid}} ->
|
|
||||||
{ok, Pid};
|
|
||||||
{error, Err} ->
|
|
||||||
{error, Err}
|
|
||||||
end.
|
|
||||||
|
|
||||||
register_db(DB, Backend) ->
|
register_db(DB, Backend) ->
|
||||||
ets:insert(?TAB, {DB, Backend}),
|
ets:insert(?TAB, {DB, Backend}),
|
||||||
ok.
|
ok.
|
||||||
|
@ -77,7 +56,7 @@ which_dbs() ->
|
||||||
|
|
||||||
init(top) ->
|
init(top) ->
|
||||||
_ = ets:new(?TAB, [public, set, named_table]),
|
_ = ets:new(?TAB, [public, set, named_table]),
|
||||||
Children = [],
|
Children = [emqx_ds_builtin_metrics:child_spec()],
|
||||||
SupFlags = #{
|
SupFlags = #{
|
||||||
strategy => one_for_one,
|
strategy => one_for_one,
|
||||||
intensity => 10,
|
intensity => 10,
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
It can't be used in a multi-node cluster.
|
It can't be used in a multi-node cluster.
|
||||||
This backend is available in both open source and enterprise editions.
|
This backend is available in both open source and enterprise editions.
|
||||||
- `builtin_raft`: A durable storage backend that uses Raft algorithm for replication.
|
- `builtin_raft`: A durable storage backend that uses Raft algorithm for replication.
|
||||||
This backend is available enterprise edition.
|
This backend is available only in the enterprise edition.
|
||||||
|
|
||||||
The following Prometheus metrics have been renamed:
|
The following Prometheus metrics have been renamed:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue