Friday, August 17, 2012

Intro to RavenDB BDB storage engine

I have set out on a quest to get the BDB storage engine working with RavenDB.  I am a big believer in C# running on Linux, we've been running production sites on Linux for years, and it's been a great experience.  Recently, we have started a new project where the RavenDB document database seemed like a good fit.  After about a week or two of poking around with it I discovered how great it is for certain applications.  Unfortunately the only production storage engine is based on Microsoft Esent database engine thus does not run under linux.

There has been some talk on the mailing lists about creating a new storage engine based on the Berkeley DB engine, which runs on both Windows and linux.  And after tackling the facet optimization for RavenDB (which I will hopefully post on later), I have decided to attempt this feat.

I have very little experience with RavenDB and exactly zero experience with BDB.  There is no documentation for the RavenDB storage backend (except for the code), so a lot of the work is based on trial and error.  So my starting point for RavenDB is the code, and for BDB is this tutorial http://pybsddb.sourceforge.net/reftoc.html.

You can track my progress in github

Step1 - Get the code to compile

  1. Copy the Raven.Storage.Esent project to Raven.Storage.Bdb, rename namespaces. 
  2. Delete all of the code from every class, and re-implemented all interfaces to throw NotImplementedException.
  3. A bdb class type to CreateTransactionalStorage so that we can create our new storage engine.
  4. Run and wait for the crash!
var storageEngine = SelectStorageEngine();
switch (storageEngine.ToLowerInvariant())
{
 case "esent":
  storageEngine = "Raven.Storage.Esent.TransactionalStorage, Raven.Storage.Esent";
  break;
 case "bdb":
  storageEngine = "Raven.Storage.Bdb.TransactionalStorage, Raven.Storage.Bdb";
  break;
 case "munin":
  storageEngine = "Raven.Storage.Managed.TransactionalStorage, Raven.Storage.Managed";
  break;
}
var type = Type.GetType(storageEngine);

Step2 - Get the server to run

Now that we have a server that at least uses our storage engine it's time to actually get the server to start up. Since I have no idea the order of events for the storage engine, it's simply a matter of a back and forth between eliminating NotImplementedException and running the server.

In order to eliminate the exceptions (without knowing what any of the functions really do yet) is to look at the return parameter.

  • If the function returns void then I just make a blank function
  • If the function returns an object then I return null
  • If the function returns IEnumberable, then I just yield break.
  • Some functions that have non-Esent code in them are copied from the previous storage engine
After a bunch of change/run sessions, we get a running server that does nothing.


Well that concludes the first post on the BDB storage engine.  Next time we will actually look at getting some files to the hard drive.

No comments:

Post a Comment