./ct_report/coverage/mongoose_wpool_rdbms.COVER.html

1 -module(mongoose_wpool_rdbms).
2 -behaviour(mongoose_wpool).
3
4 -export([init/0]).
5 -export([start/4]).
6 -export([stop/2]).
7
8 %% --------------------------------------------------------------
9 %% mongoose_wpool callbacks
10 -spec init() -> ok.
11 init() ->
12 93 ejabberd_sup:create_ets_table(
13 prepared_statements, [named_table, public, {read_concurrency, true}]).
14
15 -spec start(mongooseim:host_type_or_global(), mongoose_wpool:tag(),
16 mongoose_wpool:pool_opts(), mongoose_wpool:conn_opts()) -> {ok, pid()} | {error, any()}.
17 start(HostType, Tag, WpoolOpts, RdbmsOpts) ->
18 93 try do_start(HostType, Tag, WpoolOpts, RdbmsOpts)
19 catch
20
:-(
Err -> {error, Err}
21 end.
22
23 -spec stop(mongooseim:host_type_or_global(), mongoose_wpool:tag()) -> ok.
24 stop(_, _) ->
25 91 ok.
26
27 %% --------------------------------------------------------------
28 %% Helper functions
29 do_start(HostType, Tag, WpoolOpts0, RdbmsOpts) when is_list(WpoolOpts0), is_map(RdbmsOpts) ->
30 93 #{driver := BackendName} = RdbmsOpts,
31 93 mongoose_backend:init(global, mongoose_rdbms, [query, execute], #{backend => BackendName}),
32 93 mongoose_metrics:ensure_db_pool_metric({rdbms, HostType, Tag}),
33 93 WpoolOpts = make_wpool_opts(WpoolOpts0, RdbmsOpts),
34 93 ProcName = mongoose_wpool:make_pool_name(rdbms, HostType, Tag),
35 93 mongoose_wpool:start_sup_pool(rdbms, ProcName, WpoolOpts).
36
37 make_wpool_opts(WpoolOpts0, RdbmsOpts) ->
38 93 Worker = {mongoose_rdbms, RdbmsOpts},
39 93 [{worker, Worker}, {pool_sup_shutdown, infinity} | WpoolOpts0].
Line Hits Source