erlang precommit hook error

Hal Eisen eisen at dunhackin.org
Tue Nov 8 13:01:26 EST 2011


Sorry, typo in code.  the mangle function is actually:

mangle(X) ->
    crypto:start(),
    {_, Tokens} = lists:partition(fun(Arg) -> lists:member(Arg, mangle:stopwords()) end, string:tokens(riak_object:get_value(X), " ")),
    riak_object:update_value(X, lists:flatten(lists:map(fun(Arg) -> crypto:md5(Arg) end, Tokens))),
    riak_object:apply_updates(X).

In other words, I fixed the module reference.

Hal

On Tue, Nov 08, 2011 at 09:59:26AM -0800, Hal Eisen wrote:
> Hello again.  I have given up on using the JavaScript precommit hook
> because I could not find anything which did not produce timeouts under
> the load for my application.
> 
> So, I have ported my hook to Erlang.  Alas, I'm not getting very far.
> I've installed my hook in /etc/riak/erl/hooks.erl.  The code looks
> like this:
> 
> -module(haleisen).
> -export([stopwords/0, mangle/1]).
> stopwords() ->
> ["a","able","about","across","after","all","almost","also","am","among","an","and","any","are","as","at","be","because","been","but","by","can","cannot","could","dear","did","do","does","either","else","ever","every","for","from","get","got","had","has","have","he","her","hers","him","his","how","however","i","if","in","into","is","it","its","just","least","let","like","likely","may","me","might","most","must","my","neither","no","nor","not","of","off","often","on","only","or","other","our","own","rather","said","say","says","she","should","since","so","some","than","that","the","their","them","then","there","these","they","this","tis","to","too","twas","us","wants","was","we","were","what","when","where","which","while","who","whom","why","will","with","would","yet","you","your"].
> mangle(X) ->
>     crypto:start(),
>     {_, Tokens} = lists:partition(fun(Arg) -> lists:member(Arg, ask:stopwords()) end, string:tokens(riak_object:get_value(X), " ")),
>     riak_object:update_value(X, lists:flatten(lists:map(fun(Arg) -> crypto:md5(Arg) end, Tokens))),
>     riak_object:apply_updates(X).
> 
> I originally tested the code in the Erlang repl, using a plain string
> instead of riak_object:get_value, and it worked perfectly.
> 
> I installed my hook into a test bucket:
> bash$ curl http://127.0.0.1:8098/riak/test-hook
> {"props":{"allow_mult":false,"basic_quorum":false,"big_vclock":50,"chash_keyfun":{"mod":"riak_core_util","fun":"chash_std_keyfun"},"dw":"quorum","last_write_wins":false,"linkfun":{"mod":"riak_kv_wm_link_walker","fun":"mapreduce_linkfun"},"n_val":3,"name":"test-with","notfound_ok":true,"old_vclock":86400,"postcommit":[],"pr":0,"precommit":[{"mod":"haleisen","fun":"mangle"}],"pw":0,"r":"quorum","rw":"quorum","small_vclock":10,"w":"quorum","young_vclock":20}}
> 
> When I try to insert a key into this bucket, I get:
> Error:
> {precommit_fail,{hook_crashed,{haleisen,mangle,error,undef}}}
> 
> Any help would be appreciated.
> 
> Thanks,
> Hal




More information about the riak-users mailing list