Hi Sanket - I'd like to confirm some details. Is this a one-node cluster? Did you install an official package or build from source?
Thanks - -- Luke Bakken Engineer lbak...@basho.com On Tue, May 10, 2016 at 6:49 PM, Sanket Agrawal <sanket.agra...@gmail.com> wrote: > One more thing - I set up the hooks by bucket, not bucket type. The > documentation for 2.1.4 says that hooks are defined on the bucket level. > Here is how I set up precommit hook (derived from "Riak Handbook" p95): > > curl -X PUT localhost:8098/types/test_kv_wo/buckets/uuid_log/props -H > 'Content-Type: application/json' -d '{ "props": { "precommit": [{"mod": > "precommit", "fun": "pre_uuid"}]}}' -v > > > On Tue, May 10, 2016 at 9:15 PM, Sanket Agrawal <sanket.agra...@gmail.com> > wrote: >> >> I just set up a precommit hook function in dev environment (KV 2.1.4) >> which doesn't seem to be triggering off at all. The object is being stored >> in the bucket, but the precommit logic is not kicking off. I checked couple >> of things as listed below but came up with no error - so, it is a >> head-scratcher why precommit hook is not triggering: >>> >>> - Verify precommit is set in bucket properties - snippet from curl query >>> for bucket props below: >>> "precommit":[{"mod":"precommit","fun":"pre_uuid"}] >>> >>> - check there is no error in logs >>> >>> - check riak-console for commit errors: >>> $ ./riak1/bin/riak-admin status|grep commit >>> postcommit_fail : 0 >>> precommit_fail : 0 >>> >>> - Run the precommit function manually on Riak console itself with a riak >>> object (that the hook failed to trigger on), and verify it works >> >> >> >> Also, there is no sasl-error.log. "sasl = on" doesn't work in 2.1.4 >> because it fails with bad_config error. So, I am assuming sasl logging is >> enabled by default. >> >> Here is what precommit function does: >> - For the object (an immutable log append of JSON), calculate the location >> of a LWW bucket, and update a easily calculated key with that JSON body. It >> works fine from Riak console itself. Code below - we call pre_uuid in >> precommit hook - both precommit.beam (where the function is) and rutils.beam >> have been copied to the relevant location as set in riak config, are >> accessible through Riak console and work fine if manually executed on an >> object: >> >>> %% Preprocess JSON, and copy to a LWW bucket type >>> preprocessJ(RObj,B,Choplen) -> >>> Bn = {rutils:calcBLWWType(RObj),B}, %%this returns the location of LWW >>> bucket - works fine in riak console >>> %% We store uuid map in <username> key - we take out timestamp of >>> length 32 including "_" >>> K = riak_object:key(RObj), >>> Kn = binary:part(K,0,byte_size(K) - Choplen), >>> NObj = >>> riak_object:new(Bn,Kn,riak_object:get_value(RObj),riak_object:get_metadata(RObj)), >>> {ok, C} = riak:local_client(), >>> case C:put(NObj) of >>> ok -> RObj; >>> _ -> {fail,<<"Error when trying to process in precommit hook">>} >>> end. >>> >>> pre_uuid(RObj) -> preprocessJ(RObj,<<"uuid_latest">>,32). >> >> >> Below is a manual execution from riak console of precommit function - >> first we execute it to confirm it is returning the original object: >>> >>> (riak1@127.0.0.1)5> precommit:pre_uuid(O1). >>> {r_object,{<<"test_kv_wo">>,<<"uuid_log">>}, >>> <<"ahmed_2016-05-10T20%3a47%3a47.346299Z">>, >>> [{r_content,{dict,3,16,16,8,80,48, >>> >>> {[],[],[],[],[],[],[],[],[],[],[],[],[],[],...}, >>> >>> {{[],[],[],[],[],[],[],[],[],[],[[...]|...],[],...}}}, >>> >>> <<"{\"uname\":\"ahmed\",\"uuid\":\"df8c10e0-381d-5f65-bf43-cb8b4cb806fc\",\"timestamp\":\"2016-05-"...>>}], >>> [{<<0>>,{1,63630132467}}], >>> {dict,1,16,16,8,80,48, >>> {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],...}, >>> {{[],[],[],[],[],[],[],[],[],[],[],[],[],...}}}, >>> undefined} >> >> >> Now, we check if the object has been written to test_lww/uuid_latest >> bucket type: >>> >>> (riak1@127.0.0.1)6> >>> C:get({<<"test_lww">>,<<"uuid_latest">>},<<"ahmed">>). >>> >>> {ok,{r_object,{<<"hnm_fsm_lww">>,<<"uuid_latest">>}, >>> <<"ahmed">>, >>> [{r_content,{dict,4,16,16,8,80,48, >>> >>> {[],[],[],[],[],[],[],[],[],[],[],[],...}, >>> {{[],[],[],[],[],[],[],[],[],[],...}}}, >>> >>> <<"{\"uname\":\"ahmed\",\"uuid\":\"df8c10e0-381d-5f65-bf43-cb8b4cb806fc\",\"timestamp\":\""...>>}], >>> [{<<153,190,230,200,210,126,212,127,0,0,156,65>>, >>> {1,63630148036}}], >>> {dict,1,16,16,8,80,48, >>> {[],[],[],[],[],[],[],[],[],[],[],[],[],...}, >>> {{[],[],[],[],[],[],[],[],[],[],[],...}}}, >>> undefined}} >> >> >> Will appreciate pointer on how to debug precommit hook. > > > > _______________________________________________ > riak-users mailing list > riak-users@lists.basho.com > http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com > _______________________________________________ riak-users mailing list riak-users@lists.basho.com http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com