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.

Tuesday, October 6, 2009

WebCandy RESTs on WebMachine.

The previous post was about merge of the StickyNotes app with WebMachine. The release 0.1 was deployed on BitBucket

That was the "don't touch anything" approach. The solution was elegant, but the data flow mechanisms were all hidden by the POST.

  • In the release 0.2 the create, update, delete, read operations were made explicit through the HTTP POST, PUT, DELETE and GET which potentially allows the web server to cache the data and reduce the load.
  • The home page allows you to check / turn on / turn off / view the WebMachine TRACE without any extra coding. All functionality is already supplied in the admin resource.
  • The JQuery was extended for PUT and DELETE in the application.js - some say that the next JQuery release will have it all. Anyway, it was pretty straitforward copy/paste.
  • The notes.erl was slightly edited for the read method to put the data structure inline with the other access methods.

The release 0.2 code with pre-compiled binaries is platform-independent and ready to run. You have to install Erlang/OTP first.
After downloading and unpacking the zip, use the start.sh (or start.cmd on Windows) and point your browser to