BlitzDB Crash Safety and Auto Recovery

July 22nd, 2010

Crash Safety is a big deal in the database league. Lack of durability can lead to all sorts of terrible things upon a catastrophic event. Many projects, especially in the so called NoSQL world compromises crash safety in return for higher QPS. The argument there is that the availability of the overall system should be accomplished by replication since a database server can’t be rescued if the physical disk breaks. I happen to agree with this philosophy but I am also aware that this isn’t a correct answer for everyone. So, what will I do with BlitzDB?

Several relational database hackers have pointed out that BlitzDB isn’t any safer than MyISAM since it doesn’t guarantee crash safety. This is currently true but I plan on making BlitzDB much safer than MyISAM by providing following features.

  1. Auto Recovery Routine (startup option)
  2. Tokyo Cabinet’s Transaction API (table-specific option)

The second feature above would actually guarantee BlitzDB to be crash safe (especially combined with auto recovery) but I won’t get into depth in this post since this topic deserves a blog post of it’s own. Let me just state that this feature will be provided in a form like this:

CREATE TABLE t1 (
  a int PRIMARY KEY,
  b varchar(256)
) ENGINE = BLITZDB, CRASH_SAFE;

From here on, I’ll cover how I plan on hacking auto recovery in BlitzDB.

Auto Recovery Challenges

As I blogged a while back, recovering Tokyo Cabinet is relatively simple. However, this is not a sufficient solution in BlitzDB since the data file (hash database that actually holds the rows) and the index file(s) are independent from each other. That is, the likelihood of the data file and the index file(s) to be inconsistent is very high after a crash. So, how can we hack on this? Pretty simple.

Indexes aren’t Important at Recovery Phase

Because BlitzDB logically separates the data file and it’s indexes, index files aren’t that important. If a server crash had occurred, BlitzDB could delete the index file(s) and recompute them from the data file. Needless to say, this process would involve a lot of random access and computation but it would not dominate the time space of the system since it’s a one-time cost. This approach however has one flaw in it such that the index files can’t be recomputed if the data file is broken or is unrecoverable.

Therefore to guarantee crash safety, BlitzDB must ensure that the data file is unbreakable. This is precisely where Tokyo Cabinet’s Transaction API comes in. I’m planning on using it to protect the data file from breaking. If the data file is protected, the table can be rescued. Simple!

So, that’s what I have in mind for making BlitzDB a safer engine. Unfortunately I can’t start hacking on it immediately since I have several bugs to fix first. Nevertheless I’m looking forward to start hacking on it. This challenge should be quite fun to tackle.

Toru Maesaka drizzle, oss , , ,

Extending CREATE TABLE Syntax in Drizzle

July 21st, 2010

The flexibility to add table-specific options for things like compression, encryption and optimization can be useful to storage engine developers as this flexibility can open up new possibilities. Here’s what I’m talking about:

CREATE TABLE t1 (
  ...
) ENGINE = my_engine, MY_OPTION = your_arg;

Supporting this is relatively easy in Drizzle and this API feature (and a bit more) is available in MariaDB as well. Unfortunately Drizzle’s method to do this isn’t documented in the Wiki yet but it should be added when our Storage Engine API becomes stable (as in, no interface changes).

Implement StorageEngine::doValidateTableOptions()

Here’s the actual interface.

bool StorageEngine::doValidateTableOptions(const std::string &key,
                                           const std::string &state);

This function is called for each table options given at CREATE TABLE syntax execution. The first argument, key is a const reference to a string that represents the option name. The second argument, state represents the argument given for that option.

Therefore, given: COMPRESSION = YES_PLEASE, key would be “COMPRESSION” and state would be “YES_PLEASE”. The objective of this function is to check whether the key/state pair makes sense to your storage engine. If this function returns false, Drizzle will return an error for the CREATE TABLE query. Personally I think this interface can be improved to be a bit more Developer friendly, such as making life easier to validate numeric values without enforcing the developer to play around with the data. Saying that, given the pace that Drizzle is growing, this could be improved before we know it.

Access Options at StorageEngine::doCreateTable()

Here’s the actual interface for doCreateTable().

int doCreateTable(drizzled::Session &session,
                  drizzled::Table &table_arg,
                  const drizzled::TableIdentifier &identifier,
                  drizzled::message::Table &table_proto);

Given that the options were successfully validated, doCreateTable() is called next. In Drizzle, all information regarding a table (including options) is represented in a Google Protocol Buffer message. A reference to that message object is passed to doCreateTable() as the fourth argument so all you need to do is loop through the options list in the message object and extract what you need. Here’s a minimal example that only takes care of one option.

int n_options = table_proto.engine().options_size();
 
for (int i = 0; i < n_options; i++) {
  if (table_proto.engine().options(i).name() == "my_option_name") {
    // Do whatever you like with this stream.
    std::istringstream stream(table_proto.engine().options(i).state());
  }
}

The above example should be simple to extend to handle multiple options. What’s really important in the above example is that the option name can be accessed with the name() accessor and the state (value) of that option with the state() accessor.

So, that’s all I have to cover for now. I hope this feature will help storage engine developers create and provide useful table specific features for their engine.

Happy Hacking.

Toru Maesaka drizzle, oss ,

BlitzDB is now in Drizzle’s Trunk Repository

June 21st, 2010

Happy to announce that BlitzDB has been merged with Drizzle’s Trunk.

As much as I’m excited, it’s time to come back to reality. This merge is merely a beginning. There is much more work that needs to be done to BlitzDB such as ensuring stability by adding more tests, find bugs, and eliminate them. I’m hoping that the likelihood of bugs being found will increase due to this merge. Admittedly, I want to hack on fancy (yet important) things like auto recovery but I’m going to resist doing this until I’m truly satisfied with the quality of BlitzDB. My plan is to have BlitzDB rock solid by Drizzle’s Beta release.

The review process to get BlitzDB into Drizzle was straight forward and smooth. This is mostly due to the fact that the community was very supportive about testing. Folks like Stewart Smith and Patrick Crews from Rackspace pointed out several bugs that I would not have found myself. I’m certainly lucky to have a supportive professional QA engineer (looking at you Patrick) to test out and give punishment to BlitzDB.

All I’ll be doing on BlitzDB for the next couple of weeks is debugging and refactoring to improve readability. What I need more of at the moment is test cases on JOINs that are likely to be used in practice. If you have a good test case, I would greatly appreciate it!

Toru Maesaka drizzle, oss ,

Better Mobile Internet Life in Japan

June 16th, 2010

b-mobile U300 Having mobile internet connectivity was always something hot among tech geeks. What’s interesting though is that this luxury is gradually becoming a normal day to day lifestyle in urban Japan. Nowadays pretty much every major mobile carrier provides unlimited 3G Data SIM package for a competitive price. Pricing currently ranges between 2000 to 3000 JPY (Google Currency Conversion).

This movement in the mobile market is understandable since most modern lightweight laptops and netbooks sold in Japan has an internal 3G modem, which allows you to gain instant internet connectivity as long as there’s antenna coverage. Sony Vaio is a great example of this use-case. Needless to say, the iPad and Android is a contributing factor to the market shift as well.

The catch with these products is that you’re usually obliged to sign a contract for two years. This wouldn’t be a problem if you’re traveling to Japan and planning to stick around for that long but otherwise this can turn out to cost you unnecessary fees for cancellation.

Traveling to Japan? Read This

I’ve always been a fan of the prepaid model (as long as it’s not overpriced). So, last weekend I bought a 6 month package from b-mobile, which is a service that provides 3G internet connectivity (unlimited packets) for a finite period that you choose. The awesome thing about this service is that you don’t have to sign any contracts or register your personal information to the service provider (Japan Communications). All you need to do is prepay for a certain period and they’ll give you a SIM for it. No questions asked. Another good thing about b-mobile is that it runs on docomo’s FOMA network which is arguably the strongest mobile network in Japan.

For your interest I bought mine at Bic Camera in Shibuya and paid around 14,000 JPY for 6 months (works out to be around 2333 JPY per month). Their sales model is great for us consumers but the first impression I got was that this could be pretty dodgy if this product gets in the hands of folks with malicious intents.

Perfect with Android, Especially Nexus One

I decided to throw my new SIM into my HTC Magic (Dev Phone courtesy of Google) and setup tethering on it (both WiFi and USB Cable). Unfortunately the certain Android 2.1 kernel I was using wasn’t compatible with b-mobile so I had to go through several workarounds and ask my Android guru colleagues for help to get it working. The funny thing is that b-mobile will work out of the box with Nexus One running Froyo.

Despite the obstacles I’m happy with the outcome and I hope this blog entry would turn out to be helpful to those that are planning on traveling and staying in Japan for a while.

Toru Maesaka technology , , ,

BlitzDB Concurrent Testing and Write Performance

May 12th, 2010

Last month while being at the MySQL Conference, several people asked me about the status of BlitzDB. Specifically, they were interested in when I’ll release BlitzDB. Fair enough – I’ve been working on this project long enough for people to start questioning this.

The answer is, BlitzDB is done in terms of implementing the design. Right now it’s about finding bugs, fixing it and testing BlitzDB’s stability under concurrent load. Thanks to the motivation boost I gained at the conference, I’ve now fixed the bugs that were slowing me down and I’m gradually adding more tests into BlitzDB’s test suite. I consider BlitzDB’s initial release to be the day it gets merged into Drizzle’s trunk. This is almost ready as BlitzDB seems to be building fine on Drizzle’s Build Farm infrastructure. However, I won’t move to the next step until I’m satisfied with BlitzDB’s stability.

Yesterday I spent some time doing some concurrency testing on BlitzDB’s INSERT code with skyload. Needless to say, concurrency testing is also a convenient way to look at the performance of a particular component. So, I decided to publish my findings from this test. First, here is the background of the test.

Purpose of the Test

  • Test BlitzDB’s slot-lock mechanism.
  • Confirm that BlitzDB will not crash under concurrent INSERT workload.
  • Confirm that key insertion to the index is working as expected.
  • Confirm that writes to multiple indexes work as expected.
  • Observe the write-performance impact of adding an index.

Two commodity boxes were used. One dedicated for the client and the other dedicated for the server (Drizzle + BlitzDB). Both boxes has the same spec: Intel Quad Xeon E5345 (2×4MB L2 cache), 8GB Memory, 500GB SATA II, gigabit NIC. Servers were connected by a gigabit switch. File system on the server was ext3.

By default, a BlitzDB table is optimized for up to 1 million rows. Therefore this test inserted 1 million rows to a table with different concurrency levels. A different concurrency level is used per run. The table used in this test only contains three integer columns. Tests are performed up to three indexes. The linux kenel’s dirty buffer is flushed before each test run. Tests were run until the performance curve flattened.

Result

BlitzDB Table Insertion - Multi Index

As seen above, scalability from 1 thread to 4 thread showed an ideal curve. This is expected since the server is a 4 core box. From 4 threads, performance showed some improvements up to 12 threads. From there on, concurrency greatly exceeds the number of physical cores so we can’t observe decent performance growth. The highest insert QPS gained in this test was just over 86,000 QPS. With more cores on the server and more clients, I suspect BlitzDB can hit over 100k QPS.

Although this graph looks good at first sight, I’m not happy with it. The performance penalty for adding multiple indexes should be greater than what’s observed in this result. This is because TC’s B+Tree is internally protected by a single lock on writes. I suspect that the performance penalty is not observed in this graph because I didn’t give BlitzDB enough load to make TC work hard. This implies that a bottleneck could exist elsewhere (Network, Drizzle or BlitzDB’s handler level code).

However, I’m glad that BlitzDB stood stable on this concurrency test which was what I wanted to test in the first place. Admittedly I need to mix several types of queries to properly test BlitzDB’s stability. I plan on doing this next with sysbench and hopefully RQG.

Once this is done, I’ll submit a merge proposal to the Drizzle Project :)

Future Development Plans

  • Find bugs, Fix bugs, Repeat.
  • Write an inbuilt auto recovery routine.
  • Eventually add a crash safe option to BlitzDB.

Toru Maesaka drizzle, oss , ,

Testing BlitzDB on Drizzle’s Build Farm

May 6th, 2010

One of many important things that the Drizzle project takes seriously is for the project sourcecode to successfully build in all our target platforms AND pass tests in them. This is not really specific to Drizzle as most open source projects would have the same policy. For example we do the same thing in memcached thanks to Dustin Sailing’s buildbot kungfu.

Yesterday, Monty Taylor gave me access to Drizzle’s Build Farm Infrastructure so that I could test BlitzDB on various Linux distributions and FreeBSD. Unfortunately most build machines didn’t have Tokyo Cabinet installed so I could only test builds on Ubuntu and Debian. Fortunately the build went fine on those platforms though this was predictable since Ubuntu is my primary development platform. What was disturbing was getting test errors on my index test suite. I guess it’s time to put my thinking cap on and see what the problem is there.

This is a big leap towards getting BlitzDB in Drizzle’s trunk which I’m steadily working towards. I also want to benchmark BlitzDB at it’s current state with sysbench‘s OLTP tests. This is still low in my priority queue but hopefully I’ll do it in the next couple of months.

Toru Maesaka drizzle, oss , ,

Drizzle Google Summer of Code Projects

April 27th, 2010

This morning while being half a sleep, I was delighted to see an announcement email for Drizzle’s Google Summer of Code projects in my inbox. Congratulations to not only those that are taking part in GSoC via Drizzle but all of you participating in GSoC this year. Here’s the actual announcement email that contains the list of Drizzle projects that will take place this year.

This year I’m mentoring Djellel Eddine Difallah on “A Memcached Query Cache Plugin for Drizzle“. This happens to be a project I abandoned a long time ago so I was happy to see someone digging it up and seeking interest in it.

I’m excited to work with Djellel over the summer. Looking forward to having lots of fun with all the technical challenges and most importantly hacking under the open community environment.

Toru Maesaka drizzle, oss ,

Vacation in Hong Kong and Macau

April 2nd, 2010

I just got back from a vacation in Hong Kong and Macau. It was my first visit to Hong Kong which tuned out to be a really enjoyable one. I’d certainly love to visit Hong Kong again. People were nice, beautiful scenery and cantonese food was delicious. Getting a free business class upgrade definitely made the trip better too.

Hong Kong Hong Kong

However, what truly made our trip was the taxi driver we met on the last day. He was hardly looking at the road and kept talking to us in the back by turning around and facing us. We were all freaked out when he started drawing pictures to communicate with us while doing over 100km/h (62mph) on the highway.

It was also nice to catch up with an old University friend who is living in Hong Kong. It’s always great to see that your fellow alumni is doing well. I’m not sure when I’ll be able to visit Hong Kong again but I hope for it to be soon.

You can see more pictures here.

Toru Maesaka travel