Rewrite transaction handling for LMDB.

The old transaction handling had numerous problems:

  1. It was slow, because we open a new transaction for every single
     read/write. Especially writes would cause fsync() which is very
     I/O intensive.

  2. It was not thread safe, due to the way that transactions were
     handled when using DBWriteNoCommit. The transaction was stored
     in a globally shared structure.

After the rewrite, we store a pthread key in the global structure
instead, and use Thread Local Storage to keep the transaction pointer.
This has the added advantage of reusing the same transaction for
cursors, which means that cursors and regular DB calls can now be
mixed in LMDB. However, the other DB backends may not support this,
so it's still not recommended.