Skip to content

Commit

Permalink
Merge pull request #289 from basho/fixes/lrb/riak-generated-key-gh-287
Browse files Browse the repository at this point in the history
READY: Correctly process Riak generated keys
  • Loading branch information
lukebakken committed May 24, 2016
2 parents 96f2b74 + ee3d3cf commit f413c22
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,13 @@ Troubleshooting

If `start/2` or `start_link/2` return `{error,econnrefused}` the client could not connect to the server - make sure the protocol buffers interface is enabled on the server and the address/port is correct.

Contributors
============

This is not a comprehensive list, please see the commit history.

* [Sam Tavakoli](https://github.com/sata)

[basho_docs]: http://docs.basho.com/
[kv_setup]: http://docs.basho.com/riak/kv/latest/setup/
[erlang_client_edocs]: http://basho.github.com/riak-erlang-client/
Expand Down
36 changes: 25 additions & 11 deletions src/riakc_pb_socket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,8 @@ process_response(#request{msg = rpbgetserverinforeq},
[{server_version, ServerVersion}]
end,
{reply, {ok, NodeInfo++VersionInfo}, State};

%% rpbgetreq
process_response(#request{msg = #rpbgetreq{}}, rpbgetresp, State) ->
%% server just returned the rpbgetresp code - no message was encoded
{reply, {error, notfound}, State};
Expand All @@ -1654,16 +1656,23 @@ process_response(#request{msg = #rpbgetreq{type = Type, bucket = Bucket, key = K
B = maybe_make_bucket_type(Type, Bucket),
{reply, {ok, riakc_obj:new_obj(B, Key, Vclock, Contents)}, State};

%% rpbputreq
process_response(#request{msg = #rpbputreq{}},
rpbputresp, State) ->
%% server just returned the rpbputresp code - no message was encoded
{reply, ok, State};
process_response(#request{ msg = #rpbputreq{}},
process_response(#request{msg = #rpbputreq{}},
#rpbputresp{key = Key, content=undefined, vclock=undefined},
State) when is_binary(Key) ->
%% server generated a key and the client didn't request return_body, but
%% the created key is returned
{reply, {ok, Key}, State};
process_response(#request{msg = #rpbputreq{}},
#rpbputresp{key = Key, content=[], vclock=undefined},
State) when is_binary(Key) ->
%% server generated a key and the client didn't request return_body, but
%% the created key is returned
{reply, {ok, Key}, State};
process_response(#request{msg = #rpbputreq{type = Type, bucket = Bucket, key = Key}},
#rpbputresp{content = RpbContents, vclock = Vclock,
key = NewKey}, State) ->
Expand Down Expand Up @@ -3269,14 +3278,19 @@ live_node_tests() ->
end)},
{"putting without a key should generate one",
?_test(begin
reset_riak(),
{ok, Pid} = start_link(test_ip(), test_port()),
PO = riakc_obj:new(<<"b">>, undefined, <<"value">>),
Res1 = ?MODULE:put(Pid, PO),
Res2 = ?MODULE:put(Pid, PO),
?assertMatch({ok, _Key}, Res1),
% Make sure the same key isn't generated twice
?assert(Res1 =/= Res2)
reset_riak(),
{ok, Pid} = start_link(test_ip(), test_port()),
PO = riakc_obj:new(<<"b">>, undefined, <<"value">>),
Res1 = ?MODULE:put(Pid, PO),
Res2 = ?MODULE:put(Pid, PO),
?assertMatch({ok, _K}, Res1),
?assertMatch({ok, _K}, Res2),
{ok, K1} = Res1,
{ok, K2} = Res2,
?assertMatch(true, is_binary(K1)),
?assertMatch(true, is_binary(K2)),
% Make sure the same key isn't generated twice
?assert(Res1 =/= Res2)
end)},
{"putting without a key should generate one with return_body",
?_test(begin
Expand All @@ -3286,8 +3300,8 @@ live_node_tests() ->
{ok, Obj1} = ?MODULE:put(Pid, PO, [return_body]),
{ok, Obj2} = ?MODULE:put(Pid, PO, [return_body]),
%% Make sure the same key isn't generated twice
?assertEqual(element(1, Obj1), riakc_obj),
?assertEqual(element(1, Obj2), riakc_obj),
?assertEqual(riakc_obj, element(1, Obj1)),
?assertEqual(riakc_obj, element(1, Obj2)),
?assert(riakc_obj:key(Obj1) /= riakc_obj:key(Obj2))
end)},
{"conditional gets should return unchanged if the vclock matches",
Expand Down

0 comments on commit f413c22

Please sign in to comment.