Getting started with Scalaris

July 25, 2008

After installing Scalaris earlier today, I couldn’t help but jump into the code to see how things work. The users guide shows how to use the Java API and there are some nice examples. But as far as Erlang goes, I couldn’t find any information. Fortunately there are a few unit tests that provided the clues I needed.

Using the Transaction API

First you need to start Scalaris on a few nodes. See “bin/boot.sh” and the “cd_local” scripts. The README describes this. From within one of the erl shells you created with a “cs_local” script you can explore the API. Really pretty easy (and fast):

 %% Write a key
 > transstore.transaction_api:single_write("name", "dave").

 %% Read it back
 > {Value, Version} = transstore.transaction_api:quorum_read("name").
 > Value.
"dave"
> Version.
0

If you write the same key again, the version field will automatically increment. And you can store Erlang structures as the value if you’re looking to store more complicated data. But I couldn’t find a way to remove a key, so I’m not sure if a “delete” exists right now.

A PubSub API !

Digging around I also found a PubSub API that looks pretty interesting. However, it’s appears fixed on a specific goal: JSONRPC to a URL using the jsonrpc in yaws.

Basically you can subscribe to a Topic (Key) with a callback to a URL (Value). The URL must know how to handle the jsonrpc request because the underlying api will send the request to the page on a publish. See this Yaws JSONRPC for more info. Here’s how it appears to work:

%% Subscribe to the topic "ErlangNews". Publish events to the URL.
> pubsub.pubsub_api:subscribe("ErlangNews", "http://localhost:8000/news.yaws").

%% Get the subscibers to the topic
> pubsub.pubsub_api:get_subscribers("ErlangNews").
["http://localhost:8000/news.yaws"]

%% Publish some news...
> pubsub.pubsub_api:publish("ErlangNews", "Welcome to Erlang!").

Underneath the covers, the publish method attempts to make a jsonrpc call on the method “notify” to the URL. Even with this specific goal of JSONRPC it doesn’t look like it would be to difficult to create your own custom implementation - maybe a web based chat system might be interesting…

Rethinking the database

After all these years of using relational databases, my brain is locked in to their structured approach. Having only key value pairs to work with seems straight forward. But once I started brainstorming through a few prototypes I realized mapping all the data into Scalaris will take a little thinking.

First Look at Scalaris on OS X 10.5

July 25, 2008

Using ErlyWeb templates with MochiWeb

May 05, 2008

Install Erlang on Ubuntu with Capistrano

May 05, 2008