Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce pool names to mongoose_rdbms #4231

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions big_tests/tests/rdbms_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
-module(rdbms_SUITE).
-compile([export_all, nowarn_export_all]).

-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").

%% We need assert from it
Expand Down Expand Up @@ -91,13 +92,18 @@ init_per_suite(Config) ->
orelse mongoose_helper:is_rdbms_enabled(host_type()) of
false -> {skip, rdbms_or_ct_not_running};
true ->
Pools = rpc(mim(), mongoose_config, get_opt, [outgoing_pools]),
GlobalRdbmsPool = stop_global_default_pool(Pools),
start_local_host_type_pool(Pools),
%% Warning: inject_module does not really work well with --rerun-big-tests flag
mongoose_helper:inject_module(?MODULE),
escalus:init_per_suite(Config)
escalus:init_per_suite([{global_default_rdbms_pool, GlobalRdbmsPool} | Config])
end.

end_per_suite(Config) ->
escalus:end_per_suite(Config).
escalus:end_per_suite(Config),
GlobalRdbmsPool = ?config(global_default_rdbms_pool, Config),
rpc(mim(), mongoose_wpool, start_configured_pools, [[GlobalRdbmsPool]]).

init_per_testcase(test_incremental_upsert, Config) ->
erase_inbox(Config),
Expand Down Expand Up @@ -325,7 +331,7 @@ read_prep_boolean_case(Config) ->

select_current_timestamp_case(Config) ->
ok = rpc(mim(), mongoose_rdbms_timestamp, prepare, []),
assert_is_integer(rpc(mim(), mongoose_rdbms_timestamp, select, [])).
assert_is_integer(rpc(mim(), mongoose_rdbms_timestamp, select, [host_type(), tag()])).

assert_is_integer(X) when is_integer(X) ->
X.
Expand Down Expand Up @@ -590,9 +596,11 @@ select_like_prep_case(Config) ->
%%--------------------------------------------------------------------
%% Helpers
%%--------------------------------------------------------------------
tag() ->
extra_tag.

sql_query(_Config, Query) ->
slow_rpc(mongoose_rdbms, sql_query, [host_type(), Query]).
slow_rpc(mongoose_rdbms, sql_query, [host_type(), tag(), Query]).

sql_prepare(_Config, Name, Table, Fields, Query) ->
escalus_ejabberd:rpc(mongoose_rdbms, prepare, [Name, Table, Fields, Query]).
Expand All @@ -601,38 +609,38 @@ sql_prepare_upsert(_Config, Name, Table, Insert, Update, Unique, Incr) ->
escalus_ejabberd:rpc(rdbms_queries, prepare_upsert, [host_type(), Name, Table, Insert, Update, Unique, Incr]).

sql_execute(_Config, Name, Parameters) ->
slow_rpc(mongoose_rdbms, execute, [host_type(), Name, Parameters]).
slow_rpc(mongoose_rdbms, execute, [host_type(), tag(), Name, Parameters]).

sql_execute_cast(_Config, Name, Parameters) ->
slow_rpc(mongoose_rdbms, execute_cast, [host_type(), Name, Parameters]).
slow_rpc(mongoose_rdbms, execute_cast, [host_type(), tag(), Name, Parameters]).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it doesn't test version without a tag now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every other test suite is still testing the old way indirectly so I thought no need to duplicate test time here 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think it would be nice to check both, but it's not a must for me.


sql_query_cast(_Config, Query) ->
slow_rpc(mongoose_rdbms, sql_query_cast, [host_type(), Query]).
slow_rpc(mongoose_rdbms, sql_query_cast, [host_type(), tag(), Query]).

sql_execute_request(_Config, Name, Parameters) ->
slow_rpc(mongoose_rdbms, execute_request, [host_type(), Name, Parameters]).
slow_rpc(mongoose_rdbms, execute_request, [host_type(), tag(), Name, Parameters]).

sql_execute_wrapped_request(_Config, Name, Parameters, WrapperFun) ->
slow_rpc(mongoose_rdbms, execute_wrapped_request, [host_type(), Name, Parameters, WrapperFun]).
slow_rpc(mongoose_rdbms, execute_wrapped_request, [host_type(), tag(), Name, Parameters, WrapperFun]).

sql_execute_wrapped_request_and_wait_response(_Config, Name, Parameters, WrapperFun) ->
slow_rpc(?MODULE, execute_wrapped_request_and_wait_response, [host_type(), Name, Parameters, WrapperFun]).
slow_rpc(?MODULE, execute_wrapped_request_and_wait_response, [host_type(), tag(), Name, Parameters, WrapperFun]).

execute_wrapped_request_and_wait_response(HostType, Name, Parameters, WrapperFun) ->
RequestId = mongoose_rdbms:execute_wrapped_request(HostType, Name, Parameters, WrapperFun),
execute_wrapped_request_and_wait_response(HostType, Tag, Name, Parameters, WrapperFun) ->
RequestId = mongoose_rdbms:execute_wrapped_request(HostType, Tag, Name, Parameters, WrapperFun),
gen_server:wait_response(RequestId, 100).

sql_execute_upsert(_Config, Name, Insert, Update, Unique) ->
slow_rpc(rdbms_queries, execute_upsert, [host_type(), Name, Insert, Update, Unique]).
slow_rpc(rdbms_queries, execute_upsert, [host_type(), tag(), Name, Insert, Update, Unique]).

sql_query_request(_Config, Query) ->
slow_rpc(mongoose_rdbms, sql_query_request, [host_type(), Query]).
slow_rpc(mongoose_rdbms, sql_query_request, [host_type(), tag(), Query]).

sql_transaction_request(_Config, Query) ->
slow_rpc(mongoose_rdbms, sql_transaction_request, [host_type(), Query]).
slow_rpc(mongoose_rdbms, sql_transaction_request, [host_type(), tag(), Query]).

sql_transaction(_Config, F) ->
slow_rpc(mongoose_rdbms, sql_transaction, [host_type(), F]).
slow_rpc(mongoose_rdbms, sql_transaction, [host_type(), tag(), F]).

escape_null(_Config) ->
escalus_ejabberd:rpc(mongoose_rdbms, escape_null, []).
Expand Down Expand Up @@ -1118,6 +1126,16 @@ is_pgsql() ->
is_mysql() ->
db_engine() == mysql.

stop_global_default_pool(Pools) ->
[GlobalRdbmsPool] = [Pool || Pool = #{type := rdbms, scope := global, tag := default} <- Pools],
ok = rpc(mim(), mongoose_wpool, stop, [rdbms, global, default]),
GlobalRdbmsPool.

start_local_host_type_pool(Pools) ->
[GlobalRdbmsPool] = [Pool || Pool = #{type := rdbms, scope := global, tag := default} <- Pools],
LocalHostTypePool = GlobalRdbmsPool#{scope := host_type(), tag := tag()},
rpc(mim(), mongoose_wpool, start_configured_pools, [[LocalHostTypePool], [host_type()]]).

escape_column(Name) ->
case is_mysql() of
true ->
Expand Down
4 changes: 4 additions & 0 deletions doc/configuration/outgoing-connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ This allows you to create multiple dedicated pools of the same type.
* `host` - the pool will be started for each XMPP host or host type served by MongooseIM
* `single_host` - the pool will be started for the selected host or host type only (you must provide the name).

!!! Note
A global pool with name `default` is used by services that are not configured by host_type, like `service_domain_db` or `service_mongoose_system_metrics`, or by modules that don't support dynamic domains, like `mod_pubsub`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't define "name" here, so maybe instead of "name default" whe should say "tag default"?

If a global pool is not configured, these services will fail.

## Worker pool options

All pools are managed by the [inaka/worker_pool](https://github.com/inaka/worker_pool) library.
Expand Down
Loading