Skip to content

Commit

Permalink
Ensure OTP 20 compatibility
Browse files Browse the repository at this point in the history
update deps to compile with Erlang/OTP 20

test all on travis with Erlang/OTP 20

update big tests to compile and run with Erlang/OTP 20

use wpool_sup to start and stop a pool in a consistent way

use meck 0.8.6 to run small tests properly on Erlang/OTP 20

change crypto:rand_bytes to crypto:strong_rand_bytes

use fips related function according to Erlang/OTP doc

mnesia:delete_object always returns ok or throws exits signal

matching on anything else than 'ok' doesn't make sense

remove workarounds for Erlang older than 18 in tests

Use Erlang/OTP 19.3 for most of the jobs

One job with Erlang/OTP 18.3 and 20.0
Dialyzer job on Erlang/OTP 20.0

fix dialyzer warnings in mod_roster_mnesia

fix dialyzer warning for ejabberd_admin module

remove broken and not used mnesia update table logic

fix dialyzer warning in ejabberd_app module

run riak_mnesia preset with Erlang/OTP 18.3 instead of internal_mnesia

we can do this trick because riak driver is 3rd party library and
doesn't come with Erlang/OTP

this changes gives additional benefits:
* whole build is shorter by one job which is 30 minutes
* converage  on covaralls is not wrongly decreased because of the same result
  (as from other interl_mnesia job)

spefiy min OTP version in rebar.config

make elvis happy with line length

documentation update
  • Loading branch information
michalwski authored and fenek committed Oct 2, 2017
1 parent 773b4a9 commit 11f058a
Show file tree
Hide file tree
Showing 23 changed files with 91 additions and 212 deletions.
13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ after_failure:

after_success:
- ./rebar3 coveralls send
- if [ $PRESET = 'internal_mnesia' ] && [ $TRAVIS_OTP_RELEASE = "18.3" ]; then tools/travis-build-and-push-docker.sh; fi
- if [ $PRESET = 'internal_mnesia' ] && [ $TRAVIS_OTP_RELEASE = "19.3" ]; then tools/travis-build-and-push-docker.sh; fi

after_script:
- sudo pip install awscli --ignore-installed six
Expand All @@ -51,23 +51,22 @@ branches:
- /^\d+\.\d+\.\d+([a-z0-9\-\+])*/

otp_release:
- 18.3
- 19.3
env:
- PRESET=internal_mnesia DB=mnesia REL_CONFIG=with-all TLS_DIST=yes
- PRESET=mysql_redis DB=mysql REL_CONFIG="with-mysql with-redis"
- PRESET=odbc_pgsql_mnesia DB=pgsql REL_CONFIG=with-odbc
- PRESET=ldap_mnesia DB=mnesia REL_CONFIG=with-none
- PRESET=riak_mnesia DB=riak REL_CONFIG=with-riak
- PRESET=cassandra_mnesia DB=cassandra REL_CONFIG=with-cassandra CASSANDRA_VERSION=3.9

matrix:
include:
- otp_release: 19.3
- otp_release: 20.0
env: PRESET=dialyzer_only
- otp_release: 19.3
- otp_release: 20.0
env: PRESET=pgsql_mnesia DB=pgsql REL_CONFIG=with-pgsql
- otp_release: 17.5
env: PRESET=internal_mnesia DB=mnesia REL_CONFIG=with-none
- otp_release: 18.3
env: PRESET=riak_mnesia DB=riak REL_CONFIG=with-riak

notifications:
webhooks:
Expand Down
14 changes: 3 additions & 11 deletions apps/ejabberd/c_src/ejabberd_zlib_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ typedef struct {
z_stream *i_stream;
} ejabberd_zlib_data;

/* Wrappers around driver_alloc() that check */
/* for OOM. */
#ifdef HAS_ERTS_EXIT
void erts_exit(int n, char* v, ...);
#define erl_exit erts_exit
#else
void erl_exit(int n, char* v, ...);
#endif

void *ejabberd_zlib_drv_alloc(ErlDrvSizeT size);
ErlDrvBinary *ejabberd_zlib_drv_alloc_binary(ErlDrvSizeT size);
Expand All @@ -59,7 +51,7 @@ ErlDrvBinary *ejabberd_zlib_drv_realloc_binary(ErlDrvBinary *bin,
void *ejabberd_zlib_drv_alloc(ErlDrvSizeT size) {
void *p = driver_alloc(size);
if (p == NULL) {
erl_exit(1, "ejabberd_zlib_drv: Can't allocate %lu bytes of memory\n",
erts_exit(1, "ejabberd_zlib_drv: Can't allocate %lu bytes of memory\n",
size);
}
return p;
Expand All @@ -68,15 +60,15 @@ void *ejabberd_zlib_drv_alloc(ErlDrvSizeT size) {
ErlDrvBinary *ejabberd_zlib_drv_alloc_binary(ErlDrvSizeT size) {
ErlDrvBinary *p = driver_alloc_binary(size);
if (p == NULL) {
erl_exit(1, "ejabberd_zlib_drv: Can't allocate %lu binary\n", size);
erts_exit(1, "ejabberd_zlib_drv: Can't allocate %lu binary\n", size);
}
return p;
}

ErlDrvBinary *ejabberd_zlib_drv_realloc_binary(ErlDrvBinary *bin, ErlDrvSizeT size) {
ErlDrvBinary *p = driver_realloc_binary(bin, size);
if (p == NULL) {
erl_exit(1, "ejabberd_zlib_drv: Can't reallocate %lu binary\n", size);
erts_exit(1, "ejabberd_zlib_drv: Can't reallocate %lu binary\n", size);
}
return p;
}
Expand Down
2 changes: 0 additions & 2 deletions apps/ejabberd/rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
{d, xml_nif},
{parse_transform, lager_transform}]}.

{require_otp_vsn, "1[789]"}.

%% For behaviour info
{erl_first_files, [
"src/gen_mod.erl",
Expand Down
53 changes: 2 additions & 51 deletions apps/ejabberd/rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,18 @@ Setenv = fun(Key, Val) ->
os:putenv(Key, Append(Cur, Val))
end,

GetFullVer = fun() ->
Path = filename:join([code:root_dir(), "releases",
erlang:system_info(otp_release),
"OTP_VERSION"]),
{ok, BinString} = file:read_file(Path),
case re:replace(BinString, <<"\\s+">>, "", [global]) of
Version when is_binary(Version) ->
Version;
[Version | _] ->
Version
end
end,

SysVersion = lists:map(fun erlang:list_to_integer/1,
string:tokens(erlang:system_info(version), ".")),

DisableCoverage = fun(Config) ->
Opts = [{cover_enabled, false},
{cover_print_enabled, false},
{cover_export_enabled, false}],
lists:foldl(fun({Key, _}=Tuple, Acc) ->
lists:keyreplace(Key, 1, Acc, Tuple)
end, Config, Opts)
end,

MaybeDisableCoverage = fun(Config) ->
case erlang:system_info(otp_release) of
"17" ->
case catch GetFullVer() of
<<"17.5",_/binary>> -> % This is 17.5 where cover was fixed
Config;
_ ->
io:format("disabling coverage for OTP 17.0 to 17.4~n"),
DisableCoverage(Config)
end;
_ ->
Config
end
end,

MaybeFIPSSupport = fun(Config) ->
code:ensure_loaded(crypto),
case erlang:function_exported(crypto, info_fips, 0) of
false ->
Config;
_ ->
io:format("compiling with FIPS mode enabled"),
io:format("compiling with FIPS mode enabled~n"),
{erl_opts, ErlOpts} = lists:keyfind(erl_opts, 1, Config),
NewErlOpts = [{d, fips_mode} | ErlOpts],
lists:keyreplace(erl_opts, 1, Config, {erl_opts, NewErlOpts})
end
end,

MaybeErtsExitSupport = fun(Config) ->
ExitFlag = case SysVersion >= [7, 3] of
true -> "-DHAS_ERTS_EXIT";
_ -> ""
end,
true = Setenv("CFLAGS", ExitFlag),
Config
end,

lists:foldl(fun(Fun, Cfg) -> Fun(Cfg) end, CONFIG,
[MaybeDisableCoverage, MaybeFIPSSupport, MaybeErtsExitSupport]).
[MaybeFIPSSupport]).
17 changes: 8 additions & 9 deletions apps/ejabberd/src/ejabberd_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -491,21 +491,20 @@ backup_mnesia(Path) ->
| {'ok', []}
| {'table_not_exists', io_lib:chars()}.
restore_mnesia(Path) ->
ErrorString=lists:flatten( io_lib:format("Can't restore backup from ~p at node ~p: ",
[filename:absname(Path), node()])),
case ejabberd_admin:restore(Path) of
{atomic, _} ->
{ok, ""};
{error, Reason} ->
String = io_lib:format("Can't restore backup from ~p at node ~p: ~p",
[filename:absname(Path), node(), Reason]),
{cannot_restore, String};
{aborted, {no_exists, Table}} ->
String = io_lib:format("Can't restore backup from ~p at node ~p: Table ~p does not exist.",
[filename:absname(Path), node(), Table]),
String = io_lib:format("~sTable ~p does not exist.", [ErrorString, Table]),
{table_not_exists, String};
{aborted, enoent} ->
String = io_lib:format("Can't restore backup from ~p at node ~p: File not found.",
[filename:absname(Path), node()]),
{file_not_found, String}
String = ErrorString ++ "File not found.",
{file_not_found, String};
{aborted, Reason} ->
String = io_lib:format("~s~p", [ErrorString, Reason]),
{cannot_restore, String}
end.

%% @doc Mnesia database restore
Expand Down
1 change: 0 additions & 1 deletion apps/ejabberd/src/ejabberd_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ stop(_State) ->
%%%
%%% Internal functions
%%%
-spec db_init() -> list().
db_init() ->
case mnesia:system_info(extra_db_nodes) of
[] ->
Expand Down
29 changes: 0 additions & 29 deletions apps/ejabberd/src/ejabberd_s2s.erl
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ key({From, To}, StreamID) ->
%% Description: Initiates the server
%%--------------------------------------------------------------------
init([]) ->
update_tables(),
mnesia:create_table(s2s, [{ram_copies, [node()]}, {type, bag},
{attributes, record_info(fields, s2s)}]),
mnesia:add_table_copy(s2s, node(), ram_copies),
Expand Down Expand Up @@ -526,34 +525,6 @@ outgoing_s2s_number() ->
length(supervisor:which_children(ejabberd_s2s_out_sup)).


%%%----------------------------------------------------------------------
%%% Update Mnesia tables

update_tables() ->
case catch mnesia:table_info(s2s, type) of
bag ->
ok;
{'EXIT', _} ->
ok;
_ ->
mnesia:delete_table(s2s)
end,
case catch mnesia:table_info(s2s, attributes) of
[fromto, pid, key] ->
mnesia:transform_table(s2s, ignore, [fromto, pid]),
mnesia:clear_table(s2s);
[fromto, pid] ->
ok;
{'EXIT', _} ->
ok
end,
case lists:member(local_s2s, mnesia:system_info(tables)) of
true ->
mnesia:delete_table(local_s2s);
false ->
ok
end.

%% Check if host is in blacklist or white list
allow_host(MyServer, S2SHost) ->
Hosts = ?MYHOSTS,
Expand Down
11 changes: 0 additions & 11 deletions apps/ejabberd/src/mod_caps.erl
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ init_db(mnesia, _Host) ->
{local_content, true},
{attributes,
record_info(fields, caps_features)}]),
update_table(),
mnesia:add_table_copy(caps_features, node(),
disc_only_copies).

Expand Down Expand Up @@ -636,15 +635,5 @@ is_valid_node(Node) ->
false
end.

update_table() ->
Fields = record_info(fields, caps_features),
case mnesia:table_info(caps_features, attributes) of
Fields ->
ok;
_ ->
?INFO_MSG("Recreating caps_features table", []),
mnesia:transform_table(caps_features, ignore, Fields)
end.

db_type(_Host) ->
mnesia.
16 changes: 4 additions & 12 deletions apps/ejabberd/src/mod_offline_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,17 @@ remove_old_messages(_Host, TimeStamp) ->
remove_expired_message(TimeStamp, Rec) ->
case mod_offline:is_expired_message(TimeStamp, Rec) of
true ->
case mnesia:delete_object(Rec) of
ok ->
1;
_ ->
0
end;
mnesia:delete_object(Rec),
1;
false ->
0
end.

remove_old_message(TimeStamp, Rec) ->
case is_old_message(TimeStamp, Rec) of
true ->
case mnesia:delete_object(Rec) of
ok ->
1;
_ ->
0
end;
mnesia:delete_object(Rec),
1;
false ->
0
end.
Expand Down
6 changes: 3 additions & 3 deletions apps/ejabberd/src/mod_push.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
start(Host, Opts) ->
?INFO_MSG("mod_push starting on host ~p", [Host]),

{ok, _} = wpool:start_sup_pool(gen_mod:get_module_proc(Host, ?MODULE),
gen_mod:get_opt(wpool, Opts, [])),
{ok, _} = wpool_sup:start_pool(gen_mod:get_module_proc(Host, ?MODULE),
gen_mod:get_opt(wpool, Opts, [])),

gen_mod:start_backend_module(?MODULE, Opts, []),
mod_push_backend:init(Host, Opts),
Expand All @@ -89,7 +89,7 @@ stop(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_PUSH),
mod_disco:unregister_feature(Host, ?NS_PUSH),

wpool:stop_pool(gen_mod:get_module_proc(Host, ?MODULE)),
wpool_sup:stop_pool(gen_mod:get_module_proc(Host, ?MODULE)),

ok.

Expand Down
4 changes: 2 additions & 2 deletions apps/ejabberd/src/mod_push_service_mongoosepush.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ start(Host, Opts) ->
?INFO_MSG("mod_push_service starting on host ~p", [Host]),

MaxHTTPConnections = gen_mod:get_opt(max_http_connections, Opts, 100),
wpool:start_sup_pool(pool_name(Host, wpool), [{workers, MaxHTTPConnections}]),
wpool_sup:start_pool(pool_name(Host, wpool), [{workers, MaxHTTPConnections}]),

%% Hooks
ejabberd_hooks:add(push_notifications, Host, ?MODULE, push_notifications, 10),
Expand All @@ -60,7 +60,7 @@ start(Host, Opts) ->
-spec stop(Host :: ejabberd:server()) -> ok.
stop(Host) ->
ejabberd_hooks:delete(push_notifications, Host, ?MODULE, push_notifications, 10),
wpool:stop_pool(pool_name(Host, wpool)),
wpool_sup:stop_pool(pool_name(Host, wpool)),

ok.

Expand Down
2 changes: 1 addition & 1 deletion apps/ejabberd/src/mod_roster_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ get_roster_entry_t(LUser, LServer, LJID, full) ->

get_subscription_lists(_, LUser, LServer) ->
US = {LUser, LServer},
case mnesia:dirty_index_read(roster, US, #roster.us) of
case catch mnesia:dirty_index_read(roster, US, #roster.us) of
Items when is_list(Items) -> Items;
_ -> []
end.
Expand Down
6 changes: 3 additions & 3 deletions apps/ejabberd/src/mongoose_fips.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ status() ->

maybe_register_mech(MechFeature, Module, MechName) ->
case crypto:info_fips() of
disabled ->
do_register(MechFeature, Module, MechName);
enabled ->
ok;
_ ->
ok
do_register(MechFeature, Module, MechName)
end.

-endif.
Expand Down
5 changes: 0 additions & 5 deletions apps/ejabberd/src/node_flat.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ init(_Host, _ServerHost, _Opts) ->
mnesia:create_table(pubsub_item,
[{disc_only_copies, [node()]},
{attributes, record_info(fields, pubsub_item)}]),
ItemsFields = record_info(fields, pubsub_item),
case mnesia:table_info(pubsub_item, attributes) of
ItemsFields -> ok;
_ -> mnesia:transform_table(pubsub_item, ignore, ItemsFields)
end,
ok.

terminate(_Host, _ServerHost) ->
Expand Down
17 changes: 6 additions & 11 deletions apps/ejabberd/test/auth_jwt_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,12 @@ suite() ->
%%--------------------------------------------------------------------

init_per_suite(Config) ->
case list_to_integer(erlang:system_info(otp_release)) of
Release when Release < 18 ->
{skip, "jwerl need recent crypto features"};
_ ->
application:ensure_all_started(stringprep),
Self = self(),
ETSProcess = spawn(fun() -> ets_owner(Self) end),
wait_for_ets(),
meck_config(Config),
[{ets_process, ETSProcess} | Config]
end.
application:ensure_all_started(stringprep),
Self = self(),
ETSProcess = spawn(fun() -> ets_owner(Self) end),
wait_for_ets(),
meck_config(Config),
[{ets_process, ETSProcess} | Config].

end_per_suite(Config) ->
meck_cleanup(),
Expand Down
Loading

0 comments on commit 11f058a

Please sign in to comment.