Skip to content

Commit

Permalink
Merge pull request #204 from basho/feature/zl/add-get-preflist
Browse files Browse the repository at this point in the history
add get_preflist to erlang-client
  • Loading branch information
seancribbs committed Feb 27, 2015
2 parents 9c76571 + 3a20f73 commit 0bf7447
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
7 changes: 6 additions & 1 deletion include/riakc.hrl
Expand Up @@ -69,7 +69,6 @@
{n_val, pos_integer()} |
{sloppy_quorum, boolean()}.


%% Valid request options for get requests. When `if_modified' is
%% specified with a vclock, the request will fail if the object has
%% not changed. When `head' is specified, only the metadata will be
Expand Down Expand Up @@ -191,3 +190,9 @@
-type search_schema() :: [{name, binary()} |
{content, binary()}].

-record(preflist_item, {
partition :: non_neg_integer(),
node :: binary(),
primary :: boolean()
}).
-type preflist() :: [#preflist_item{}].
2 changes: 1 addition & 1 deletion rebar.config
Expand Up @@ -4,7 +4,7 @@
{eunit_opts, [verbose]}.
{erl_opts, [warnings_as_errors, debug_info, nowarn_deprecated_type]}.
{deps, [
{riak_pb, "2.0.0.16", {git, "git://github.com/basho/riak_pb", {tag, "2.0.0.16"}}}
{riak_pb, "2.1.0.0", {git, "git://github.com/basho/riak_pb", {tag, "2.1.0.0"}}}
]}.
{edoc_opts, [{stylesheet_file, "priv/edoc.css"},
{preprocess, true}]}.
Expand Down
43 changes: 42 additions & 1 deletion src/riakc_pb_socket.erl
Expand Up @@ -69,7 +69,8 @@
get_index_eq/4, get_index_range/5, get_index_eq/5, get_index_range/6,
cs_bucket_fold/3,
default_timeout/1,
tunnel/4]).
tunnel/4,
get_preflist/3, get_preflist/4]).

%% Counter API
-export([counter_incr/4, counter_val/3]).
Expand Down Expand Up @@ -1210,6 +1211,22 @@ modify_type(Pid, Fun, BucketAndType, Key, Options) ->
{error, Reason}
end.

%% @doc Get active preflist.
%% @equiv get_preflist(Pid, Bucket, Key, default_timeout(get_preflist_timeout))
-spec get_preflist(pid(), bucket(), key()) -> {ok, preflist()}
| {error, term()}.
get_preflist(Pid, Bucket, Key) ->
get_preflist(Pid, Bucket, Key, default_timeout(get_preflist_timeout)).

%% @doc Get active preflist specifying a server side timeout.
%% @equiv get_preflist(Pid, Bucket, Key, default_timeout(get_preflist_timeout))
-spec get_preflist(pid(), bucket(), key(), timeout()) -> {ok, preflist()}
| {error, term()}.
get_preflist(Pid, Bucket, Key, Timeout) ->
{T, B} = maybe_bucket_type(Bucket),
Req = #rpbgetbucketkeypreflistreq{type = T, bucket = B, key = Key},
call_infinity(Pid, {req, Req, Timeout}).


%% ====================================================================
%% gen_server callbacks
Expand Down Expand Up @@ -1819,6 +1836,14 @@ process_response(#request{msg = #rpbyokozunaschemagetreq{}},
Result = [{name,Schema#rpbyokozunaschema.name}, {content,Schema#rpbyokozunaschema.content}],
{reply, {ok, Result}, State};

process_response(#request{msg = #rpbgetbucketkeypreflistreq{}},
#rpbgetbucketkeypreflistresp{preflist=Preflist}, State) ->
Result = [#preflist_item{partition=T#rpbbucketkeypreflistitem.partition,
node=T#rpbbucketkeypreflistitem.node,
primary=T#rpbbucketkeypreflistitem.primary}
|| T <- Preflist],
{reply, {ok, Result}, State};

process_response(Request, Reply, State) ->
%% Unknown request/response combo
{reply, {error, {unknown_response, Request, Reply}}, State}.
Expand Down Expand Up @@ -3805,6 +3830,22 @@ live_node_tests() ->

?assert(lists:member(<<"Z">>, L1)),
?assertEqual(length(L1), 1)
end)},
{"get preflist test",
?_test(begin
reset_riak(),
{ok, Pid} = start_link(test_ip(), test_port()),
{ok, Preflist} = get_preflist(Pid, <<"b">>, <<"f">>),
?assertEqual([#preflist_item{partition = 52,
node = <<"riak@127.0.0.1">>,
primary = true},
#preflist_item{partition = 53,
node = <<"riak@127.0.0.1">>,
primary = true},
#preflist_item{partition = 54,
node = <<"riak@127.0.0.1">>,
primary = true}],
Preflist)
end)}
].

Expand Down

0 comments on commit 0bf7447

Please sign in to comment.