Friday, October 31, 2014

Irmin Irmin on the wall, who is the pretiest of them all - Moana

I am currently working on MoanaML.

My recent challenge was to code a backend based on Mirage/Irmin.

Ok, first thing first, what is Moana:

Moana, an information-centric middleware for distributed services and applications. Moana offers a shared graph-based storage abstraction through which applications communicate with each other by appending and observing the shared graph.
Moana supports two basic operations of ADD and MAP; add allows an application to persistently extend the global graph, and map provides a dynamically maintained mapping of the global graph to an application specific, internal sub-graph.
MoanaML is an implementation of the Moana primitives in OCaml.

Now, what is Irmin:

Irmin is a distributed database with built-in snapshot, branch and revert mechanisms. It is designed to use a large variety of backends, although it is optimized for append-only store.
 
Just  to recap, at the moment, MoanaML contains:

Here I wanted to summaries some of my initial progress on developing the Irmin backend for Moana.

To code Irmin-based backed we need to implement two Moana signatures, namely STORE and GRAPH

I am a noobie when it comes to Irmin, I am still trying to figure out all of its functionalities so proceed with caution :)

I recommend reading this blog post to get a better understanding on Irmin, also I found this short paper very insightful. For better code understanding, make sure you familiarise yourself with the lwt library.

So to use Irmin, I chose to use blocks of type String, just because it is provided; to have different types of values you need to implement your own IrminContents signature. This, from my understanding, involves letting Irmin know how to merge your values.

Ultimately, I want to use Irmin to store Moana tuples, not strings, so I will have to implement the Contents signature. For now, I convert Moana tuples into JSON string and store them in Irmin.

Now to the code...


Following Irmin examples, I first implemented t_of_view  and view_to_t functions to convert list of tuples to view and take list of tuples from the view, respectively. I later use these functions to store the views inside Irmin.

The cool thing about Irmin that all  my data is stored in git.

Thanks to this:

module Git =
  IrminGit.FS(struct let root = Some "/tmp/irmin/moana"
                        let bare = true
                           end)
 
(* Values are Strings * *)
module Store = Git.Make(IrminKey.SHA1)(IrminContents.String)(IrminTag.String)

You can also visualise it!