Friday, 31 May 2013

MongoDB Java driver randomness - it's only logging, but

I saw a number or people on Twitter yesterday posting a link to some "interesting" code in MongoDB's Java driver github.

The strange code located inside some exception handling included the following:

                if (!((_ok) ? true : (Math.random() > 0.1))) {
                    return res;
                }

I know my own code isn't always a shining example to be held up as the one true way of doing things, but seriously doubt that I have ever produced something as inexplicable as that.

I briefly tried to trace back the history to determine how long this has been around and whether there is a meaningful commit comment, but was in the middle of other more important things (lunch) and gave up.

The latest theory I have heard is that the code was introduced as an approach to reduce the amount of noise in logging of the exception.  I don't expect to see this recommended as a pattern any time soon.

Monday, 27 May 2013

MongoDB Lightning Talk

My employer recently hosted a gathering of their IT teams from around the world for a two day conference in Madrid.  It was a good opportunity to meet colleagues that I had previously only dealt with by phone and email in a relaxed social setting.

In a moment of madness I volunteered to give a presentation about a topic that I have been dabbling with in recent months - MongoDB.

My agile style of preparation - "delay commitment until the last responsible moment" - could easily have been mistaken for procrastination.  I'm not sure if I would recommend sitting on a sofa watching old episodes of Miami Vice with the laptop drifting in and out of sleep mode as being optimal for all.

Without further ado, here is a high level view of some of the content that I blended together:
  • What is MongoDB?
    • Non-Relational JSON Document Store
    • Dynamic Schema
    • Embedding of Documents and Arrays
    • Comparison with relational database (Table -> Collection, Row -> Document etc.)
  • How to Organise Data
    • Entity -> Document
    • Embedding vs Referencing
    • 16MB document size limit
    • Indexing
  • How to Query
    • Example of find
    • Example of insert
    • Example of aggregation framework
  • What is MongoDB being used for?
    • E-commerce
    • Analytics and Reporting
    • Content Management
      • CoreMedia Elastic Social
    • Logging
  • Language and Framework Support
    • Listing of languages and frameworks
    • Drivers have semantics to fit with the style of the language
  • Replication
    • Configurable tags - usable within write concerns
    • Configurable delay
  • Sharding
    • Distribution of writes
    • Shard key selection importance
    • Scatter-gather for reads not satisfiable by a single shard
  • Gotchas
    • Database level locking
    • Default settings not suitable for all
    • Application needs to check for result of operations