Hi Geoff, Looks like the WM endpoint isn't handling that crash well.
As for your precommit hook, the hook runs inside the server context so you'll need to use the riak_object module instead. riakc_obj is a cut-down version for use in the Erlang client. Jon On Tue, Dec 1, 2015 at 11:53 AM Geoff Simonds <[email protected]> wrote: > Good afternoon, > > I am writing to ask for some help regarding a pre-commit hook in Riak > 2.1.1. I am locally running a 5 node Riak dev cluster ( > https://github.com/xing/riak-dev-cluster) on a Mac and am having trouble > with a pre-commit hook. I have added the "add_paths" to my advanced.config: > [ > Riak KV config > {riak_kv, > [ > %% Paths to custom erlang modules. > {add_paths, ["/tmp/ls/custom_modules"]} > ]} > ]. > > and then copied the compiled beam to this directory. I then issued a curl > PUT to add the pre-commit to the bucket props: > > curl -XPUT -H "Content-Type: application/json" -d > '{"props":{"precommit":[{"mod":"rr_pre_commit","fun":"set_process_datetime_index"}]}}' > http://127.0.0.1:11098/buckets/LS\~News/props > > and am able to confirm it worked when I do a GET on the bucket > properties. The bucket already had a single key stored in it and when I do > another PUT on that object (hoping to get the pre-commit to fire), I get > the following error: > > {error,badarg, > [{erlang,iolist_to_binary, > [{hook_crashed, > {rr_pre_commit,set_process_datetime_index,error, > function_clause}}], > []}, > {wrq,append_to_response_body,2,[{file,"src/wrq.erl"},{line,215}]}, > {riak_kv_wm_object,handle_common_error,3, > [{file,"src/riak_kv_wm_object.erl"},{line,1178}]}, > {webmachine_resource,resource_call,3, > [{file,"src/webmachine_resource.erl"},{line,186}]}, > {webmachine_resource,do,3, > [{file,"src/webmachine_resource.erl"},{line,142}]}, > {webmachine_decision_core,resource_call,1, > [{file,"src/webmachine_decision_core.erl"},{line,48}]}, > {webmachine_decision_core,accept_helper,1, > [{file,"src/webmachine_decision_core.erl"},{line,616}]}, > {webmachine_decision_core,decision,1, > [{file,"src/webmachine_decision_core.erl"},{line,521}]}]}} > > > I am able to run the pre-commit function when I attach to the Riak shell and > add the paths manually (code:add_patha) but not when it triggers via a PUT. > Also, in my pre-commit hook module/function I am using the riak erlang client > to access the object metadata. Is this module compiled into Riak or do I > also need to add a path for this? > > > The pre-commit module/function is below: > > > set_process_datetime_index(Obj) -> > case is_deleted(Obj) of > true -> > Obj; > _ -> > MD = riakc_obj:get_update_metadata(Obj), > case riakc_obj:get_user_metadata_entry(MD, > <<"process_messagedate">>) of > %% if user "process messagedate" metadata is not found > notfound -> > %% add it > MD2 = > riakc_obj:set_user_metadata_entry(MD,{<<"process_messagedate">>,format_date_index(calendar:local_time())}), > %% and modify the message_date 2i index > MD3 = riakc_obj:set_secondary_index(MD2,{{binary_index, > <<"messagedate">>}, [format_date_index(calendar:local_time())]}), > riakc_obj:update_metadata(Obj,MD3); > _ -> > %% otherwise, don't do anything as we have already stored the > process time > Obj > end > > end. > > is_deleted(Obj)-> > case dict:find(<<"X-Riak-Deleted">>,riakc_obj:get_metadata(Obj)) of > {ok,_} -> > true; > _ -> > false > end. > > > Any help or advice is appreciated. > > > Geoff > > _______________________________________________ > riak-users mailing list > [email protected] > http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com >
_______________________________________________ riak-users mailing list [email protected] http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
