Merge pull request #12264 from ieQu1/avoid-starting-ds-when-feature-is-off

fix(ds): Don't start the supervision tree when feature is off
This commit is contained in:
ieQu1 2024-01-08 17:52:08 +00:00 committed by GitHub
commit 88f649531b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 12 deletions

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2023 EMQ Technologies Co., Ltd. All Rights Reserved. %% Copyright (c) 2023-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -109,6 +109,7 @@ list_shards(DB) ->
-spec open_db(emqx_ds:db(), builtin_db_opts()) -> ok | {error, _}. -spec open_db(emqx_ds:db(), builtin_db_opts()) -> ok | {error, _}.
open_db(DB, CreateOpts) -> open_db(DB, CreateOpts) ->
ok = emqx_ds_sup:ensure_workers(),
Opts = emqx_ds_replication_layer_meta:open_db(DB, CreateOpts), Opts = emqx_ds_replication_layer_meta:open_db(DB, CreateOpts),
MyShards = emqx_ds_replication_layer_meta:my_shards(DB), MyShards = emqx_ds_replication_layer_meta:my_shards(DB),
lists:foreach( lists:foreach(

View File

@ -1,12 +1,12 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved. %% Copyright (c) 2022-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-module(emqx_ds_sup). -module(emqx_ds_sup).
-behaviour(supervisor). -behaviour(supervisor).
%% API: %% API:
-export([start_link/0]). -export([start_link/0, ensure_workers/0]).
%% behaviour callbacks: %% behaviour callbacks:
-export([init/1]). -export([init/1]).
@ -23,21 +23,41 @@
-spec start_link() -> {ok, pid()}. -spec start_link() -> {ok, pid()}.
start_link() -> start_link() ->
supervisor:start_link({local, ?SUP}, ?MODULE, []). supervisor:start_link({local, ?SUP}, ?MODULE, top).
-spec ensure_workers() -> ok.
ensure_workers() ->
ChildSpec = #{
id => workers_sup,
restart => temporary,
type => supervisor,
start => {supervisor, start_link, [?MODULE, workers]}
},
case supervisor:start_child(?SUP, ChildSpec) of
{ok, _} ->
ok;
{error, already_present} ->
ok;
{error, {already_started, _}} ->
ok
end.
%%================================================================================ %%================================================================================
%% behaviour callbacks %% behaviour callbacks
%%================================================================================ %%================================================================================
-dialyzer({nowarn_function, init/1}). -dialyzer({nowarn_function, init/1}).
init([]) -> init(top) ->
SupFlags = #{
strategy => one_for_all,
intensity => 10,
period => 1
},
{ok, {SupFlags, []}};
init(workers) ->
%% TODO: technically, we don't need rocksDB for the alternative %% TODO: technically, we don't need rocksDB for the alternative
%% backends. But right now we have any: %% backends. But right now we have any:
Children = Children = [meta(), storage_layer_sup()],
case mria:rocksdb_backend_available() of
true -> [meta(), storage_layer_sup()];
false -> []
end,
SupFlags = #{ SupFlags = #{
strategy => one_for_all, strategy => one_for_all,
intensity => 0, intensity => 0,

View File

@ -2,7 +2,7 @@
{application, emqx_durable_storage, [ {application, emqx_durable_storage, [
{description, "Message persistence and subscription replays for EMQX"}, {description, "Message persistence and subscription replays for EMQX"},
% strict semver, bump manually! % strict semver, bump manually!
{vsn, "0.1.9"}, {vsn, "0.1.10"},
{modules, []}, {modules, []},
{registered, []}, {registered, []},
{applications, [kernel, stdlib, rocksdb, gproc, mria, emqx_utils]}, {applications, [kernel, stdlib, rocksdb, gproc, mria, emqx_utils]},

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved. %% Copyright (c) 2022-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-module(emqx_ds_storage_bitfield_lts_SUITE). -module(emqx_ds_storage_bitfield_lts_SUITE).
@ -378,6 +378,7 @@ suite() -> [{timetrap, {seconds, 20}}].
init_per_suite(Config) -> init_per_suite(Config) ->
{ok, _} = application:ensure_all_started(emqx_durable_storage), {ok, _} = application:ensure_all_started(emqx_durable_storage),
emqx_ds_sup:ensure_workers(),
Config. Config.
end_per_suite(_Config) -> end_per_suite(_Config) ->