nano-node icon indicating copy to clipboard operation
nano-node copied to clipboard

Add submodule lmdbxx which is a c++ wrapper for lmdb

Open clemahieu opened this issue 5 months ago • 0 comments

This change adds the lmdbxx submodule which is a c++ wrapper for LMDB. https://github.com/hoytech/lmdbxx

Currently we're using an amalgamation of direct access to the LMDB C API and some custom c++ wrapping of select portions of functionality.

Major motivations for using this library:

  • Header-only
  • C++17 language support
  • Errors are exceptions
  • RAII for LMDB resources
  • Uses std::string_view for exchanging serialised objects which is compatible with rocksdb::Slice

The library has two implementation strategies, a near 1-to-1 wrapping of the C API with exception handling, and full RAII types. Migrating existing code to use the direct API was relatively painless and some of the RAII types can already be used.

The primary motivation for the change is to get a clear separation of the lmdb c++ wrapper from node-specific logic. Additionally, this removes the burden of wrapping the C API from the node code.

The library itself seems to make good design decisions and is reasonably maintained.

There are parts of the library which are not fully complete e.g. ::lmdb::dbi does not fully implement RAII, it is both copyable and doesn't destroy the underlying resources when it goes out of scope. To get full benefits we will likely have to upstream some patches which they will hopefully be receptive and responsive to.

clemahieu avatar Sep 09 '24 19:09 clemahieu