0

The answer in this post about using riak_kv_crdt shows how to extract counters. I can't locate riak_kv_crdt library api documentation. How would one extract the CRDTs such as map from a bucket object in version 2.1.4?

I checked riakc_pb but couldn't figure out from the documentation if there is any API to extract map from a bucket object. Will appreciate pointers on how to deal with riak data types using erlang code.

In the commit hooks that I am planning to write, I plan to use map datatype to create immutable log append to keep track of user info, and use post-commit hook to update another mutable map, say latest_info to point to latest log for that user. So, I need to be able to extract map from the object, and look at the contents before copying them.

Update

Following Joe's tips in comments, I tried to do map_value on a bucket object containing map but got errors below:

Let us first verify that the object has a map.

> riakc_obj:get_content_type(O1).
"application/riak_map"

Now, let us try to get the map:

> riak_kv_crdt:map_value(O1). 

** exception error: no function clause matching 
                    riak_object:get_contents({riakc_obj,
                                              {<<"test_map">>,<<"uinfo_log">>},
                                              <<"ahmed_info_1">>,
                                              <<107,206,97,96,96,96,204,96,202,5,82,60,7,47,197,115,
                                                158,125,191,80,29,34,148,200,...>>,
                                              [{{dict,3,16,16,8,80,48,
                                                 {[],[],[],[],[],[],[],[],[],[],[],[],[],...},
                                                 {{[],[],[],[],[],[],[],[],[],[],[...],...}}},
                                                <<69,2,0,0,0,11,114,105,97,107,95,100,116,95,109,97,
                                                  112,77,2,131,...>>}],
                                              undefined,undefined}) (src/riak_object.erl, line 595)
     in function  riak_kv_crdt:merge_object/1 (src/riak_kv_crdt.erl, line 186)
     in call from riak_kv_crdt:value/2 (src/riak_kv_crdt.erl, line 98)
     in call from riak_kv_crdt:map_value/1 (src/riak_kv_crdt.erl, line 140)
Community
  • 1
  • 1
Sal
  • 4,312
  • 1
  • 17
  • 26
  • I don't know of any documentation, but you should be able to get the map from the riak object with riak_kv_crdt:map_value/1, and then use the [riak_dt_map](https://github.com/basho/riak_dt/blob/develop/src/riak_dt_map.erl) module to work with it – Joe Apr 29 '16 at 04:59
  • @Joe, I just tried your suggestion but got an error. I have added `update` section in my question with the error details. Will appreciate pointers on resolving it. – Sal Apr 29 '16 at 11:33
  • @Joe, figured out what the error is - there seems to be type difference between riakc_obj and riak_object which caused the above error. For riakc_obj, is there another way to get the map out? – Sal Apr 29 '16 at 15:23
  • riakc_obj only exists on the client side, if you are writing a commit hook, you will be working with r_object. – Joe Apr 30 '16 at 01:42

0 Answers0