I've been taking a look at how riakc_obj is used in the erlang PBC client after the issue of updating metadata was brought up by Mikl Kurkov a few weeks ago.

The typical use case for the library is to get some data from the server, and then sometimes modify it/write it back again. With the current riakc_obj you have to set both the metadata and the value for update or data will be lost. I've changed the library so that if there are no siblings, updating the value or the metadata will leave the other intact. If there are siblings you can base the result on one of them using the new riakc_obj:select_sibling/2 call. The library also throws descriptive atoms rather than badmatch when you try and use calls that only work for objects without siblings.

Here's an example of updating links under the new API (before you would have had to add an additional step of retrieving the value from O1 and re-setting it in O2).

                 {ok, Pid} = start_link(Ip, Port),
                 O0 = riakc_obj:new(<<"b">>, <<"k">>, <<"d">>),
                 {ok, O1} = riakc_pb_socket:put(Pid, O0, [return_body]),
                 M1 = riakc_obj:get_metadata(O1),
M2 = dict:store(?MD_LINKS, [{{<<"b">>, <<"k1">>}, <<"t1">>}], M1),
                 O2 = riakc_obj:update_metadata(O1, M2),
                 riakc_pb_socket:put(Pid, O2)

I plan to push the changes into the main repo in a few days. To give people a chance to play with them ahead of time I've forked the repo here

   http://bitbucket.org/jon_meredith/riak-erlang-client-updobj

Let me know if anybody has concerns/feedback about the change.

--Jon.

_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to