Installing a custom hash function

Simon Fell sfell at
Fri Apr 26 12:58:49 EDT 2013

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.

From: Olav Frengstad [olav at]
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 <sfell at<mailto:sfell at>>
I'm following the instructions at 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


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)

-export([extract_id/1, kv_hash_fun/1]).

extract_id(Key) ->
        case binary:match(Key,<<",">>) of
                {Pos, 1} -> binary:part(Key, 0, Pos);
                _ -> Key

kv_hash_fun({Bucket,Key}) ->
        chash:key_of({Bucket, extract_id(Key)}).

This is with riak 1.2.0 on Unbuntu.

riak-users mailing list
riak-users at<mailto:riak-users at>

Med Vennlig Hilsen
Olav Frengstad

Systemutvikler // FWT
+47 920 42 090

More information about the riak-users mailing list