Skip to content

Commit b2a5002

Browse files
Luca FavatellaLuke Bakken
authored andcommitted
Expose CRDT update without key delegating key generation to Riak
Optional key in request and Riak-generated key are [documented already](https://github.com/basho/basho_docs/blob/814125935ca55a5801764dcb780534a89b599dec/content/riak/kv/2.2.0/developing/api/protocol-buffers/dt-store.md#optional-parameters). PB encoder [already has type spec](https://github.com/basho/riak_pb/blob/4198223ec788401da5cbf2868e3181b6b5db289a/src/riak_pb_dt_codec.erl#L490-L494) catering for optional key.
1 parent f3e6401 commit b2a5002

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
@@ -1225,7 +1225,7 @@ fetch_type(Pid, BucketAndType, Key, Options) ->
12251225

12261226
%% @doc Updates the convergent datatype in Riak with local
12271227
%% modifications stored in the container type.
1228-
-spec update_type(pid(), bucket_and_type(), Key::binary(), Update::riakc_datatype:update(term())) ->
1228+
-spec update_type(pid(), bucket_and_type(), Key::binary()|'undefined', Update::riakc_datatype:update(term())) ->
12291229
ok | {ok, Key::binary()} | {ok, riakc_datatype:datatype()} |
12301230
{ok, Key::binary(), riakc_datatype:datatype()} | {error, term()}.
12311231
update_type(Pid, BucketAndType, Key, Update) ->
@@ -1234,7 +1234,7 @@ update_type(Pid, BucketAndType, Key, Update) ->
12341234
%% @doc Updates the convergent datatype in Riak with local
12351235
%% modifications stored in the container type, using the given request
12361236
%% options.
1237-
-spec update_type(pid(), bucket_and_type(), Key::binary(),
1237+
-spec update_type(pid(), bucket_and_type(), Key::binary()|'undefined',
12381238
Update::riakc_datatype:update(term()), [proplists:property()]) ->
12391239
ok | {ok, Key::binary()} | {ok, riakc_datatype:datatype()} |
12401240
{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
@@ -999,6 +999,25 @@ integration_tests() ->
999999
1 == Result#search_results.num_found
10001000
end )
10011001
end)}},
1002+
{"updating without a key should generate one",
1003+
?_test(begin
1004+
riakc_test_utils:reset_riak(),
1005+
{ok, Pid} = riakc_test_utils:start_link(),
1006+
Res1 = riakc_pb_socket:update_type(Pid,
1007+
{<<"sets">>, <<"bucket">>}, undefined,
1008+
riakc_set:to_op(riakc_set:add_element(<<"X">>, riakc_set:new()))),
1009+
Res2 = riakc_pb_socket:update_type(Pid,
1010+
{<<"sets">>, <<"bucket">>}, undefined,
1011+
riakc_set:to_op(riakc_set:add_element(<<"Y">>, riakc_set:new()))),
1012+
?assertMatch({ok, _K}, Res1),
1013+
?assertMatch({ok, _K}, Res2),
1014+
{ok, K1} = Res1,
1015+
{ok, K2} = Res2,
1016+
?assertMatch(true, is_binary(K1)),
1017+
?assertMatch(true, is_binary(K2)),
1018+
% Make sure the same key isn't generated twice
1019+
?assert(Res1 =/= Res2)
1020+
end)},
10021021
{"trivial set delete",
10031022
?_test(begin
10041023
riakc_test_utils:reset_riak(),

0 commit comments

Comments
 (0)