Skip to content

Commit

Permalink
Merge pull request #949 from IRog/develop-3.0
Browse files Browse the repository at this point in the history
fixing platform deprecation, newlines, and lager upgrade
  • Loading branch information
martinsumner authored Nov 25, 2019
2 parents a01d63a + 90dc9c8 commit ce810ce
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 53 deletions.
8 changes: 5 additions & 3 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
{cover_enabled, true}.
{erl_opts, [warnings_as_errors,
{parse_transform, lager_transform},
debug_info, {platform_define, "^[0-9]+", namespaced_types},
{platform_define, "^R15", "old_hash"}]}.
debug_info,
{platform_define, "^[0-9]+", namespaced_types},
{platform_define, "^R15", "old_hash"},
{platform_define, "^[2-9][1-9][0-9]*(.?[0-9]*)", deprecated_21}]}.
{edoc_opts, [{preprocess, true}]}.
{eunit_opts, [verbose]}.
{xref_checks,[undefined_function_calls,undefined_functions,locals_not_used,
Expand All @@ -13,7 +15,7 @@
{plugins, [{rebar3_eqc, {git, "https://github.com/Vagabond/rebar3-eqc-plugin", {branch, "master"}}}]}.

{deps, [
{lager, ".*", {git, "git://github.com/erlang-lager/lager.git", {tag, "3.6.1"}}},
{lager, ".*", {git, "git://github.com/erlang-lager/lager.git", {tag, "3.6.10"}}},
{poolboy, ".*", {git, "https://github.com/Kyorai/poolboy.git", {branch, "r21"}}},
{basho_stats, ".*", {git, "git://github.com/basho/basho_stats.git", {branch, "develop-3.0"}}},
{riak_sysmon, "~>2.1.7"},
Expand Down
102 changes: 57 additions & 45 deletions src/riak_core_gen_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved via the world wide web at http://www.erlang.org/.
%%
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%%
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
%% AB. All Rights Reserved.''
%%
%%
%% $Id$
%%
-module(riak_core_gen_server).
Expand All @@ -63,13 +63,13 @@
%%%
%%% The idea behind THIS server is that the user module
%%% provides (different) functions to handle different
%%% kind of inputs.
%%% kind of inputs.
%%% If the Parent process terminates the Module:terminate/2
%%% function is called.
%%%
%%% The user module should export:
%%%
%%% init(Args)
%%% init(Args)
%%% ==> {ok, State}
%%% {ok, State, Timeout}
%%% ignore
Expand All @@ -81,21 +81,21 @@
%%% {reply, Reply, State, Timeout}
%%% {noreply, State}
%%% {noreply, State, Timeout}
%%% {stop, Reason, Reply, State}
%%% {stop, Reason, Reply, State}
%%% Reason = normal | shutdown | Term terminate(State) is called
%%%
%%% handle_cast(Msg, State)
%%%
%%% ==> {noreply, State}
%%% {noreply, State, Timeout}
%%% {stop, Reason, State}
%%% {stop, Reason, State}
%%% Reason = normal | shutdown | Term terminate(State) is called
%%%
%%% handle_info(Info, State) Info is e.g. {'EXIT', P, R}, {nodedown, N}, ...
%%%
%%% ==> {noreply, State}
%%% {noreply, State, Timeout}
%%% {stop, Reason, State}
%%% {stop, Reason, State}
%%% Reason = normal | shutdown | Term, terminate(State) is called
%%%
%%% terminate(Reason, State) Let the user module clean up
Expand Down Expand Up @@ -178,6 +178,18 @@
Extra :: term()) ->
{ok, NewState :: term()} | {error, Reason :: term()}.

%%%=========================================================================
%%% Preprocessor
%%%=========================================================================

-ifdef(deprecated_21).
get_log(Debug) ->
sys:get_log(Debug).
-else.
get_log(Debug) ->
sys:get_debug(log, Debug, []).
-endif.

%%% -----------------------------------------------------------------
%%% Starts a generic server.
%%% start(Mod, Args, Options)
Expand Down Expand Up @@ -213,7 +225,7 @@ start_link(Name, Mod, Args, Options) ->
%% be monitored.
%% If the client is trapping exits and is linked server termination
%% is handled here (? Shall we do that here (or rely on timeouts) ?).
%% -----------------------------------------------------------------
%% -----------------------------------------------------------------
call(Name, Request) ->
case catch gen:call(Name, '$gen_call', Request) of
{ok,Res} ->
Expand Down Expand Up @@ -252,33 +264,33 @@ pcall(Name, Priority, Request, Timeout) ->
cast({global,Name}, Request) ->
catch global:send(Name, cast_msg(Request)),
ok;
cast({Name,Node}=Dest, Request) when is_atom(Name), is_atom(Node) ->
cast({Name,Node}=Dest, Request) when is_atom(Name), is_atom(Node) ->
do_cast(Dest, Request);
cast(Dest, Request) when is_atom(Dest) ->
do_cast(Dest, Request);
cast(Dest, Request) when is_pid(Dest) ->
do_cast(Dest, Request).

do_cast(Dest, Request) ->
do_cast(Dest, Request) ->
do_send(Dest, cast_msg(Request)),
ok.

cast_msg(Request) -> {'$gen_cast',Request}.

pcast({global,Name}, Priority, Request) ->
catch global:send(Name, cast_msg(Priority, Request)),
ok;
pcast({Name,Node}=Dest, Priority, Request) when is_atom(Name), is_atom(Node) ->
pcast({Name,Node}=Dest, Priority, Request) when is_atom(Name), is_atom(Node) ->
do_cast(Dest, Priority, Request);
pcast(Dest, Priority, Request) when is_atom(Dest) ->
do_cast(Dest, Priority, Request);
pcast(Dest, Priority, Request) when is_pid(Dest) ->
do_cast(Dest, Priority, Request).

do_cast(Dest, Priority, Request) ->
do_cast(Dest, Priority, Request) ->
do_send(Dest, cast_msg(Priority, Request)),
ok.

cast_msg(Priority, Request) -> {'$gen_pcast', {Priority, Request}}.

%% -----------------------------------------------------------------
Expand All @@ -287,9 +299,9 @@ cast_msg(Priority, Request) -> {'$gen_pcast', {Priority, Request}}.
reply({To, Tag}, Reply) ->
catch To ! {Tag, Reply}.

%% -----------------------------------------------------------------
%% -----------------------------------------------------------------
%% Asyncronous broadcast, returns nothing, it's just send'n prey
%%-----------------------------------------------------------------
%%-----------------------------------------------------------------
abcast(Name, Request) when is_atom(Name) ->
do_abcast([node() | nodes()], Name, cast_msg(Request)).

Expand All @@ -305,36 +317,36 @@ do_abcast([], _,_) -> abcast.
%%% Make a call to servers at several nodes.
%%% Returns: {[Replies],[BadNodes]}
%%% A Timeout can be given
%%%
%%%
%%% A middleman process is used in case late answers arrives after
%%% the timeout. If they would be allowed to glog the callers message
%%% queue, it would probably become confused. Late answers will
%%% queue, it would probably become confused. Late answers will
%%% now arrive to the terminated middleman and so be discarded.
%%% -----------------------------------------------------------------
multi_call(Name, Req)
when is_atom(Name) ->
do_multi_call([node() | nodes()], Name, Req, infinity).

multi_call(Nodes, Name, Req)
multi_call(Nodes, Name, Req)
when is_list(Nodes), is_atom(Name) ->
do_multi_call(Nodes, Name, Req, infinity).

multi_call(Nodes, Name, Req, infinity) ->
do_multi_call(Nodes, Name, Req, infinity);
multi_call(Nodes, Name, Req, Timeout)
multi_call(Nodes, Name, Req, Timeout)
when is_list(Nodes), is_atom(Name), is_integer(Timeout), Timeout >= 0 ->
do_multi_call(Nodes, Name, Req, Timeout).


%%-----------------------------------------------------------------
%% enter_loop(Mod, Options, State, <ServerName>, <TimeOut>) ->_
%%
%% Description: Makes an existing process into a gen_server.
%% The calling process will enter the gen_server receive
%% enter_loop(Mod, Options, State, <ServerName>, <TimeOut>) ->_
%%
%% Description: Makes an existing process into a gen_server.
%% The calling process will enter the gen_server receive
%% loop and become a gen_server process.
%% The process *must* have been started using one of the
%% start functions in proc_lib, see proc_lib(3).
%% The user is responsible for any initialization of the
%% The process *must* have been started using one of the
%% start functions in proc_lib, see proc_lib(3).
%% The user is responsible for any initialization of the
%% process, including registering a name for it.
%%-----------------------------------------------------------------
enter_loop(Mod, Options, State) ->
Expand Down Expand Up @@ -373,7 +385,7 @@ init_it(Starter, Parent, Name0, Mod, Args, Options) ->
Queue = riak_core_priority_queue:new(),
case catch Mod:init(Args) of
{ok, State} ->
proc_lib:init_ack(Starter, {ok, self()}),
proc_lib:init_ack(Starter, {ok, self()}),
loop(Parent, Name, State, Mod, infinity, undefined, Queue, Debug);
{ok, State, Timeout} ->
proc_lib:init_ack(Starter, {ok, self()}),
Expand Down Expand Up @@ -564,7 +576,7 @@ do_multi_call(Nodes, Name, Req, Timeout) ->
{'DOWN',Mref,_,_,{Receiver,Tag,Result}} ->
Result;
{'DOWN',Mref,_,_,Reason} ->
%% The middleman code failed. Or someone did
%% The middleman code failed. Or someone did
%% exit(_, kill) on the middleman process => Reason==killed
exit(Reason)
end.
Expand All @@ -581,7 +593,7 @@ send_nodes([Node|Tail], Name, Tag, Req, Monitors)
send_nodes([_Node|Tail], Name, Tag, Req, Monitors) ->
%% Skip non-atom Node
send_nodes(Tail, Name, Tag, Req, Monitors);
send_nodes([], _Name, _Tag, _Req, Monitors) ->
send_nodes([], _Name, _Tag, _Req, Monitors) ->
Monitors.

%% Against old nodes:
Expand All @@ -591,18 +603,18 @@ send_nodes([], _Name, _Tag, _Req, Monitors) ->
%% Against contemporary nodes:
%% Wait for reply, server 'DOWN', or timeout from TimerId.

rec_nodes(Tag, Nodes, Name, TimerId) ->
rec_nodes(Tag, Nodes, Name, TimerId) ->
rec_nodes(Tag, Nodes, Name, [], [], 2000, TimerId).

rec_nodes(Tag, [{N,R}|Tail], Name, Badnodes, Replies, Time, TimerId ) ->
receive
{'DOWN', R, _, _, _} ->
rec_nodes(Tag, Tail, Name, [N|Badnodes], Replies, Time, TimerId);
{{Tag, N}, Reply} -> %% Tag is bound !!!
unmonitor(R),
rec_nodes(Tag, Tail, Name, Badnodes,
unmonitor(R),
rec_nodes(Tag, Tail, Name, Badnodes,
[{N,Reply}|Replies], Time, TimerId);
{timeout, TimerId, _} ->
{timeout, TimerId, _} ->
unmonitor(R),
%% Collect all replies that already have arrived
rec_nodes_rest(Tag, Tail, Name, [N|Badnodes], Replies)
Expand All @@ -618,7 +630,7 @@ rec_nodes(Tag, [N|Tail], Name, Badnodes, Replies, Time, TimerId) ->
monitor_node(N, false),
rec_nodes(Tag, Tail, Name, Badnodes,
[{N,Reply}|Replies], 2000, TimerId);
{timeout, TimerId, _} ->
{timeout, TimerId, _} ->
receive {nodedown, N} -> ok after 0 -> ok end,
monitor_node(N, false),
%% Collect all replies that already have arrived
Expand Down Expand Up @@ -732,7 +744,7 @@ handle_msg({'$gen_call', From, Msg},
{noreply, NState, Time1} ->
loop(Parent, Name, NState, Mod, Time1, TimeoutState, Queue, []);
{stop, Reason, Reply, NState} ->
{'EXIT', R} =
{'EXIT', R} =
(catch terminate(Reason, Name, Msg, Mod, NState, [])),
reply(From, Reply),
exit(R);
Expand Down Expand Up @@ -765,7 +777,7 @@ handle_msg({'$gen_call', From, Msg},
{noreply, NState}),
loop(Parent, Name, NState, Mod, Time1, TimeoutState, Queue, Debug1);
{stop, Reason, Reply, NState} ->
{'EXIT', R} =
{'EXIT', R} =
(catch terminate(Reason, Name, Msg, Mod, NState, Debug)),
_ = reply(Name, From, Reply, NState, Debug),
exit(R);
Expand Down Expand Up @@ -857,7 +869,7 @@ print_event(Dev, {in, Msg}, Name) ->
io:format(Dev, "*DBG* ~p got ~p~n", [Name, Msg])
end;
print_event(Dev, {out, Msg, To, State}, Name) ->
io:format(Dev, "*DBG* ~p sent ~p to ~w, new state ~w~n",
io:format(Dev, "*DBG* ~p sent ~p to ~w, new state ~w~n",
[Name, Msg, To, State]);
print_event(Dev, {noreply, State}, Name) ->
io:format(Dev, "*DBG* ~p new state ~w~n", [Name, State]);
Expand Down Expand Up @@ -894,7 +906,7 @@ error_info(_Reason, application_controller, _Msg, _State, _Debug) ->
%% of it instead
ok;
error_info(Reason, Name, Msg, State, Debug) ->
Reason1 =
Reason1 =
case Reason of
{undef,[{M,F,A}|MFAs]} ->
case code:is_loaded(M) of
Expand All @@ -910,7 +922,7 @@ error_info(Reason, Name, Msg, State, Debug) ->
end;
_ ->
Reason
end,
end,
format("** Generic server ~p terminating \n"
"** Last message in was ~p~n"
"** When Server state == ~p~n"
Expand All @@ -937,7 +949,7 @@ debug_options(Name, Opts) ->
end.

dbg_options(Name, []) ->
Opts =
Opts =
case init:get_argument(generic_debug) of
error ->
[];
Expand Down Expand Up @@ -968,7 +980,7 @@ get_proc_name({local, Name}) ->
exit(process_not_registered);
[] ->
exit(process_not_registered)
end;
end;
get_proc_name({global, Name}) ->
case global:whereis_name(Name) of
undefined ->
Expand Down Expand Up @@ -1015,8 +1027,8 @@ format_status(Opt, StatusData) ->
Name
end,
Header = lists:concat(["Status for generic server ", NameTag]),
Log = sys:get_debug(log, Debug, []),
Specfic =
Log = get_log(Debug),
Specfic =
case erlang:function_exported(Mod, format_status, 2) of
true ->
case catch Mod:format_status(Opt, [PDict, State]) of
Expand Down
10 changes: 9 additions & 1 deletion src/riak_core_handoff_receiver.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
%% set the timeout for the vnode to process the handoff_data msg to 60s
-define(VNODE_TIMEOUT, 60000).

-ifdef(deprecated_21).
ssl_handshake(Socket, SslOpts, Timeout) ->
ssl:handshake(Socket, SslOpts, Timeout).
-else.
ssl_handshake(Socket, SslOpts, Timeout) ->
ssl:ssl_accept(Socket, SslOpts, Timeout).
-endif.

start_link() ->
start_link([]).

Expand All @@ -69,7 +77,7 @@ init([SslOpts]) ->
handle_call({set_socket, Socket0}, _From, State = #state{ssl_opts = SslOpts}) ->
SockOpts = [{active, once}, {packet, 4}, {header, 1}],
Socket = if SslOpts /= [] ->
{ok, Skt} = ssl:ssl_accept(Socket0, SslOpts, 30*1000),
{ok, Skt} = ssl_handshake(Socket0, SslOpts, 30*1000),
ok = ssl:setopts(Skt, SockOpts),
Peer = safe_peername(Skt, ssl),
Skt;
Expand Down
10 changes: 9 additions & 1 deletion src/riak_core_ssl_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
-include_lib("eunit/include/eunit.hrl").
-endif.

-ifdef(deprecated_21).
ssl_handshake(Socket, SslOpts) ->
ssl:handshake(Socket, SslOpts).
-else.
ssl_handshake(Socket, SslOpts) ->
ssl:ssl_accept(Socket, SslOpts).
-endif.


maybe_use_ssl(App) ->
SSLOpts = [
Expand Down Expand Up @@ -128,7 +136,7 @@ upgrade_server_to_ssl(Socket, App) ->
false ->
{error, no_ssl_config};
Config ->
ssl:ssl_accept(Socket, Config)
ssl_handshake(Socket, Config)
end.

load_certs(undefined) ->
Expand Down
Loading

0 comments on commit ce810ce

Please sign in to comment.