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)
1>
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...

[EDIT]
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.
[/EDIT]

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@127.0.0.1' 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
"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@127.0.0.1 -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@127.0.0.1)1> net_adm:ping('riakdemo@127.0.0.1').
pong

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

(riaktest@127.0.0.1)6> {ok,C}=riak:client_connect('riakdemo@127.0.0.1').
{ok,{riak_client,'riakdemo@127.0.0.1',
<<"20091014003214-riaktest@127.0.0.1-riakdemo@127.0.0.1-13736">>}}
Now the README doc is good to go with again:

(riaktest@127.0.0.1)6> O0 = riak_object:new(<<"groceries">>, <<"mine">>, ["bread"]).
{r_object,<<"groceries">>,<<"mine">>,
[{r_content,{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},
{{[],[],[],[],[],[],[],[],[],[],[],[],...}}},
["bread"]}],
[],
{dict,1,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],...}}},
undefined}
(riaktest@127.0.0.1)7> C:put(O0, 1).
ok
(riaktest@127.0.0.1)8> {ok, O1} = C:get(<<"groceries">>, <<"mine">>, 1).
{ok,{r_object,<<"groceries">>,<<"mine">>,
[{r_content,{dict,2,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],...},
{{[],[],[],[],[],[],[],[],[],[],...}}},
["bread"]}],
[{<<"20091014003214-riaktest@127.0.0.1-riakdemo@127.0.0.1-13736">>,
{1,63422699573}}],
{dict,1,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],...},
{{[],[],[],[],[],[],[],[],[],[],[],...}}},
undefined}}
(riaktest@127.0.0.1)9> V = riak_object:get_value(O1).
["bread"]
(riaktest@127.0.0.1)10> O2 = riak_object:update_value(O1, ["milk"|V]).
{r_object,<<"groceries">>,<<"mine">>,
[{r_content,{dict,2,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},
{{[],[],[],[],[],[],[],[],[],[],[[...]],[],...}}},
["bread"]}],
[{<<"20091014003214-riaktest@127.0.0.1-riakdemo@127.0.0.1-13736">>,
{1,63422699573}}],
{dict,1,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],...}}},
["milk","bread"]}
(riaktest@127.0.0.1)11> C:put(O2, 1).
ok
(riaktest@127.0.0.1)12> C:list_keys(<<"groceries">>).
{ok,[<<"mine">>]}
(riaktest@127.0.0.1)13>

Now Riak is really ready for experiments.

2 comments:

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 :)