diff --git a/rebar.config b/rebar.config index c1be1f64f..f0a178c5a 100644 --- a/rebar.config +++ b/rebar.config @@ -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, @@ -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"}, diff --git a/src/riak_core_gen_server.erl b/src/riak_core_gen_server.erl index 095f42525..b73289616 100644 --- a/src/riak_core_gen_server.erl +++ b/src/riak_core_gen_server.erl @@ -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). @@ -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 @@ -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 @@ -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) @@ -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} -> @@ -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}}. %% ----------------------------------------------------------------- @@ -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)). @@ -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, , ) ->_ -%% -%% Description: Makes an existing process into a gen_server. -%% The calling process will enter the gen_server receive +%% enter_loop(Mod, Options, State, , ) ->_ +%% +%% 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) -> @@ -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()}), @@ -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. @@ -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: @@ -591,7 +603,7 @@ 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 ) -> @@ -599,10 +611,10 @@ rec_nodes(Tag, [{N,R}|Tail], Name, Badnodes, Replies, Time, TimerId ) -> {'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) @@ -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 @@ -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); @@ -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); @@ -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]); @@ -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 @@ -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" @@ -937,7 +949,7 @@ debug_options(Name, Opts) -> end. dbg_options(Name, []) -> - Opts = + Opts = case init:get_argument(generic_debug) of error -> []; @@ -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 -> @@ -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 diff --git a/src/riak_core_handoff_receiver.erl b/src/riak_core_handoff_receiver.erl index 83fb65943..66881032a 100644 --- a/src/riak_core_handoff_receiver.erl +++ b/src/riak_core_handoff_receiver.erl @@ -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([]). @@ -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; diff --git a/src/riak_core_ssl_util.erl b/src/riak_core_ssl_util.erl index 4d26b24d5..735d0191e 100644 --- a/src/riak_core_ssl_util.erl +++ b/src/riak_core_ssl_util.erl @@ -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 = [ @@ -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) -> diff --git a/src/riak_core_tcp_mon.erl b/src/riak_core_tcp_mon.erl index 56f3851d8..29e678f4d 100644 --- a/src/riak_core_tcp_mon.erl +++ b/src/riak_core_tcp_mon.erl @@ -66,7 +66,6 @@ ts_hist = [], %% History of timestamps for readings hist = []}). %% History of readings - start_link() -> start_link([]). @@ -389,6 +388,15 @@ format_socket_stats([{K,V}|T], Buf) -> format_socket_stats(T, [{K, V} | Buf]). -ifdef(TEST). + +-ifdef(deprecated_21). +ssl_handshake(Socket) -> + ssl:handshake(Socket). +-else. +ssl_handshake(Socket) -> + ssl:ssl_accept(Socket). +-endif. + updown() -> %% Set the stat gathering interval to 100ms {ok, TCPMonPid} = riak_core_tcp_mon:start_link([{interval, 100}]), @@ -458,8 +466,15 @@ ssl_test_() -> spawn(fun () -> %% server {ok, S} = ssl:transport_accept(LS), - ok = ssl:ssl_accept(S), - ssl_recv_loop(S) + {ok, SslSock} = case ssl_handshake(S) of + ok -> + {ok, S}; + {ok, NewSocket} -> + {ok, NewSocket}; + Error = {error, _} -> + Error + end, + ssl_recv_loop(SslSock) end), {ok, Socket} = ssl:connect("localhost", Port, [binary, {active, true}, {certfile, "test/site2-cert.pem"}, {keyfile, "test/site2-key.pem"}]),