2012-04-22

BSON objectid customization for sharding


Following the recommendations in http://www.mongodb.org/display/DOCS/Choosing+a+Shard+Key I implemented these two id generators that follow the ObjectId model. I hope some day they can get driver support so that saving them in binary format will be possible.
ShardableObjectId: Creates a nice distribution of keys over all buckets/shards for linear write/read scaling.
ShardableObjectIdWithMoPrefix: Creates keys prefixed with yyyymm so eg. 201203 so that inserts affect only part of the index.
Currently I propose just using them as string generators with the toString or toStringBase64URLSafe methods. The generated strings are safe for copy'n paste and work in most frameworks as entity ids that can be passed in the URL.
Needs:
  • BSON mongodb driver
  • apache commons codec
Limitations:
  • design has a log of repeated code everywhere (shardable* and BSON ObjectId very similar).
  • string generation not optimized. Too lazy to change apache commons codec now.
  • depends on commons codec
Those limitations are fine for me of course.

What do you think?

2012-04-10

Using dust.js in play framework 2.0

I'm really into trying frameworks and play 2.0 is a really nice package. Something's always missing, and for me and play 2.0 it's dust.js templates.

There's a half official typesafe dust sbt plugin, but

  1. I cannot make it download via ivy/mave/sbt magic
  2. I cannot compile it - how do I let it find play?
So had to make a shameless copy of the nice coffeescript plugin that comes with play 2.0. You can clone my dust sbt play plugin on github.

Just call 
  1. git clone git://github.com/georgkoester/Play20.git  
  2. cd Play20
  3. git checkout dust_play_sbt_plugin 
  4. cd framework
  5. ./build
  6. build-repository
  7. compile
  8. publish-local
and you got a version of play 2.0 with my patch. Of course you could just pull the patch too.

Happy playin!