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