Installing a custom hash function

Olav Frengstad olav at fwt.no
Thu Apr 25 08:24:57 EDT 2013


Hey Simon,

The badarg exception means that it can't convert your string to an atom
because the 'sfdc_hash' atom is not previously used.
Most likely this is because your .beam file is in the path but not loaded,
meaning list_to_existing_binary/1 will until you load the file in an
alternative way.

I'm not sure how the "{add_paths, _}" config setting works, but assuming it
just wraps around the code module you can try to attach to the riak console
and run "code:ensure_loaded(sfdc_hash)." and try to update the bucket props
again.


2013/4/24 Simon Fell <sfell at salesforce.com>

> I'm following the instructions at
> http://docs.basho.com/riak/1.2.0/cookbooks/Erlang-Named-Functions/ to
> setup a custom hash function, how safe or not is it to assume its the same
> process ?
>
> Currently when i try and PUT the bucket config to specify the new function
> i get back
>
> {error,badarg,
>         [{erlang,list_to_existing_atom,["sfdc_hash"],[]},
>          {riak_kv_wm_props,erlify_bucket_prop,1,
>              [{file,"src/riak_kv_wm_props.erl"},{line,304}]},
>          {lists,map,2,[{file,"lists.erl"},{line,1173}]},
>          {riak_kv_wm_props,accept_bucket_body,2,
>              [{file,"src/riak_kv_wm_props.erl"},{line,201}]},
>          {webmachine_resource,resource_call,3,
>              [{file,"src/webmachine_resource.erl"},{line,169}]},
>          {webmachine_resource,do,3,
>              [{file,"src/webmachine_resource.erl"},{line,128}]},
>          {webmachine_decision_core,resource_call,1,
>              [{file,"src/webmachine_decision_core.erl"},{line,48}]},
>          {webmachine_decision_core,accept_helper,0,
>
> My .beam file is in /tmp/riak_fun, and i added {add_paths,
> ["/tmp/riak_fun"]}, to the riak_kv section in the app.config, and the .beam
> file is world readable.
>
> I'm running this to set the properties
> curl -v --data-binary @props.json -H Content-Type:application/json
> http://riak1.local:8098/riak/ex -X PUT
>
> props.json contains
> {"props": { "chash_keyfun":{"mod":"sfdc_hash","fun":"kv_hash_fun"} } }
>
> Is there a more detailed log somewhere? is there an easy way to see if
> riak can actually load my .beam file?
>
> the source for the module is very straighforward (we just want to hash on
> part of the key)
>
> -module(sfdc_hash).
> -export([extract_id/1, kv_hash_fun/1]).
>
> extract_id(Key) ->
>         case binary:match(Key,<<",">>) of
>                 {Pos, 1} -> binary:part(Key, 0, Pos);
>                 _ -> Key
>         end.
>
> kv_hash_fun({Bucket,Key}) ->
>         chash:key_of({Bucket, extract_id(Key)}).
>
> This is with riak 1.2.0 on Unbuntu.
>
> Thanks
> Simon
> _______________________________________________
> riak-users mailing list
> riak-users at lists.basho.com
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
>



-- 
Med Vennlig Hilsen
Olav Frengstad

Systemutvikler // FWT
+47 920 42 090
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20130425/210a8c27/attachment.html>


More information about the riak-users mailing list