Getting started with Scalaris
Dave Bryson - daveb - July 26, 2008After 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.
Categories: Blogs Dave Bryson
Comments
No comments so far, you could be the first.Add comment
Erlang on Twitter
» rianindahinyonk (Rian Indah Syafitri): RT @fathiaamandaaa: RT @indrasan: selamat ulang tahun saudara reza erlang @rezasur semoga makin banyak proyek nya ya.
» ericmoritz (Eric Moritz): RT @Burbass: I can now control my Mindstorm Lego car with Erlang. #erlang #mindstorm http://t.co/Jn78yViH
» dalnefre (Dale Schumacher): RT @Burbass: I can now control my Mindstorm Lego car with Erlang. #erlang #mindstorm http://t.co/Jn78yViH
» Erlang_ABNIC (Erlangga .A): “Dream, Believe, and Make it Happen”. ☺ RT @cjerikho829: “Believe”
» aidilnasution (M Aidil Nasution): RT @fathiaamandaaa: RT @indrasan: selamat ulang tahun saudara reza erlang @rezasur semoga makin banyak proyek nya ya.
» indytertuing (indy hamid): ƪ(^ヮ^)ʃ RT @fathiaamandaaa: RT @indrasan: selamat ulang tahun saudara reza erlang @rezasur semoga makin banyak proyek nya ya.
» rvirding (Robert Virding): RT @Burbass: I can now control my Mindstorm Lego car with Erlang. #erlang #mindstorm http://t.co/Jn78yViH
» pikuseru (Dave Birdsall): @mho105 I bought an O’Reilly book about Clojure, a language for the JVM. Bought Scala and Erlang books over a year ago. Just interesting.
» maxmurphy (Max Murphy): @mdesjardins LOL, erlang might fix something….but not that
» mdesjardins (Mike Desjardins): @maxmurphy running city eats on erlang?
Statistics
Number of aggregated posts: 10503
Number of comments: 2135
Most recent article: May 21, 2012
Latest comments
» DRS786 on 25 May 2012: Poznan Erlang User Group Event: I’m going!
» the tantric way in london on TextOne HD for webOS: Interesting articles are published here. By reading it I acquired great deal of knowledge on various subject. Thank you for…
» israeli jewelry on 08 February 2012: Erlang Express 3-day Course in San Francisco on 8 February: It is a wonderful blog. It helps me out a lot. Thank you. I really need help in development and…