<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <title>The Basho Blog</title>
    <link>http://blog.basho.com</link>
    <description>The Basho Blog</description>
    <pubDate>Wed, 24 Feb 2010 16:07:54 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Link Walking By Example</title>
      <link>http://blog.basho.com/2010/02/24/link-walking-by-example/</link>
      <pubDate>Wed, 24 Feb 2010 11:40:00 EST</pubDate>
      <category><![CDATA[Riak]]></category>
      <category><![CDATA[Links]]></category>
      <guid isPermaLink="true">http://blog.basho.com/2010/02/24/link-walking-by-example/</guid>
      <description>Link Walking By Example</description>
      <content:encoded><![CDATA[

<p>Riak has a notion of &ldquo;links&rdquo; as part of the metadata of its objects.  We talk about traversing, or &ldquo;walking&rdquo;, links, but what do the queries for doing so actually look like?</p>

<p>Let's put four objects in riak:</p>

<table>
<tr>
<td>
<ol>
  <li><code>hb/first</code> will link to <code>hb/second</code> and <code>hb/third</code></li>
  <li><code>hb/second</code> will link to <code>hb/fourth</code></li>
  <li><code>hb/third</code> will also link to <code>hb/fourth</code></li>
  <li><code>hb/fouth</code> doesn't link anywhere</li>
</ol>
</td>
<td>
  <img src="/images/link-walking-by-example.png" />
</td>
</tr>
</table>

<pre class="example">
$ curl -X PUT -H &quot;content-type:text/plain&quot; \
  -H &quot;Link: &lt;/raw/hb/second&gt;; riaktag=\&quot;foo\&quot;, &lt;/raw/hb/third&gt;; riaktag=\&quot;bar\&quot;&quot; \
  http://localhost:8098/raw/hb/first --data &quot;hello&quot;

$ curl -X PUT -H &quot;content-type: text/plain&quot; \
  -H &quot;Link:&lt;/raw/hb/fourth&gt;; riaktag=\&quot;foo\&quot;&quot; \
  http://localhost:8098/raw/hb/second --data &quot;the second&quot;

$ curl -X PUT -H &quot;content-type: text/plain&quot; \
  -H &quot;Link:&lt;/raw/hb/fourth&gt;; riaktag=\&quot;foo\&quot;&quot; \
  http://localhost:8098/raw/hb/third --data &quot;the third&quot;

$ curl -X PUT -H &quot;content-type: text/plain&quot; \
  http://localhost:8098/raw/hb/fourth --data &quot;the fourth&quot;
</pre>

<p>Now, say we wanted to start at <code>hb/first</code>, and follow
all of its outbound links.  The easiest way to do this is with the
link-walker URL syntax:</p>

<pre class="example">
$ curl http://localhost:8098/raw/hb/first/_,_,_
</pre>

<p>The response will be a multipart/mixed body with two parts: the
<code>hb/second</code> object in one, and the hb/third object in the
other:</p>

<pre class="example">
--N2gzGP3AY8wpwdQY0jio62L9nJm
Content-Type: multipart/mixed; boundary=3ai6VRl4aLli3dKw8tG9unUeznT

--3ai6VRl4aLli3dKw8tG9unUeznT
X-Riak-Vclock: a85hYGBgzGDKBVIsTKLLozOYEhnzWBn+H/h5hC8LAA==
Location: /raw/hb/third
Content-Type: text/plain
Link: &lt;/raw/hb&gt;; rel=&quot;up&quot;, &lt;/raw/hb/fourth&gt;; riaktag=&quot;foo&quot;
Etag: 5Fs0VskZWx7Y25tf1oQsvS
Last-Modified: Wed, 24 Feb 2010 15:25:51 GMT

the third
--3ai6VRl4aLli3dKw8tG9unUeznT
X-Riak-Vclock: a85hYGBgzGDKBVIsLEHbN2YwJTLmsTLMPvDzCF8WAA==
Location: /raw/hb/second
Content-Type: text/plain
Link: &lt;/raw/hb&gt;; rel=&quot;up&quot;, &lt;/raw/hb/fourth&gt;; riaktag=&quot;foo&quot;
Etag: 2ZKEJ2gaT57NT7xhLDPCQz
Last-Modified: Wed, 24 Feb 2010 15:24:11 GMT

the second
--3ai6VRl4aLli3dKw8tG9unUeznT--

--N2gzGP3AY8wpwdQY0jio62L9nJm--
</pre>

<p>It's also possible to express the same query in map-reduce,
directly:</p>

<pre class="example">
$ curl -X POST -H &quot;content-type:application/json&quot; \
  http://localhost:8098/mapred --data @-
{&quot;inputs&quot;:[[&quot;hb&quot;,&quot;first&quot;]],&quot;query&quot;:[{&quot;link&quot;:{}},{&quot;map&quot;:{&quot;language&quot;:&quot;javascript&quot;,&quot;source&quot;:&quot;function(v)
{ return [v]; }&quot;}}]}
^D
</pre>

<p>That's the exact same query.  The content type of the response is
different.  It's now a JSON array with two elements: a JSON encoding
of the <code>hb/second</code> object, and a JSON encoding of
the <code>hb/third</code> object. (Pretty-printed here, for
clarity.)</p>

<pre class="example">
[
    {
        &quot;bucket&quot;: &quot;hb&quot;,
        &quot;key&quot;: &quot;second&quot;,
        &quot;vclock&quot;: &quot;a85hYGBgzGDKBVIsLEHbN2YwJTLmsTLMPvDzCF8WAA==&quot;,
        &quot;values&quot;: [
            {
                &quot;metadata&quot;: {
                    &quot;Links&quot;: [
                        [&quot;hb&quot;,&quot;fourth&quot;,&quot;foo&quot;]
                    ],
                    &quot;X-Riak-VTag&quot;: &quot;2ZKEJ2gaT57NT7xhLDPCQz&quot;,
                    &quot;content-type&quot;: &quot;text/plain&quot;,
                    &quot;X-Riak-Last-Modified&quot;: &quot;Wed, 24 Feb 2010 15:24:11 GMT&quot;,
                    &quot;X-Riak-Meta&quot;: []
                },
                &quot;data&quot;: &quot;the second&quot;
            }
        ]
    },
    {
        &quot;bucket&quot;: &quot;hb&quot;,
        &quot;key&quot;: &quot;third&quot;,
        &quot;vclock&quot;: &quot;a85hYGBgzGDKBVIsTKLLozOYEhnzWBn+H/h5hC8LAA==&quot;,
        &quot;values&quot;: [
            {
                &quot;metadata&quot;: {
                    &quot;Links&quot;: [
                        [&quot;hb&quot;,&quot;fourth&quot;,&quot;foo&quot;]
                    ],
                    &quot;X-Riak-VTag&quot;: &quot;5Fs0VskZWx7Y25tf1oQsvS&quot;,
                    &quot;content-type&quot;: &quot;text/plain&quot;,
                    &quot;X-Riak-Last-Modified&quot;: &quot;Wed, 24 Feb 2010 15:25:51 GMT&quot;,
                    &quot;X-Riak-Meta&quot;: []
                },
                &quot;data&quot;: &quot;the third&quot;
            }
        ]
    }
]
</pre>

<p>Another interesting query is &ldquo;follow only links that are tagged
<code>foo</code>.&rdquo; For that, just add a <code>tag</code> field
to the link phase spec:</p>

<pre class="example">
$ curl -X POST -H &quot;content-type:application/json&quot; \
  http://localhost:8098/mapred --data @-
{&quot;inputs&quot;:[[&quot;hb&quot;,&quot;first&quot;]],&quot;query&quot;:[{&quot;link&quot;:{&quot;tag&quot;:&quot;foo&quot;}},{&quot;map&quot;:{&quot;language&quot;:&quot;javascript&quot;,&quot;source&quot;:&quot;function(v)
{ return [v]; }&quot;}}]}
^D
</pre>

<p>Here you should get a JSON array with one element: a JSON encoding
of the <code>hb/second</code> object.  The link to
the <code>hb/third</code> object was tagged <code>bar</code>, so that
link was not followed.  The equivalent URL syntax is:</p>

<pre class="example">
$ curl http://localhost:8098/raw/hb/first/_,foo,_
</pre>

<p>It's also possible to filter links by bucket by adding a
<code>bucket</code> field to the link phase spec, or by replacing the
first underscore with a bucket name in the URL format.  But, all of
our example links point to the same bucket, so
<code>hb</code> is the only interesting setting here.</p>

<p>Link phases may also be chained together (or put after other phases
if those phases produce bucket/key lists).  For example, we could
follow the links all the way from <code>hb/first</code>
to <code>hb/fourth</code> with:</p>

<pre class="example">
$ curl -X POST -H &quot;content-type:application/json&quot; \
  http://localhost:8098/mapred --data @-
{&quot;inputs&quot;:[[&quot;hb&quot;,&quot;first&quot;]],&quot;query&quot;:[{&quot;link&quot;:{}},{&quot;link&quot;:{}},{&quot;map&quot;:{&quot;language&quot;:&quot;javascript&quot;,&quot;source&quot;:&quot;function(v)
{ return [v]; }&quot;}}]}
^D
</pre>

<p>(Notice the added link phase.)  If you run that, you'll find that
you get two copies of the <code>hb/fourth</code> object in the
response.  This is because we didn't bother uniquifying the results of
the link extraction, and both <code>hb/second</code>
and <code>hb/third</code> link to <code>hb/fourth</code>.  A reduce
phase is fairly easy to add:</p>

<pre class="example">
$ curl -X POST -H &quot;content-type:application/json&quot; \
  http://localhost:8098/mapred --data @-
{&quot;inputs&quot;:[[&quot;hb&quot;,&quot;first&quot;]],&quot;query&quot;:[{&quot;link&quot;:{}},{&quot;link&quot;:{}},{&quot;reduce&quot;:{&quot;language&quot;:&quot;erlang&quot;,&quot;module&quot;:&quot;riak_mapreduce&quot;,&quot;function&quot;:&quot;reduce_set_union&quot;}},{&quot;map&quot;:{&quot;language&quot;:&quot;javascript&quot;,&quot;source&quot;:&quot;function(v)
{ return [v]; }&quot;}}]}
^D
</pre>

<p>The resource handling the URL link-walking format does just
this:</p>

<pre class="example">
$ curl http://localhost:8098/raw/hb/first/_,_,_/_,_,_
</pre>

<p>That should get you just one copy of the <code>hb/fourth</code>
object.</p>

<p>So why choose either map/reduce or URL-syntax?  The advantage of URL
syntax is that if you're starting from just one object, and just want
to get the objects at the ends of the links, and you can handle
multipart/mixed encoding, then URL syntax is much simpler and more
compact.  Map/reduce with link phases should be your choice if you
want to start from multiple objects at once, or you want to get some
processed or aggregated form of the objects, or you want the result to
be JSON-encoded.</p>

<p><em>Riak version 0.8 note</em>: In Riak 0.8, the format of the
result of 'link' map/reduce phases was not able to be transformed into
JSON.  This meant both that it was not possible to put a Javascript
reduce phase right after a link phase, and also that it was not
possible to end an HTTP map/reduce query with a link phase.  Those
issues have been resolved in the tip of the source repository, and
will be part of the 0.9 release.</p>

<p><em>Riak version 0.9 note</em>: In Riak 0.9, the URL for Riak's
HTTP interface will change from <code>/raw</code>
to <code>/riak</code>.  You may need to adjust the above examples
accordingly.</p>

<p><a href="http://twitter.com/hobbyist">-Bryan</a></p>
]]></content:encoded>
    </item>
    <item>
      <title>Using Innostore with Riak</title>
      <link>http://blog.basho.com/2010/02/22/using-innostore-with-riak/</link>
      <pubDate>Mon, 22 Feb 2010 11:00:00 EST</pubDate>
      <category><![CDATA[Riak]]></category>
      <category><![CDATA[Erlang]]></category>
      <category><![CDATA[Innostore]]></category>
      <category><![CDATA[Database]]></category>
      <guid isPermaLink="true">http://blog.basho.com/2010/02/22/using-innostore-with-riak/</guid>
      <description>Using Innostore with Riak</description>
      <content:encoded><![CDATA[

<p>Innostore is an Erlang application that provides an API for storing and retrieving key/value data using the InnoDB storage system. This storage system is the same one used by MySQL for reliable, transactional data storage. It&#8217;s a proven, fast system and perfect for use with Riak if you have a large amount of data to store.  Let&#8217;s take a look at how you can use Innostore as a backend for Riak.</p>

<p>(Note: I assume that you have successfully built an instance of Riak for your platform. If you built Riak from source in ~/riak, then set $RIAK to ~/riak/rel/riak.&#8221;)</p>
<p>We first get started by grabbing a stable release of Innostore. You&#8217;ll need to download the source for a release from: <code>http://bitbucket.org/basho/innostore/downloads/</code></p>
<p>Looking in the &#8220;Tags &#038; snapshots&#8221; section, you should download the source for the highest available RELEASE_* tag. In my case, RELEASE_4 is the most recent release, so I&#8217;ll grab the bz2 file associated with it:<br />
<code><br />
http://bitbucket.org/basho/innostore/get/RELEASE_4.tar.bz2<br />

</code></p>
<p>Once I have the source code, it&#8217;s time to unpack it and build:<br />
<code><br />
$ tar -xjf innostore-RELEASE_4.tar.bz2<br />
$ cd innostore<br />
$ make<br />
</code></p>
<p>Depending on the speed of the machine you are building on, this may take a few minutes to complete. At the end, you should see a series of unit tests run, with the output ending:<br />
<code><br />
=======================================================<br />

All 7 tests passed.<br />
100222  7:43:58  InnoDB: Shutdown completed; log sequence number 90283<br />
Cover analysis: /Users/dizzyd/src/public/innostore/.eunit/index.html<br />
</code></p>
<p>Now that we have successfully built Innostore, it&#8217;s time to install it into the Riak distribution:<br />
<code><br />
$ ./rebar install target=$RIAK/lib<br />
</code><br />
If you look in the $RIAK/lib directory now, you should see the innostore-4 directory alongside a bunch of .ez files and other directories which compose the Riak release.</p>

<p>Now, we need to tell Riak to use the Innostore driver as a backend. Make sure Riak is not running. Edit $RIAK/etc/app.config, setting the value for &#8220;storage_backend&#8221; as follows:<br />
<code><br />
{storage_backend, innostore_riak},<br />
</code><br />
In addition, append the configuration for the Innostore application after the SASL section:<br />
<code><br />
{sasl, [ ....<br />
          ]},    %% < -- make sure you add a comma here!!</p>

<p>{innostore, [<br />
             {data_home_dir,            "data/innodb"}, %% Where data files go<br />
             {log_group_home_dir,       "data/innodb"}, %% Where log files go<br />
             {buffer_pool_size,         2147483648}     %% 2G in-memory buffer in bytes<br />
             ]}<br />
</code><br />
You may need to adjust the directories for your data_home_dir and log_group_home_dirs to match where you want the inno data and log files to be stored. If possible, make sure that the data and log dirs are on separate disks -- this can yield much better performance.</p>

<p>Once you've completed the changes to $RIAK/etc/app.config, you're ready to start Riak:<br />
</code><code><br />
$ $RIAK/bin/riak console<br />
</code><br />
As it starts up, you should see messages from Inno that end with something like:</p>
<p>100220 16:36:58  InnoDB: highest supported file format is Barracuda.<br />
100220 16:36:58 Embedded InnoDB 1.0.3.5325 started; log sequence number 45764</p>
<p>That&#8217;s it! You&#8217;re ready to start using Riak for storing truly massive amounts of data.</p>

<p>Enjoy,</p>

<p><a href="http://www.twitter.com/dizzyco">Dave Smith</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Calling all Rubyists - Ripple has Arrived!</title>
      <link>http://blog.basho.com/2010/02/11/calling-all-rubyists---ripple-has-arrived!/</link>
      <pubDate>Thu, 11 Feb 2010 11:30:00 EST</pubDate>
      <category><![CDATA[Riak]]></category>
      <category><![CDATA[Ruby]]></category>
      <category><![CDATA[Map/Reduce]]></category>
      <category><![CDATA[NoSQL]]></category>
      <guid isPermaLink="true">http://blog.basho.com/2010/02/11/calling-all-rubyists---ripple-has-arrived!/</guid>
      <description>Calling all Rubyists - Ripple has Arrived!</description>
      <content:encoded><![CDATA[
<p>The Basho Dev. Team has been very excited about working with the Ruby community for some time. The only problem was we were heads down on <a href="http://basho.com/developers.html">so many other projects</a> that it was hard to make any progress. But, even with all that work on our plate, we were committed to showing some love to Rubyists and their frameworks.</p>
 
<p>Enter <a href="http://twitter.com/seancribbs">Sean Cribbs. </a>As Sean details in his latest blog post, <a href="http://seancribbs.com/tech/2010/02/10/introducing-ripple-0-5-you-got-your-riak-in-my-ruby">"You Got your Riak in my Ruby,"</a> Basho and the stellar team at <a href="http://www.sonian.com/">Sonian</a> made it possible for him to hack on Ripple, a one-of-a-kind client library and object mapper for <a href="http://riak.basho.com">Riak.</a> The full feature set for Ripple can be found on Sean's blog, but highlights include a DataMapper-like API, an easy builder-style interface to Map/Reduce, and near-term integration with Rails 3.</p>

<p>And, in case you need any convincing that you should consider Riak as the primary datastore for your next Rails app, check out Sean's earlier post, <a href="http://seancribbs.com/tech/2010/02/06/why-riak-should-power-your-next-rails-app/">"Why Riak should power your next Rails app."</a></p>

<p>So, if you've read enough and want to get your hands on Ripple, <a href="http://github.com/seancribbs/ripple">go check it out on GitHub.</a></p>

<p>If you don't have Riak downloaded and built yet, <a href="http://bitbucket.org/basho/riak/wiki/Home">get on it.</a></p>

<p>Lastly, you are going to be seeing a lot more Riak in your Ruby. So stay tuned because we have some big plans.</p>

<p>Best,</p>

<a href="http://www.twitter.com/pharkmillups">Mark</p>]]></content:encoded>
    </item>
    <item>
      <title>The Release Riak 0.8 and JavaScript Map/Reduce</title>
      <link>http://blog.basho.com/2010/02/03/the-release-riak-0.8-and-javascript-map/reduce/</link>
      <pubDate>Wed, 03 Feb 2010 16:00:00 EST</pubDate>
      <category><![CDATA[Riak]]></category>
      <category><![CDATA[JavaScript]]></category>
      <category><![CDATA[Map/Reduce]]></category>
      <category><![CDATA[Screencast]]></category>
      <guid isPermaLink="true">http://blog.basho.com/2010/02/03/the-release-riak-0.8-and-javascript-map/reduce/</guid>
      <description>The Release Riak 0.8 and JavaScript Map/Reduce</description>
      <content:encoded><![CDATA[

<p>We are happy to announce the release of Riak 0.8 available for <a href="http://hg.basho.com/riak/downloads/">download</a>
immediately. Riak 0.8 features a number of enhancements to the core map/reduce machinery that will make Riak more accessible to a wider audience. The biggest enhancement is the ability to write map/reduce queries in
JavaScript. We're using our <a href="http://bitbucket.org/basho/erlang_js/">erlang_js</a> project to 
integrate Mozilla's Spidermonkey engine directly into Riak to keep overhead to a minimum.</p>

<p>We've also built a spiffy REST API for submitting map/reduce queries. Queries are described in JSON
and POST-ed to the Riak server. Results are sent back as JSON for your processing pleasure. And, the REST
interface supports streaming results for large result sets, too.</p>

<p>To kick it all off, we've put together a short screencast demonstrating 
how to use Riak's flashy new features. You can watch it below, or <a href="http://vimeo.com/9188550">view it on Vimeo.</a> There's also a slew of bug fixes and optimizations included in
Riak 0.8. See <a href="http://lists.basho.com/pipermail/riak-users_lists.basho.com/2010-February/000387.html">the release notes</a> for all the juicy details.</p>

<p>Download and enjoy!</p>

<p><a href="http://www.twitter.com/kevsmith">Kevin</a><p>



<object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=9188550&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=9188550&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object>
<p><a href="http://vimeo.com/9188550">View on Vimeo</a> 

]]></content:encoded>
    </item>
    <item>
      <title>Basho Podcast Three - An Introduction To Innostore</title>
      <link>http://blog.basho.com/2010/02/02/basho-podcast-three---an-introduction-to-innostore/</link>
      <pubDate>Tue, 02 Feb 2010 15:45:00 EST</pubDate>
      <category><![CDATA[Riak]]></category>
      <category><![CDATA[InnoDB]]></category>
      <category><![CDATA[Erlang]]></category>
      <category><![CDATA[Innostore]]></category>
      <guid isPermaLink="true">http://blog.basho.com/2010/02/02/basho-podcast-three---an-introduction-to-innostore/</guid>
      <description>Basho Podcast Three - An Introduction To Innostore</description>
      <content:encoded><![CDATA[
<p>You may remember that Basho recently open-sourced 
	<a href="http://basho.com/developers.html#innostore">Innostore</a>, our standalone Erlang application that provides a simple interface to embedded InnoDB...</a></p>

<p>In this podcast, <a href="http://www.twitter.com/dizzyco">Dave "Dizzy" Smith</a> and 
	<a href="http://twitter.com/justinsheehy">Justin Sheehy</a> discuss the release of Innostore, why we built it, how we use it in <a href="http://basho.com/Riak.html">Riak</a>, and why it might be useful for other Erlang projects. The discussion focuses on the stability and predictability of InnoDB, especially under load and as compared with other storage backends like DETS.</p>

<p>And of course, <a href="http://hg.basho.com/innostore/">go download Innostore</a> when you are done with the podcast.</p>

<p>Enjoy!</p>

<p><a href="http://www.twitter.com/pharkmillups">Mark</a></p>


<script language="JavaScript" src="/audio/audio-player.js"></script>
<object type="application/x-shockwave-flash" data="/audio/player.swf" id="audioplayer1" height="24" width="290">
<param name="movie" value="/audio/player.swf">
<param name="FlashVars" value="playerID=audioplayer1&soundFile=/audio/Basho-Podcast-Three-An-Introduction-to-Innostore.mp3">
<param name="quality" value="high">
<param name="menu" value="false">
<param name="wmode" value="transparent">
</object>
<br></br>
<p><a href="/audio/Basho-Podcast-Three-An-Introduction-to-Innostore.mp3"><i>If you are having problems getting the podcast to play, click here to play in new window or right click to download the podcast.</i></a></p>
]]></content:encoded>
    </item>
    <item>
      <title>Why Vector Clocks are Easy</title>
      <link>http://blog.basho.com/2010/01/29/why-vector-clocks-are-easy/</link>
      <pubDate>Fri, 29 Jan 2010 11:15:00 EST</pubDate>
      <category><![CDATA[Riak]]></category>
      <guid isPermaLink="true">http://blog.basho.com/2010/01/29/why-vector-clocks-are-easy/</guid>
      <description>Why Vector Clocks are Easy</description>
      <content:encoded><![CDATA[

<div id="outline-container-1" class="outline-2">

<div class="outline-text-2" id="text-1">
<p>
<a href="http://en.wikipedia.org/wiki/Vector_clock">Vector clocks</a>
are confusing the first time you're introduced to them.  It's not
clear what their benefits are, nor how it is you derive said benefits.
Indeed, each Riak developer has had his own set of false starts in
making them behave.
</p>
<p>
The truth, though, is that vector clocks are actually very simple, and
a couple of quick rules will get you all the power you need to use
them effectively.
</p>
<p>
The simple rule is: assign each of your actors an ID, then make sure you
include that ID and the last vector clock you saw for a given value
whenever to store a modification.
</p>
<p>
The rest of this post will explain why and how to follow that simple
rule.  First, I'll explain how vector clocks work with a <b>very</b> simple
example, and then show how to use them easily in Riak.
</p>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Vector Clocks by Example </h2>
<div class="outline-text-2" id="text-2">
<p>
We've all had this problem:
</p>
<blockquote>
<p>Alice, Ben, Cathy, and Dave are planning to meet next week for
dinner.  The planning starts with Alice suggesting they meet on
Wednesday.  Later, Dave discuss alternatives with Cathy, and they
decide on Thursday instead.  Dave also exchanges email with Ben, and
they decide on Tuesday.  When Alice pings everyone again to find out
whether they still agree with her Wednesday suggestion, she gets
mixed messages: Cathy claims to have settled on Thursday with Dave,
and Ben claims to have settled on Tuesday with Dave.  Dave can't be
reached, and so no one is able to determine the order in which these
communications happened, and so none of Alice, Ben, and Cathy know
whether Tuesday or Thursday is the correct choice.
</p>
</blockquote>
<p>
The story changes, but the end result is always the same: you ask
two people for the latest version of a piece of information, and
they reply with two different answers, and there's no way to tell
which one is <b>really</b> the most recent.
</p>
<p>
Vector clocks to the rescue, but how?  Simple: tag the date choice
with a vector clock, and then have each party member update the
clock whenever they alter the choice.  Start with Alice's initial
message:
</p>
<pre class="example">
date = Wednesday
vclock = Alice:1
</pre>
<p>
Alice says, "Let's meet Wednesday," and tags that value as the first
version of the message that she has seen.  Now Dave and Ben start
talking.  Ben suggests Tuesday:
</p>
<pre class="example">
date = Tuesday
vclock = Alice:1, Ben:1
</pre>
<p>
Ben left Alice's mark alone, but added a mark specifying that it was
the first version of the message that he had seen.  Dave replies,
confirming Tuesday:
</p>
<pre class="example">
date = Tuesday
vclock = Alice:1, Ben:1, Dave:1
</pre>
<p>
Just like Ben's modification, Dave just adds his own first-revision
mark.  Now Cathy gets into the act, suggesting Thursday:
</p>
<pre class="example">
date = Thursday
vclock = Alice:1, Cathy:1
</pre>
<p>
But wait, what happened to Ben's and Dave's marks?  Cathy didn't
have a version of the object that had been modified by Ben or Dave,
so their marks can't appear in her modification.  This means that
<b>Dave</b> has two conflicting objects:
</p>
<pre class="example">
date = Tuesday
vclock = Alice:1, Ben:1, Dave:1
</pre>
<p>
and
</p>
<pre class="example">
date = Thursday
vclock = Alice:1, Cathy:1
</pre>
<p>
Dave can tell that these versions are in conflict, because neither
vclock "descends" from the other.  In order for vclock B to be
considered a descendant of vclock A, each marker in vclock A must have
a corresponding marker in B that has a revision number greater than or
equal to the marker in vclock A.  Markers not contained in a
vclock can be considered to have revision number zero.  So, since
the <i>Tuesday</i> value has a Cathy revision of zero
while <i>Thursday</i> has a Cathy revision of one, <i>Tuesday</i>
cannot descend from <i>Thursday</i>.  But, since <i>Thursday</i> has
Ben and Dave revisions of zero while <i>Tuesday</i> has Bend and Dave
revisions of one, <i>Thursday</i> is also not descended
from <i>Tuesday</i>.  Neither succeeds the other, so Dave has a
conflict to sort out.
</p>
<p>
Luckily, Dave's a reasonable guy, and chooses Thursday:
</p>
<pre class="example">
date = Thursday
vclock = Alice:1, Ben:1, Cathy:1, Dave:2
</pre>
<p>
Dave also created a vector clock that is successor to all
previously-seen vector clocks: it has revision numbers for every
actor equal to or greater than the last revision number he saw for
that actor.  He emails this value back to Cathy.
</p>
<p>
So now when Alice asks Ben and Cathy for the latest decision, the
replies she receive are, from Ben:
</p>
<pre class="example">
date = Tuesday
vclock = Alice:1, Ben:1, Dave:1
</pre>
<p>
and from Cathy:
</p>
<pre class="example">
date = Thursday
vclock = Alice:1, Ben:1, Cathy:1, Dave:2
</pre>
<p>
From this, she can tell that Dave intended his correspondence with
Cathy to override the decision he made with Ben.  All Alice has to
do is show Ben the vector clock from Cathy's message, and Ben will
know that he has been overruled.  (Dave will, almost certainly,
blame his broken email software for failing to inform Ben of the
change.)
</p>
</div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">How to do this in Riak </h2>
<div class="outline-text-2" id="text-3">
<p>
Now that you understand vector clocks, using them with Riak is easy.
I'll use the raw HTTP interface to illustrate.
</p>
<p>
First, whenever you store a value, include an <code>X-Riak-ClientId</code>
header to identify your actor.  For Alice's first message above,
you'd say:
</p>
<pre class="example">
curl -X PUT -H "X-Riak-ClientId: Alice" -H "content-type: text/plain" \
http://localhost:8098/raw/plans/dinner --data "Wednesday"
</pre>
<p>
When Ben, Cathy, and Dave each GET Alice's plans, they'll get the
same vector clock (I've removed some of the other headers for
brevity):
</p>
<pre class="example">
curl -i http://localhost:8098/raw/plans/dinner
HTTP/1.1 200 OK
X-Riak-Vclock: a85hYGBgzGDKBVIsrLnh3BlMiYx5rAzLJpw7wpcFAA==
Content-Type: text/plain
Content-Length: 9

Wednesday
</pre>
<p>
The <code>X-Riak-Vclock</code> header contains an encoded version of a vclock
that is the same as out earlier example: Alice has modified this
value once.
</p>
<p>
Now when Ben sends his change to Dave, he includes both the vector
clock he pulled down (in the <code>X-Riak-Vclock</code> header), and his own
<code>X-Riak-Client-Id</code>:
</p>
<pre class="example">
curl -X PUT -H "X-Riak-ClientId: Ben" -H "content-type: text/plain" \
-H "X-Riak-Vclock: a85hYGBgzGDKBVIsrLnh3BlMiYx5rAzLJpw7wpcFAA==" \
http://localhost:8098/raw/plans/dinner --data "Tuesday"
</pre>
<p>
Dave pulls down a fresh copy, and then confirms Tuesday:
</p>
<pre class="example">
curl -i http://localhost:8098/raw/plans/dinner
...
X-Riak-Vclock: a85hYGBgymDKBVIsrLnh3BlMiYx5rAymfeeO8EGFWRLl30GF/00ACmcBAA==
...
curl -X PUT -H "X-Riak-ClientId: Dave" -H "content-type: text/plain" \
-H "X-Riak-Vclock: a85hYGBgymDKBVIsrLnh3BlMiYx5rAymfeeO8EGFWRLl30GF/00ACmcBAA==" \
http://localhost:8098/raw/plans/dinner --data "Tuesday"
</pre>
<p>
Cathy, on the other hand, hasn't pulled down a new version, and
instead merely updated the plans with her suggestion of Thursday:
</p>
<pre class="example">
curl -X PUT -H "X-Riak-ClientId: Cathy" -H "content-type: text/plain" \
-H "X-Riak-Vclock: a85hYGBgzGDKBVIsrLnh3BlMiYx5rAzLJpw7wpcFAA==" \
http://localhost:8098/raw/plans/dinner --data "Thursday"
</pre>
<p>
(That's the same vector clock that Ben used, in that encoded
gibberish is making your eyes cross.)
</p>
<p>
Now, when Dave goes to grab this new copy (after Cathy tells him she
has posted it), he'll see one of two things.  If the "plans" Riak
bucket has the <code>allow_mult</code> property set to <code>false</code>, he'll see just
Cathy's update.  If <code>allow_mult</code> is <code>true</code> for the "plans" bucket,
he'll see both his last update and Cathy's.  I'm going to show the
<code>allow_mult=true</code> version below, because I think it illustrates the
flow better.
</p>
<pre class="example">
curl -i -H "Accept: multipart/mixed" http://localhost:8098/raw/plans/dinner
HTTP/1.1 300 Multiple Choices
X-Riak-Vclock: a85hYGBgzWDKBVIsrLnh3BlMiYx5rAymfeeO8EGFWRLl30GF1fsRwsypF59BhT0mIoTZ/1SYQIUrEcJszUksu9R6kCWyAA==
Content-Type: multipart/mixed; boundary=ZZ3eyjUllBi7GXRRMJsUublFxjn
Content-Length: 368


--ZZ3eyjUllBi7GXRRMJsUublFxjn
Content-Type: text/plain

Tuesday
--ZZ3eyjUllBi7GXRRMJsUublFxjn
Content-Type: text/plain

Thursday
--ZZ3eyjUllBi7GXRRMJsUublFxjn--
</pre>
<p>
Dave sees two values because the vclock that Cathy generated wasn't
a successor to the vclock that Dave had generated with his last
modification.  Riak couldn't choose between them, and therefore kept
both values.
</p>
<p>
Dave picks Thursday, and updates the object, resolving the conflict.
Riak has already computed a unified, descendant vector clock for
Dave, so he uses the vector clock from the multi-value version he
just pulled down, just like before:
</p>
<pre class="example">
curl -X PUT -H "X-Riak-ClientId: Dave" -H "content-type: text/plain" \
-H "X-Riak-Vclock: a85hYGBgzWDKBVIsrLnh3BlMiYx5rAymfeeO8EGFWRLl30GF1fsRwsypF59BhT0mIoTZ/1SYQIUrEcJszUksu9R6kCWyAA==" \
http://localhost:8098/raw/plans/dinner --data "Thursday"
</pre>
<p>
Now when Alice check for the latest version, she just sees the final
decision:
</p>
<pre class="example">
curl -i http://localhost:8098/raw/plans/dinner
HTTP/1.1 200 OK
X-Riak-Vclock: a85hYGBgzWDKBVIsrLnh3BlMiYx5rAymfeeO8EGFWRLl30GF1fvhwmzNSSy71HqgEpUTEerZ/1SYYBFmTr34DCjMBBTOnQwUzgIA
Content-Type: text/plain
Content-Length: 7

Thursday
</pre>
<p>
While Riak couldn't decide whether to choose Cathy's modification
over Dave's earlier modification, it was easy to choose Dave's
latest modification, because the vclock created was a successor to
the vclock in place.
</p>
</div>
</div>
<div id="outline-container-4" class="outline-2">
<h2 id="sec-4">Review </h2>
<div class="outline-text-2" id="text-4">
<p>
So, vclocks are easy: assign each of your actors an ID ("Alice",
"Ben", "Cathy", and "Dave" in these examples), then make sure you
include that ID and the last vector clock you saw for a given value
whenever to store a modification.
</p>
<p>
If two actors store changes with vector clocks that don't descend
from each other, Riak will store and hand back both values.  When
descendancy can be calculated, values stored with vector clocks that
have been succeeded will be removed.
</p>
<p>
<a href="http://twitter.com/hobbyist">-Bryan</a>
</p></div>
</div>
]]></content:encoded>
    </item>
    <item>
      <title>Innostore -- connecting Erlang to InnoDB</title>
      <link>http://blog.basho.com/2010/01/26/innostore----connecting-erlang-to-innodb/</link>
      <pubDate>Tue, 26 Jan 2010 08:11:41 EST</pubDate>
      <category><![CDATA[Riak]]></category>
      <category><![CDATA[InnoDB]]></category>
      <guid isPermaLink="true">http://blog.basho.com/2010/01/26/innostore----connecting-erlang-to-innodb/</guid>
      <description>Innostore -- connecting Erlang to InnoDB</description>
      <content:encoded><![CDATA[
<p>
<a href="http://www.basho.com/Riak.html">Riak</a> has pluggable storage engines, and so we're always on the lookout for better ways that users can store their data locally.  Recent experiences with some <a href="http://www.basho.com/">Basho</a> customers managing some large datasets led us to believe that InnoDB might work out very well for them.
</p>
<p>
To answer that question and fill that need, <a href="http://www.basho.com/developers.html#innostore">Innostore</a> was written.  It is a standalone Erlang application that provides a simple interface to Embedded InnoDB.  So far its performance has been quite good, though InnoDB (with or without the Innostore API) is highly dependent on tuning the local configuration to match the local hardware.  Luckily, <a href="http://basho.com/bios.html#Dave">Dizzy</a> -- the author of Innostore -- has some heavy-duty experience doing that kind of tuning and as a result we've been able to help people meet their performance goals using Innostore.

<p><a href="http://www.twitter.com/justinsheehy">-Justin</a></p>
]]></content:encoded>
    </item>
    <item>
      <title>Basho Podcast Two - An Introduction to erlang_js</title>
      <link>http://blog.basho.com/2010/01/19/basho-podcast-two---an-introduction-to-erlang_js/</link>
      <pubDate>Tue, 19 Jan 2010 09:10:04 EST</pubDate>
      <category><![CDATA[Riak]]></category>
      <category><![CDATA[Map/Reduce]]></category>
      <category><![CDATA[NoSQL]]></category>
      <category><![CDATA[Database]]></category>
      <category><![CDATA[JavaScript]]></category>
      <category><![CDATA[erlang_js]]></category>
      <category><![CDATA[Scaling]]></category>
      <category><![CDATA[Podcast]]></category>
      <guid isPermaLink="true">http://blog.basho.com/2010/01/19/basho-podcast-two---an-introduction-to-erlang_js/</guid>
      <description>Basho Podcast Two - An Introduction to erlang_js</description>
      <content:encoded><![CDATA[
<p>Check out the new Basho podcast featuring <a href="http://basho.com/bios.html#Kevin">Kevin Smith</a> and <a href="http://basho.com/bios.html#Bryan">Bryan Fink</a> that discusses erlang_js,  a simple and easy-to-use binding between Erlang and JavaScript. It is packaged as an OTP application so developers can easily embed Javascript inside their own applications.</p>

<p>Once you are done with the podcast, go <a href="http://bitbucket.org/basho/erlang_js/downloads/">download erlang_js.</a>


<p>Enjoy,</p>

<p><a href="http://www.twitter.com/pharkmillups">Mark Phillips</a></p>



<script language="JavaScript" src="/audio/audio-player.js"></script>
<object type="application/x-shockwave-flash" data="/audio/player.swf" id="audioplayer1" height="24" width="290">
<param name="movie" value="/audio/player.swf">
<param name="FlashVars" value="playerID=audioplayer1&soundFile=/audio/Basho-Riak-Podcast-Two-Introducing-erlang_js.mp3">
<param name="quality" value="high">
<param name="menu" value="false">
<param name="wmode" value="transparent">
</object>
<br></br>
<p><a href="/audio/Basho-Riak-Podcast-Two-Introducing-erlang_js.mp3"><i>Right click here to download the Podcast</i></a></p>
]]></content:encoded>
    </item>
    <item>
      <title>A Quick Note on Rebar</title>
      <link>http://blog.basho.com/2010/01/10/a-quick-note-on-rebar/</link>
      <pubDate>Sun, 10 Jan 2010 23:45:00 EST</pubDate>
      <category><![CDATA[Riak]]></category>
      <category><![CDATA[Rebar]]></category>
      <guid isPermaLink="true">http://blog.basho.com/2010/01/10/a-quick-note-on-rebar/</guid>
      <description>A Quick Note on Rebar</description>
      <content:encoded><![CDATA[

<p>As many of you Erlang and <a href="http://basho.com/Riak.html">Riak</a> fans know, <a href="http://twitter.com/dizzyco">Dave Smith</a> has been hard at work on <a href="http://hg.basho.com/rebar/">Rebar</a>. For those of you who don't know, Rebar is a truly cool packaging and build tool for Erlang applications. Dave took a break from coding this morning to <a href="http://dizzyd.com/blog/">post a few words on his blog Gradual Epiphany</a> about why he was inspired to write Rebar and what it means for building and deploying applications. Check it out. It's a great read.</p>

<p>Also, if you haven't had a chance to join the Rebar mailing list, you <a href="http://lists.basho.com/mailman/listinfo/rebar_lists.basho.com">can do so here.</a></p>

<p><a href="http://www.twitter.com/pharkmillups">Mark</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Riak Screencasts and Presentations - The Collected Works</title>
      <link>http://blog.basho.com/2009/12/28/riak-screencasts-and-presentations---the-collected-works/</link>
      <pubDate>Mon, 28 Dec 2009 15:45:00 EST</pubDate>
      <category><![CDATA[NoSQL]]></category>
      <category><![CDATA[Riak]]></category>
      <category><![CDATA[Resources]]></category>
      <category><![CDATA[Screencast]]></category>
      <category><![CDATA[Database]]></category>
      <guid isPermaLink="true">http://blog.basho.com/2009/12/28/riak-screencasts-and-presentations---the-collected-works/</guid>
      <description>Riak Screencasts and Presentations - The Collected Works</description>
      <content:encoded><![CDATA[

<p>To date, there have been a number of screencasts and presentations done on <a href="http://basho.com/Riak.html">Riak</a> and Riak-related technologies. As a belated holiday gift (we were coding, not blogging), we thought it would be a valuable resource if we assembled all of them in an easy-to-peruse list here on the Basho Blog. If we missed any, please let us know in the comments.

<p>Go forth and consume!</p>

<p><a href="http://twitter.com/pharkmillups">Mark</a></p>

<br/>
<ul id="Riak Screencasts">

<li><a href="http://twitter.com/justinsheehy">Justin Sheehy's</a> Riak presentation at NoSQL East    
	<p><b>Link: </b> <a href="https://nosqleast.com/2009/#speaker/sheehy">https://nosqleast.com/2009/#speaker/sheehy</a></p></li>

<li><a href="http://twitter.com/hobbyist">Bryan Fink's</a> fantastic overview of Riak in October at <a href="http://sqlfreenyc.org/">SQLFreeNYC</a>
	<p><b>Link: </b><a href="http://www.vimeo.com/6973519">http://www.vimeo.com/6973519</a></li></p>
	
<li><a href="http://twitter.com/dizzyco">Dave Smith's</a> introducion to Riak in an embedded node using<a href="http://hg.basho.com/rebar/"> Rebar</a>, a packing and build tool for Erlang applications.
	<p><b>Link:</b> <a href="http://vimeo.com/8311407">http://vimeo.com/8311407</a></li>
	
<li>Dave Smith also gave a more general overview of Rebar</a>
	<p><b>Link: </b><a href="http://vimeo.com/8311407">http://vimeo.com/8311407</a></p> </li> 

<li><a href="http://twitter.com/Zeit_geist">Martin Scholl's</a>...awesome presentation on Riak at <a href="http://nosqlberlin.de">NoSQL Berlin</a> 
	<p><b>Link:</b><a href="http://vimeo.com/7318171"> http://vimeo.com/7318171</a></li></p>

<li><a href="http://twitter.com/rklophaus">Rusty Klophaus'</a> presentation entitled "Nitrogen and Riak by Example" at <a href="http://www.erlang-factory.com/conference/ErlangUserConference2009">Erlang Factory in Stockholm</a> 
	<p><b>Link: </b> <a href="http://bit.ly/5AgKzW">http://bit.ly/5AgKzW</a></li></p>

<li>Bryan Fink's screencast with <a href="http://twitter.com/benahlan">Ben Ahlan</a> of <a href="http://www.videocodechat.com">Video Code Chat</a> demonstrating basic setup and usage of Riak 
	<p><b>Link: </b> <a href="http://bit.ly/akagc"> http://bit.ly/akagc</a></p></li>

</ul>]]></content:encoded>
    </item>
  </channel>
</rss>
