Skip to content

Commit 47b2c79

Browse files
authored
Merge pull request #1955 (Worker pools unification)
Unify pool deps
2 parents 8fd6804 + c17fdd7 commit 47b2c79

22 files changed

+342
-465
lines changed

big_tests/tests/mam_helper.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,10 @@ is_mam_possible(Host) ->
11041104
mongoose_helper:is_odbc_enabled(Host) orelse is_riak_enabled(Host) orelse
11051105
is_cassandra_enabled(Host) orelse is_elasticsearch_enabled(Host).
11061106

1107+
%% TODO create mongoose_riak:get_status() for cleaner checks, same for cassandra and elasticsearch
11071108
is_riak_enabled(_Host) ->
1108-
case rpc(mim(), mongoose_riak, get_worker, []) of
1109-
Pid when is_pid(Pid) ->
1109+
case catch rpc(mim(), mongoose_riak, list_buckets, [<<"default">>]) of
1110+
{ok, _} ->
11101111
true;
11111112
_ ->
11121113
false

big_tests/tests/push_pubsub_SUITE.erl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,16 @@ init_per_testcase(CaseName, Config) ->
7575
MongoosePushMockPort = setup_mock_rest(),
7676

7777
%% Start HTTP pool
78-
HTTPOpts = [{mongoose_push_http, [
78+
HTTPOpts = [
7979
{server, "http://localhost:" ++ integer_to_list(MongoosePushMockPort)}
80-
]}],
81-
rpc(mongoose_http_client, start, [HTTPOpts]),
80+
],
81+
rpc(mongoose_http_client, start, []),
82+
rpc(mongoose_http_client, start_pool, [mongoose_push_http, HTTPOpts]),
8283
escalus:init_per_testcase(CaseName, Config).
8384

8485

8586
end_per_testcase(CaseName, Config) ->
87+
rpc(mongoose_http_client, stop_pool, [mongoose_push_http]),
8688
rpc(mongoose_http_client, stop, []),
8789
teardown_mock_rest(),
8890
escalus:end_per_testcase(CaseName, Config).

include/mongoose.hrl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@
3434
%% ---------------------------------
3535
%% Logging mechanism
3636
-include("mongoose_logger.hrl").
37+
38+

include/mongoose_wpool.hrl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-author("bartlomiej.gorny@erlang-solutions.com").
2+
3+
%% for worker_pool
4+
-record(mongoose_worker_pool, {name :: atom(),
5+
selection_strategy :: atom(),
6+
extra :: term(),
7+
request_timeout :: pos_integer(),
8+
pool_timeout :: pos_integer() }).

rebar.config

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
{deps,
3333
[
3434
{base16, ".*", {git, "https://github.com/goj/base16.git", "f78918e"}},
35-
{cuesport, ".*", {git, "https://github.com/esl/cuesport.git", "d82ff25"}},
36-
{redo, ".*", {git, "https://github.com/Wallapop/redo.git", "35a8d1c"}},
3735
{exml, ".*", {git, "https://github.com/esl/exml.git", {tag, "3.0.1"}}},
3836
{lager, ".*", {git, "https://github.com/erlang-lager/lager.git", {ref, "06f676a"}}},
3937
{lager_syslog, ".*", {git, "https://github.com/erlang-lager/lager_syslog.git", "3.0.3"}},
@@ -45,11 +43,10 @@
4543
{jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", "0.14.11"}},
4644
{fusco, ".*", {git, "https://github.com/esl/fusco.git", {branch, "master"}}},
4745
{idna, ".*", {git, "https://github.com/benoitc/erlang-idna.git", {tag, "1.2.0"}}},
48-
{poolboy, ".*", {git, "https://github.com/devinus/poolboy.git", {tag, "1.5.1"}}},
4946
{uuid, ".*", {git, "https://github.com/okeuday/uuid.git", {tag, "v1.7.1"}}},
5047
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls.git", "a166f0e9fe78304e5ca628fd5eff57c850241813"}},
5148
{lasse, ".*", {git, "https://github.com/inaka/lasse.git", "692eaec"}},
52-
{worker_pool, ".*", {git, "https://github.com/inaka/worker_pool.git", {tag, "3.0.0"}}},
49+
{worker_pool, ".*", {git, "https://github.com/inaka/worker_pool.git", {branch, "fix-spec-3.0.0"}}},
5350

5451
{riakc, ".*", {git, "https://github.com/basho/riak-erlang-client", "2.5.3"}},
5552
{cqerl, ".*", {git, "https://github.com/esl/cqerl.git", {ref, "08067ae"}}},

rebar.lock

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
{git,"https://github.com/bszaf/csv.git",
3232
{ref,"b0b854d8be2d69b0c6eb9bae5591008098973af9"}},
3333
0},
34-
{<<"cuesport">>,
35-
{git,"https://github.com/esl/cuesport.git",
36-
{ref,"d82ff25baf393eb11712721fb1b881b4b9f80176"}},
37-
0},
3834
{<<"eini">>,{pkg,<<"eini">>,<<"1.2.4">>},1},
3935
{<<"eodbc">>,
4036
{git,"https://github.com/arcusfelis/eodbc.git",
@@ -63,11 +59,11 @@
6359
0},
6460
{<<"exometer_report_graphite">>,
6561
{git,"https://github.com/esl/exometer_report_graphite.git",
66-
{ref,"699ea55fb351dcf6d0a72f304e4f5cede0674f50"}},
62+
{ref,"264dd7bcbadbd7febcd43917302251286c88b681"}},
6763
0},
6864
{<<"exometer_report_statsd">>,
6965
{git,"https://github.com/esl/exometer_report_statsd.git",
70-
{ref,"1264c0ca1c463a4d945936cff42d956463d32925"}},
66+
{ref,"75f6f9ef2b3c0a677f9dba9a4b3d9d77c276a032"}},
7167
0},
7268
{<<"fast_tls">>,
7369
{git,"https://github.com/processone/fast_tls.git",
@@ -76,7 +72,7 @@
7672
{<<"folsom">>,{pkg,<<"folsom">>,<<"0.8.5">>},1},
7773
{<<"fusco">>,
7874
{git,"https://github.com/esl/fusco.git",
79-
{ref,"599a413e367a50388c7e8733c32c9dac6992133f"}},
75+
{ref,"de08adef32d12f0984d6d1c6fec28be207db2e7e"}},
8076
0},
8177
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1},
8278
{<<"gun">>,
@@ -117,7 +113,7 @@
117113
{<<"lhttpc">>,{pkg,<<"lhttpc">>,<<"1.5.1">>},1},
118114
{<<"luerl">>,
119115
{git,"https://github.com/rvirding/luerl.git",
120-
{ref,"a9c35b8faff7c77676c12ca4e1beb60959bf515f"}},
116+
{ref,"091fca3d03de5de19efebb2bd37523cdef4bbdb5"}},
121117
2},
122118
{<<"lz4">>,
123119
{git,"https://github.com/szktty/erlang-lz4.git",
@@ -154,19 +150,12 @@
154150
{ref,"1a29ef3e112ee0a8d8ac53bd6963ccc8f7879343"}},
155151
0},
156152
{<<"observer_cli">>,{pkg,<<"observer_cli">>,<<"1.1.0">>},0},
157-
{<<"p1_utils">>,
158-
{git,"https://github.com/processone/p1_utils",
159-
{ref,"470539abadf8b69c9647d17eb6c033d39dc7e6d7"}},
160-
1},
153+
{<<"p1_utils">>,{pkg,<<"p1_utils">>,<<"1.0.10">>},1},
161154
{<<"pa">>,
162155
{git,"https://github.com/erszcz/pa.git",
163156
{ref,"e53c540005f4114a854cfa414b00cbc7e9e65ecb"}},
164157
0},
165158
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.1.0">>},1},
166-
{<<"poolboy">>,
167-
{git,"https://github.com/devinus/poolboy.git",
168-
{ref,"3bb48a893ff5598f7c73731ac17545206d259fac"}},
169-
0},
170159
{<<"pooler">>,{pkg,<<"pooler">>,<<"1.5.3">>},1},
171160
{<<"proper">>,
172161
{git,"https://github.com/manopapad/proper.git",
@@ -188,10 +177,6 @@
188177
{git,"https://github.com/ferd/recon.git",
189178
{ref,"fcc1a7db6d367234171ab24a3d1762f94e57ff22"}},
190179
0},
191-
{<<"redo">>,
192-
{git,"https://github.com/Wallapop/redo.git",
193-
{ref,"35a8d1caa7bdf431826e63665646cf0c8196e688"}},
194-
0},
195180
{<<"riak_pb">>,
196181
{git,"https://github.com/basho/riak_pb",
197182
{ref,"08771aba2ce4935b715d32d1b92555efdc3da994"}},
@@ -231,7 +216,7 @@
231216
0},
232217
{<<"worker_pool">>,
233218
{git,"https://github.com/inaka/worker_pool.git",
234-
{ref,"86de749ba4a7b253eba075940e44bcc026c2c7ba"}},
219+
{ref,"888ef6a376a3797d1a517bbf901019558e6a7150"}},
235220
0}]}.
236221
[
237222
{pkg_hash,[
@@ -250,6 +235,7 @@
250235
{<<"metrics">>, <<"25F094DEA2CDA98213CECC3AEFF09E940299D950904393B2A29D191C346A8486">>},
251236
{<<"mimerl">>, <<"993F9B0E084083405ED8252B99460C4F0563E41729AB42D9074FD5E52439BE88">>},
252237
{<<"observer_cli">>, <<"F3A47C22327424291758167DF3C4600DCF8BF34795A3787612019AA5B86A5C21">>},
238+
{<<"p1_utils">>, <<"A6D6927114BAC79CF6468A10824125492034AF7071ADC6ED5EBC4DDB443845D4">>},
253239
{<<"parse_trans">>, <<"1BAD3B959941CC53FFD6F4769A5D2666F9CDF179B2D62826636497D3FBAD9EC0">>},
254240
{<<"pooler">>, <<"898CD1FA301FC42D4A8ED598CE139B71CA85B54C16AB161152B5CC5FBDCFA1A8">>},
255241
{<<"ssl_verify_fun">>, <<"28A4D65B7F59893BC2C7DE786DEC1E1555BD742D336043FE644AE956C3497FBE">>}]}

src/auth/ejabberd_auth_http.erl

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,13 @@
4343

4444
-spec start(binary()) -> ok.
4545
start(Host) ->
46-
AuthHost = ejabberd_auth:get_opt(Host, host),
47-
PoolSize = ejabberd_auth:get_opt(Host, connection_pool_size, 10),
48-
Opts = ejabberd_auth:get_opt(Host, connection_opts, []),
49-
ChildMods = [fusco],
50-
ChildMF = {fusco, start_link},
51-
ChildArgs = {for_all, [AuthHost, Opts]},
52-
ChildSpec = {{ejabberd_auth_http_sup, Host},
53-
{cuesport, start_link,
54-
[pool_name(Host), PoolSize, ChildMods, ChildMF, ChildArgs]},
55-
transient, 2000, supervisor, [cuesport | ChildMods]},
56-
ejabberd_sup:start_child(ChildSpec),
46+
Opts = [{selection_strategy, ejabberd_auth:get_opt(Host, selection_strategy, random_worker)},
47+
{server, ejabberd_auth:get_opt(Host, host)},
48+
{path_prefix, ejabberd_auth:get_opt(Host, path_prefix, "")},
49+
{pool_size, ejabberd_auth:get_opt(Host, connection_pool_size, 20)},
50+
{http_opts, ejabberd_auth:get_opt(Host, connection_opts, [])}
51+
],
52+
mongoose_http_client:start_pool(pool_name(Host), Opts),
5753
ok.
5854

5955

@@ -220,12 +216,6 @@ remove_user_req(LUser, LServer, Password, Method) ->
220216
make_req(_, _, LUser, LServer, _) when LUser == error orelse LServer == error ->
221217
{error, invalid_jid};
222218
make_req(Method, Path, LUser, LServer, Password) ->
223-
PathPrefix = case ejabberd_auth:get_opt(LServer, path_prefix) of
224-
undefined ->
225-
<<"/">>;
226-
Prefix ->
227-
ejabberd_binary:string_to_binary(Prefix)
228-
end,
229219
LUserE = list_to_binary(http_uri:encode(binary_to_list(LUser))),
230220
LServerE = list_to_binary(http_uri:encode(binary_to_list(LServer))),
231221
PasswordE = list_to_binary(http_uri:encode(binary_to_list(Password))),
@@ -237,14 +227,11 @@ make_req(Method, Path, LUser, LServer, Password) ->
237227
BasicAuth64 = base64:encode(BasicAuth),
238228
[{<<"Authorization">>, <<"Basic ", BasicAuth64/binary>>}]
239229
end,
240-
Connection = cuesport:get_worker(existing_pool_name(LServer)),
241230

242231
?DEBUG("Making request '~s' for user ~s@~s...", [Path, LUser, LServer]),
243-
{ok, {{Code, _Reason}, _RespHeaders, RespBody, _, _}} = case Method of
244-
get -> fusco:request(Connection, <<PathPrefix/binary, Path/binary, "?", Query/binary>>,
245-
"GET", Header, "", 2, 5000);
246-
post -> fusco:request(Connection, <<PathPrefix/binary, Path/binary>>,
247-
"POST", Header, Query, 2, 5000)
232+
{ok, {Code, RespBody}} = case Method of
233+
get -> mongoose_http_client:get(pool_name(LServer), <<Path/binary, "?", Query/binary>>, Header);
234+
post -> mongoose_http_client:post(pool_name(LServer), Path, Header, Query)
248235
end,
249236

250237
?DEBUG("Request result: ~s: ~p", [Code, RespBody]),
@@ -266,10 +253,6 @@ make_req(Method, Path, LUser, LServer, Password) ->
266253
pool_name(Host) ->
267254
list_to_atom("ejabberd_auth_http_" ++ binary_to_list(Host)).
268255

269-
-spec existing_pool_name(binary()) -> atom().
270-
existing_pool_name(Host) ->
271-
list_to_existing_atom("ejabberd_auth_http_" ++ binary_to_list(Host)).
272-
273256
-spec verify_scram_password(binary(), binary(), binary()) ->
274257
{ok, boolean()} | {error, bad_request | not_exists}.
275258
verify_scram_password(LUser, LServer, Password) ->

src/ejabberd_app.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ start(normal, _Args) ->
4949
acl:start(),
5050
ejabberd_node_id:start(),
5151
ejabberd_ctl:init(),
52+
mongoose_wpool:ensure_started(),
5253
ejabberd_commands:init(),
5354
mongoose_commands:init(),
5455
mongoose_subhosts:init(),

src/ejabberd_redis.erl

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/ejabberd_sm.erl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,11 @@ handle_info(_Info, State) ->
535535
%%--------------------------------------------------------------------
536536
-spec terminate(_, state()) -> 'ok'.
537537
terminate(_Reason, _State) ->
538-
ejabberd_commands:unregister_commands(commands()),
538+
try
539+
ejabberd_commands:unregister_commands(commands())
540+
catch E:R ->
541+
?ERROR_MSG("Caught error while terminating sm: ~p:~p~n~p", [E, R, erlang:get_stacktrace()])
542+
end,
539543
ok.
540544

541545
%%--------------------------------------------------------------------

0 commit comments

Comments
 (0)