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.

                        Riak a super scale datastore

                        I started looking into Riak lately to see how it can fit into my application which is currently using CouchDb. I really like CouchDb for
                        1. Map Reduce view -- just throw some mr function you will find out the document which it preserved
                        2. Web UI (the futon) it alleviate lot of Admin pages along with lately added security is good enough to manage it
                        3. Hot data backup, it is an excellent feature and makes like easier

                        1. Mindset of treating CouchDb as all in all self contained product and hence lacks native interface, (there are APIs but it is based on http -- even http world is moving to websocket due to its inherent limitation for certain usecases, having Database served by http to another middleware is costly and environmentally hazardous like gas guzzling trucks
                        2. lack of native search (full text) but there is a lucene based one but already couchdb is dependent on JS, Erlang, ICU and having Java into the fold is kind of nightmare to the mix but it works and also gives head ache when replicating and spinning multiple nodes
                        3. It is not truly distributed but it is kind of storage engine which can be equated to better dets storage engine or innostore but there is nothing similar in couch architecture to be comparable with Cassandra or Riak.