Skip to content

Commit 87958bd

Browse files
authored
Merge pull request #351 from lucafavatella/dt-update-with-riak-generated-key
Expose CRDT update without key delegating key generation to Riak
2 parents 8ae580b + 778f21d commit 87958bd

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/riakc_pb_socket.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ fetch_type(Pid, BucketAndType, Key, Options) ->
12571257

12581258
%% @doc Updates the convergent datatype in Riak with local
12591259
%% modifications stored in the container type.
1260-
-spec update_type(pid(), bucket_and_type(), Key::binary(), Update::riakc_datatype:update(term())) ->
1260+
-spec update_type(pid(), bucket_and_type(), Key::binary()|'undefined', Update::riakc_datatype:update(term())) ->
12611261
ok | {ok, Key::binary()} | {ok, riakc_datatype:datatype()} |
12621262
{ok, Key::binary(), riakc_datatype:datatype()} | {error, term()}.
12631263
update_type(Pid, BucketAndType, Key, Update) ->
@@ -1266,7 +1266,7 @@ update_type(Pid, BucketAndType, Key, Update) ->
12661266
%% @doc Updates the convergent datatype in Riak with local
12671267
%% modifications stored in the container type, using the given request
12681268
%% options.
1269-
-spec update_type(pid(), bucket_and_type(), Key::binary(),
1269+
-spec update_type(pid(), bucket_and_type(), Key::binary()|'undefined',
12701270
Update::riakc_datatype:update(term()), [proplists:property()]) ->
12711271
ok | {ok, Key::binary()} | {ok, riakc_datatype:datatype()} |
12721272
{ok, Key::binary(), riakc_datatype:datatype()} | {error, term()}.

test/riakc_pb_socket_tests.erl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,25 @@ integration_tests() ->
10651065
1 == Result#search_results.num_found
10661066
end )
10671067
end)}},
1068+
{"updating without a key should generate one",
1069+
?_test(begin
1070+
riakc_test_utils:reset_riak(),
1071+
{ok, Pid} = riakc_test_utils:start_link(),
1072+
Res1 = riakc_pb_socket:update_type(Pid,
1073+
{<<"sets">>, <<"bucket">>}, undefined,
1074+
riakc_set:to_op(riakc_set:add_element(<<"X">>, riakc_set:new()))),
1075+
Res2 = riakc_pb_socket:update_type(Pid,
1076+
{<<"sets">>, <<"bucket">>}, undefined,
1077+
riakc_set:to_op(riakc_set:add_element(<<"Y">>, riakc_set:new()))),
1078+
?assertMatch({ok, _K}, Res1),
1079+
?assertMatch({ok, _K}, Res2),
1080+
{ok, K1} = Res1,
1081+
{ok, K2} = Res2,
1082+
?assertMatch(true, is_binary(K1)),
1083+
?assertMatch(true, is_binary(K2)),
1084+
% Make sure the same key isn't generated twice
1085+
?assert(Res1 =/= Res2)
1086+
end)},
10681087
{"trivial set delete",
10691088
?_test(begin
10701089
riakc_test_utils:reset_riak(),

0 commit comments

Comments
 (0)