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)