Add assert against mixing cursor and regular DB calls.

Only active in debug mode.
(cherry picked from commit a73669c1afd4da1db3c9ed8310416bb2f072547e)

Strictly cherry-picked to make the next cherry-pick conflictless.
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.

Additionally changed wrong include style at top of file, and also
removed a few stubs from tests that are not needed anymore after
libutils is included in the test build.
(cherry picked from commit 1c3d1171a7d6cf76bde858457f7f4a046ef34646)
Rename write_txn to rw_txn to make its meaning clearer.
(cherry picked from commit 761c72fcaf172387173fc061cf9acbb2221cfc48)
Redmine#5486 Better support for LMDB >= 0.9.11

API has changed slightly, "key" is now required even with MDB_CURRENT.
It was ignored in older versions, so enable it everywhere.

Based on a patch by jeffali <hichame.jeffali@cfengine.com>.
(cherry picked from commit 87dd768569a925e9607c56abc902c945ee334616)
Redmine#5486 Re-enable db_concurrent_test
(cherry picked from commit 685a11c8bdf202d876f31edd0c17ee9cb6606b55)
Rename shell script to .sh extension.
(cherry picked from commit 907697d685d927f73d74ad6541f18cdb4ea616c7)
Introducing lastseen_threaded_load.
(cherry picked from commit 8727eff894c8a9dea47fe30fb3beeb25800f1de9)