Monday, 15 February 2010

erlang - dealing with riak datatypes in postcommit hooks -


I want to apply a post-driven hook for a hit which decreases the counter in a map in a bucket. However, I am facing trouble with the rickety datatype.

Trying here with me riak console :

  (riak@127.0.0.1.19) 9 & gt; {OK, C} = Riaq: Local_client () (OK, {riak_client, ['riak @ 127.0.0.1', undefined]}} (riak@127.0.0.1) 10> OK {OK}, =) : Receive ({& lt; & lt; "product">,> << "> default"> gt;>}, <1 ">" 1 "& gt; & Gt;). {OK, {r_object, {& quot; "product"> gt;>   

  • "default"> ; & lt; & lt; 1 "& gt; & gt; [[R_content, {dict, 5,16,16,8, 80,48, {[], [], [], [], [], [], [], [], [], [], [], [], ...}, {{[,], [], [], [], [[& lt; "dot"> gt; & gt; | | <& Lt; & lt; "# \ tþù" ... & gt;>, {...}}, [], [], [], [], [], ... 8} Gt;}], [[Lt 35 9, 254,24 9,108,41,151,242>>, {1,63593788980}}], {dict, 1,1 6, 16,880,48, {[], [], [], [], [], [], [], [], [], [], [], [], [], .. .. , {{[,], [], [], [], [], [], [], [], [], [], [], ...}}}, undefined}} (riak@127.0 .0.1) 11> MP = riak_object: get_value (O3) & lt; 69,2,0,0,0,11,114,105,97,107,95,100,116,95,109,97,112, 77,1,131,80 , 0,0,0,020,206,120,1,203,96, ... & gt; & Gt; (Riak@127.0.0.1) 12 & gt; MpP = riak_dt_map: from_binary (mp3). {Error, invalid_binary}
  • product bucket datatype is set to map . Each object stored must have a counter called quantity , which I would like to subtract.

    However, I can not get a documentation or sample code with data type in the first or post related context. (Actually any kind of examples are some) I am studying the source, but I am new to IrLeng, so I am making slow progress and appreciate some help. You have R_object that there is not a riak_dt_map directly there, but it maintains a riak_kv_crdt, in which one is called riak_dt_map

    To update the counter, you first need to get context from the map:

      {{reference, _}, _} = riak_kv_crdt: value (obj, Riak_dt_map).  

    Then the map contained in the CRDT called & lt; & Lt; Create the name to increase the "name" >> Counter:

      op = {crdt_op, riak_dt_map, {update, [{update, {& lt; & Lt; "Name" & gt; & Gt ;, riak_dt_emcntr}, increment}}}, context}.  

    and then apply that operation to the CRDT, provide the actor ID you want to use to update vclock / version vector:

     < Code> NewObj = riak_kv_crdt: Update (Obj, Actor, Op).  

    The result should be another r_object that is ready to send back for storage.


    No comments:

    Post a Comment