./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 104 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 104 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 101 ok.
26
27 %% --------------------------------------------------------------
28 %% Helper functions
29 do_start(HostType, Tag, WpoolOpts0, RdbmsOpts) when is_list(WpoolOpts0), is_map(RdbmsOpts) ->
30 104 #{driver := BackendName} = RdbmsOpts,
31 104 mongoose_backend:init(global, mongoose_rdbms, [query, execute], #{backend => BackendName}),
32 104 mongoose_metrics:ensure_db_pool_metric({rdbms, HostType, Tag}),
33 104 WpoolOpts = make_wpool_opts(WpoolOpts0, RdbmsOpts),
34 104 ProcName = mongoose_wpool:make_pool_name(rdbms, HostType, Tag),
35 104 mongoose_wpool:start_sup_pool(rdbms, ProcName, WpoolOpts).
36
37 make_wpool_opts(WpoolOpts0, RdbmsOpts) ->
38 104 Worker = {mongoose_rdbms, RdbmsOpts},
39 104 [{worker, Worker}, {pool_sup_shutdown, infinity} | WpoolOpts0].
Line Hits Source