Thursday, April 01, 2010

Riak, thoughts on Erlang based client

I compiled Riak and started it, couple of times I tried with documented hello world like example but this time I wanted to separate Riak DB server from Erlang client. Riak is notoriously bad for omitting how to guides -- this also helps early adapter to delve deeply to understand and hence good for devs at the end. I really need to thank Joe Armstrong for pointing to Riak as it is not visible few months back.

1. Riak's default cookie name is "riak" and it can be verified by "ps -ef | grep riak" or rel/etc/vm.args file has cookie properties, here it can be changed to match Erlang client
2. I copied few files from cp <>/riak/apps/riak or luke/ebin to my working directory to check dependent module to work with and found

    1. luke.beam
    2. luke_flow.beam
    3. luke_flow_sup.beam
    4. riak.beam
    5. riak_client.beam
    6. riak_core_util.beam
    7. riak_kv_map_phase.beam
    8. riak_kv_mapred_query.beam
    9. riak_kv_util.beam
    10. riak_object.beam
    11. vclock.beam
                        are necessary to talk to Riak using Erlang application
                        3. Once grap hold of those files and node at which Riak server is running with cookie which Riak uses -- Erlang can talk to Riak period.
                        4. Now the steps detailed in the README (Riak's) is working fine for me. Assuming you are the directory where the above 5 files are available (or include that dir in erl path (-pa))
                        I just copied sample code from README file below and io output is omitted for brevity.
                        prompt> erl -name riaktest@ -setcookie riak
                        (riaktest@> RiakNode = 'riak@'.
                        (riaktest@> net_adm:ping(RiakNode).
                        (riaktest@> {ok, C} = riak:client_connect(RiakNode).
                        (riaktest@> O0 = riak_object:new(<<"groceries">>, <<"mine">>, ["bread"]).
                        (riaktest@> C:put(O0, 1).
                        (riaktest@> {ok, O1} = C:get(<<"groceries">>, <<"mine">>, 1).
                        (riaktest@> V = riak_object:get_value(O1).
                        (riaktest@> O2 = riak_object:update_value(O1, ["milk" | V]).
                        (riaktest@> C:put(O2, 1).

                        I am not sure only these files are enough, but probably not! there are modules for certain kind of map reduce available in Riak, so if you plan to use those builtins you may need to copy them as well.

                        No comments:

                        Post a Comment

                        Thanks for reading and welcome for commenting...