Skip to content

Commit

Permalink
Add backward compatible of pg2 for OTP 22
Browse files Browse the repository at this point in the history
  • Loading branch information
vkatsuba committed Jul 16, 2021
1 parent e53a622 commit bb30d4d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,15 @@ workflows:
requires:
- otp_22
filters: *all_tags
- big_tests:
name: pgsql_mnesia_22
otp_package: 22.3.4.9-1
preset: pgsql_mnesia
db: pgsql
context: mongooseim-org
requires:
- otp_22
filters: *all_tags
# ============= MOST RECENT VERSION TESTS OTP 24 =============
- big_tests:
name: ldap_mnesia_24
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
matrix:
preset: [internal_mnesia, pgsql_mnesia, mysql_redis, odbc_mssql_mnesia,
ldap_mnesia, riak_mnesia, elasticsearch_and_cassandra_mnesia]
otp: ['23.0.3', '24.0.2']
otp: ['22.3', '23.0.3', '24.0.2']
runs-on: ubuntu-20.04
env:
PRESET: ${{matrix.preset}}
Expand Down
12 changes: 12 additions & 0 deletions include/backward_compatible.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-ifdef(OTP_RELEASE).
-if(?OTP_RELEASE >= 23).
-define(PG_JOIN(Group, PID), pg:join(Group, PID)).
-define(PG_GET_MEMBERS(Group), pg:get_members(Group)).
-else.
-define(PG_JOIN(Group, PID), pg2:create(Group), pg2:join(Group, PID)).
-define(PG_GET_MEMBERS(Group), pg2:get_members(Group)).
-endif.
-else.
-define(PG_JOIN(Group, PID), pg2:create(Group), pg2:join(Group, PID)).
-define(PG_GET_MEMBERS(Group), pg2:get_members(Group)).
-endif.
17 changes: 10 additions & 7 deletions src/domain/service_domain_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

-include("mongoose_config_spec.hrl").
-include("mongoose_logger.hrl").
-include("backward_compatible.hrl").

-define(GROUP, service_domain_db_group).
-define(LAST_EVENT_ID_KEY, {?MODULE, last_event_id}).
Expand Down Expand Up @@ -67,19 +68,21 @@ enabled() ->

force_check_for_updates() ->
%% Send a broadcast message.
case pg:get_members(?GROUP) of
[] -> ok;
Pids ->
case ?PG_GET_MEMBERS(?GROUP) of
[_|_] = Pids ->
[Pid ! check_for_updates || Pid <- Pids],
ok;
_ ->
ok
end.

%% Does nothing but blocks until every member processes its queue.
sync() ->
case pg:get_members(?GROUP) of
[] -> ok;
Pids ->
case ?PG_GET_MEMBERS(?GROUP) of
[_|_] = Pids ->
[gen_server:call(Pid, ping) || Pid <- Pids],
ok;
_ ->
ok
end.

Expand All @@ -90,7 +93,7 @@ sync_local() ->
%% Server callbacks

init([]) ->
pg:join(?GROUP, self()),
?PG_JOIN(?GROUP, self()),
gen_server:cast(self(), initial_loading),
%% initial state will be set on initial_loading processing
{ok, #{}}.
Expand Down
10 changes: 6 additions & 4 deletions src/mam/mod_mam_cache_user.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

-include("mongoose.hrl").
-include("jlib.hrl").
-include("backward_compatible.hrl").

-record(state, {}).

Expand Down Expand Up @@ -164,11 +165,12 @@ lookup_archive_id(ArcJID) ->
-spec clean_cache(jid:jid()) -> ok.
clean_cache(ArcJID) ->
%% Send a broadcast message.
case pg:get_members(group_name()) of
[] -> ok;
Pids ->
case ?PG_GET_MEMBERS(group_name()) of
[_|_] = Pids ->
[gen_server:cast(Pid, {remove_user, ArcJID})
|| Pid <- Pids],
ok;
_ ->
ok
end.

Expand All @@ -177,7 +179,7 @@ clean_cache(ArcJID) ->
%%====================================================================

init([]) ->
pg:join(group_name(), self()),
?PG_JOIN(group_name(), self()),
TOpts = [named_table, protected,
{write_concurrency, false},
{read_concurrency, true}],
Expand Down

0 comments on commit bb30d4d

Please sign in to comment.