Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix Dialyzer type problems that then propagate to other PB-using apps. #49

Closed
wants to merge 4 commits into from

2 participants

@slfritchie
Owner

There are more Dialyzer warnings that may be affecting several
apps that I'm working on, but these are the most immediately
egregious ones.

@seancribbs

@slfritchie See also #42. Scratch my back, I'll scratch yours?

@slfritchie
Owner

Closing this PR in favor of #42.

@slfritchie slfritchie closed this
@seancribbs seancribbs deleted the slf-20120405-type-fixing branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 50 additions and 41 deletions.
  1. +2 −0  src/riakc_obj.erl
  2. +48 −41 src/riakc_pb_socket.erl
View
2  src/riakc_obj.erl
@@ -74,6 +74,8 @@
updatemetadata :: dict(),
updatevalue :: value()
}).
+-type riakc_obj() :: #riakc_obj{}.
+-export_type([riakc_obj/0]).
%% ====================================================================
%% object functions
View
89 src/riakc_pb_socket.erl
@@ -81,20 +81,27 @@
-type bucket_prop() :: {n_val, pos_integer()} | {allow_mult, boolean()}.
-type bucket_props() :: [bucket_prop()].
+-record(request, {ref :: reference(),
+ msg :: rpb_req(),
+ from,
+ ctx :: ctx(), timeout :: integer(),
+ tref :: reference() | undefined}).
+
-record(state, {address, % address to connect to
port, % port to connect to
- auto_reconnect = false, % if true, automatically reconnects to server
+ % if true, automatically reconnects to server
% if false, exits on connection failure/request timeout
- queue_if_disconnected = false, % if true, add requests to queue if disconnected
- sock, % gen_tcp socket
- active, % active request
- queue, % queue of pending requests
- connects=0, % number of successful connects
- failed=[], % breakdown of failed connects
- connect_timeout=infinity, % timeout of TCP connection
- reconnect_interval=?FIRST_RECONNECT_INTERVAL}).
--record(request, {ref :: reference(), msg :: rpb_req(), from, ctx :: ctx(), timeout :: integer(),
- tref :: reference() | undefined }).
+ auto_reconnect = false :: boolean(),
+ % if true, add requests to queue if disconnected
+ queue_if_disconnected = false :: boolean(),
+ sock, % gen_tcp socket
+ active :: undefined | #request{}, % active request
+ queue, % queue of pending requests
+ connects = 0 :: non_neg_integer(), % number of successful connects
+ failed=[], % breakdown of failed connects
+ % timeout of TCP connection
+ connect_timeout = infinity :: timeout(),
+ reconnect_interval=?FIRST_RECONNECT_INTERVAL :: non_neg_integer()}).
%% @doc Create a linked process to talk with the riak server on Address:Port
@@ -119,13 +126,13 @@ start_link(Address, Port, Options) when is_list(Options) ->
%% @doc Create a process to talk with the riak server on Address:Port
%% Client id will be assigned by the server.
--spec start(address(), portnum()) -> {ok, pid()} | {error, term()}.
+-spec start(address(), portnum()) -> {ok, pid()} | {error, term()} | ignore.
start(Address, Port) ->
start(Address, Port, []).
%% @doc Create a process to talk with the riak server on Address:Port with Options
%% See start_link/3.
--spec start(address(), portnum(), options()) -> {ok, pid()} | {error, term()}.
+-spec start(address(), portnum(), options()) -> {ok, pid()} | {error, term()} | ignore.
start(Address, Port, Options) when is_list(Options) ->
gen_server:start(?MODULE, [Address, Port, Options], []).
@@ -392,12 +399,12 @@ list_buckets(Pid, Timeout, CallTimeout) ->
gen_server:call(Pid, {req, rpblistbucketsreq, Timeout}, CallTimeout).
%% @doc List all keys in a bucket
--spec list_keys(pid(), bucket()) -> {ok, [key()]}.
+-spec list_keys(pid(), bucket()) -> {ok, [key()]} | {error, term()}.
list_keys(Pid, Bucket) ->
list_keys(Pid, Bucket, default_timeout(list_keys_timeout)).
%% @doc List all keys in a bucket specifying timeout
--spec list_keys(pid(), bucket(), timeout()) -> {ok, [key()]}.
+-spec list_keys(pid(), bucket(), timeout()) -> {ok, [key()]} | {error, term()}.
list_keys(Pid, Bucket, Timeout) ->
case stream_list_keys(Pid, Bucket, Timeout) of
{ok, ReqId} ->
@@ -818,7 +825,7 @@ handle_call(is_connected, _From, State) ->
handle_call({set_options, Options}, _From, State) ->
{reply, ok, parse_options(Options, State)};
handle_call(stop, _From, State) ->
- disconnect(State),
+ _ = disconnect(State),
{stop, normal, ok, State}.
%% @private
@@ -846,14 +853,14 @@ handle_info({tcp, Sock, Data}, State=#state{sock = Sock, active = Active}) ->
%% Send reply and get ready for the next request - send the next request
%% if one is queued up
cancel_req_timer(Active#request.tref),
- send_caller(Response, NewState0#state.active),
+ _ = send_caller(Response, NewState0#state.active),
NewState = dequeue_request(NewState0#state{active = undefined});
{pending, NewState0} -> %% Request is still pending - do not queue up a new one
NewActive = restart_req_timer(Active),
NewState = NewState0#state{active = NewActive}
end
end,
- inet:setopts(Sock, [{active, once}]),
+ ok = inet:setopts(Sock, [{active, once}]),
{noreply, NewState};
handle_info({req_timeout, Ref}, State) ->
case State#state.active of %%
@@ -1077,13 +1084,13 @@ process_response(#request{msg = rpblistbucketsreq},
process_response(#request{msg = #rpblistkeysreq{}}=Request,
#rpblistkeysresp{done = Done, keys = Keys}, State) ->
- case Keys of
- undefined ->
- ok;
- _ ->
- %% Have to directly use send_caller as may want to reply with done below.
- send_caller({keys, Keys}, Request)
- end,
+ _ = case Keys of
+ undefined ->
+ ok;
+ _ ->
+ %% Have to directly use send_caller as may want to reply with done below.
+ send_caller({keys, Keys}, Request)
+ end,
case Done of
true ->
{reply, done, State};
@@ -1104,13 +1111,13 @@ process_response(#request{msg = #rpbsetbucketreq{}},
process_response(#request{msg = #rpbmapredreq{content_type = ContentType}}=Request,
#rpbmapredresp{done = Done, phase=PhaseId, response=Data}, State) ->
- case Data of
- undefined ->
- ok;
- _ ->
- Response = decode_mapred_resp(Data, ContentType),
- send_caller({mapred, PhaseId, Response}, Request)
- end,
+ _ = case Data of
+ undefined ->
+ ok;
+ _ ->
+ Response = decode_mapred_resp(Data, ContentType),
+ send_caller({mapred, PhaseId, Response}, Request)
+ end,
case Done of
true ->
{reply, done, State};
@@ -1197,7 +1204,7 @@ create_req_timer(Msecs, Ref) ->
cancel_req_timer(undefined) ->
ok;
cancel_req_timer(Tref) ->
- erlang:cancel_timer(Tref),
+ _ = erlang:cancel_timer(Tref),
ok.
%% @private
@@ -1232,12 +1239,12 @@ connect(State) when State#state.sock =:= undefined ->
%% Disconnect socket if connected
disconnect(State) ->
%% Tell any pending requests we've disconnected
- case State#state.active of
- undefined ->
- ok;
- Request ->
- send_caller({error, disconnected}, Request)
- end,
+ _ = case State#state.active of
+ undefined ->
+ ok;
+ Request ->
+ send_caller({error, disconnected}, Request)
+ end,
%% Make sure the connection is really closed
case State#state.sock of
@@ -1272,7 +1279,7 @@ increase_reconnect_interval(State) ->
%% @private
send_request(Request, State) when State#state.active =:= undefined ->
Pkt = riakc_pb:encode(Request#request.msg),
- gen_tcp:send(State#state.sock, Pkt),
+ ok = gen_tcp:send(State#state.sock, Pkt),
maybe_reply(after_send(Request, State#state{active = Request})).
%% Queue up a request if one is pending
@@ -1299,7 +1306,7 @@ remove_queued_request(Ref, State) ->
State;
{value, Req, L2} ->
{reply, Reply, NewState} = on_timeout(Req, State),
- send_caller(Reply, Req),
+ _ = send_caller(Reply, Req),
NewState#state{queue = queue:from_list(L2)}
end.
Something went wrong with that request. Please try again.