Tuesday, October 13, 2009

Riak on my Ubuntu

[EDIT] The situation with README being out of sync is already fixed. That was fast! Actually after all fixes in README the only bump on the road is to install a correct Erlang version. After that, clone, make, edit config/riak-demo.erlenv and start go very smoothly. Please disregard all "fighting" an "lying" below. It was actual just for me.[EDIT]

I wanted to install and launch Riak on my Ubuntu 9.04.
It did not work out first: my conveniently apt-get-installed Erlang 5.6.4 happened to be incompatible with Riak, so I needed the latest Erlang.

There is also a minor README issue, which is easily remediated below. I hope by the time you will read this that one will be fixed. But the routine I found works with current version OK anyway.

So, the terribly convenient packager sudo apt-get install erlang does not yet install the newer Erlang 5.7.3, so I had to compile the latest otp_src_R13B02-1.tar.gz myself.

Here is the sequence which led me to success:

0. sudo apt-get remove erlang
>> that depends on your installation. In my case I also needed
>> 0.1 sudo apt-get clean
>> 0.2 sudo apt-get remove erlang-base
1. sudo apt-get install build-essential libncurses5-dev m4
2. sudo apt-get install openssl libssl-dev
3. tar -zxf otp_src_R13B02-1.tar.gz
4. cd otp_src_R13B02-1
5. ./configure
6. make
7. sudo make install

Now if you are lucky, you have the right version of Erlang:
serge@ubuntu:~$ erl
Erlang R13B02 (erts-5.7.3) [source] [rq:1] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.7.3 (abort with ^G)
Now we have to fight with Riak documentation, which is out of sync with Riak too. It seems to be the good sign: real hackers never write documentation! (c) some classics...

Actually, I have to credit this team with a bunch of nice intros and comments:
  1. the demo,
  2. the big one of course,
  3. the docs in the distro - my favorite,
  4. the very cool movie presentation from NYC NOSQL '09
  5. For those (including me) who keep thinking what in the wind is going on here - a bit of theory is a great help.

Here it goes. First, we will replace $RIAK with the path-to-riak in the config/riak-demo.erlenv: line 11 in there will look like
{riak_heart_command, "(cd /home/serge/src/riak; ./start-restart.sh /home/serge/src/riak/config/riak-demo.erlenv)"}.

Now we are ready to launch Riak
./start-fresh.sh config/riak-demo.erlenv

Nothing happens. Riak is supposed to work in the backround now.
Is it?

serge@ubuntu:~/src/riak$ ./start-fresh.sh config/riak-demo.erlenv
Attempting to connect to 'riakdemo@' with cookie riak_demo_cookie...
Connected successfully
Looking for pre-existing object at {<<"riak_demo">>, <<"demo">>}...
Pre-existing object found, modifying
Storing object with new value...
Written successfully
Fetching object at {<<"riak_demo">>, <<"demo">>}...
Fetched successfully
Object contained correct value
"SUCCESS" looks like success!

Now there is the point where README is [EDIT] no longer! [/EDIT] "lying", so we will do the right thing on our own:
serge@ubuntu:~/src/riak$ erl -name riaktest@ -pa ebin -setcookie riak_demo_cookie
Erlang R13B02 (erts-5.7.3) [source] [rq:1] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.7.3 (abort with ^G)
(riaktest@> net_adm:ping('riakdemo@').

So far so good, the Riak node is found. Let's work with it:

(riaktest@> {ok,C}=riak:client_connect('riakdemo@').
Now the README doc is good to go with again:

(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).
(riaktest@> C:list_keys(<<"groceries">>).

Now Riak is really ready for experiments.


Justin Sheehy said...

real hackers never write documentation!

Actually, I think there's a bunch of decent documentation there; while it could get better, Riak is not undocumented by any stretch of the imagination.

However, the people that already use a system everyday are less likely than a beginner to notice that a README has become out of sync with the software - thanks for helping out with that!

It has been fixed.

Serge said...

Justin, you are right. I admit - my attempt at humor was ambiguous to say the least. I will fix it too right here and right away. The good news: there are just two of us reading this :)