Thanks, yes, using the console to do something that uses the module let it 
work. Although that's going to be a pain as far as automated deployment goes.

Cheers
Simon
________________________________________
From: Olav Frengstad [[email protected]]
Sent: Thursday, April 25, 2013 5:24 AM
To: Simon Fell
Cc: riak-users Users
Subject: Re: Installing a custom hash function

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 <[email protected]<mailto:[email protected]>>
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
[email protected]<mailto:[email protected]>
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com



--
Med Vennlig Hilsen
Olav Frengstad

Systemutvikler // FWT
+47 920 42 090

_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to