41 constexpr
const mdb_mode_t open_flags = (S_IRUSR | S_IWUSR);
49 constexpr
const mdb_size_t max_resize = 1 * 1024 * 1024 * 1024;
50 void acquire_context(
context& ctx) noexcept
52 while (ctx.
lock.test_and_set());
57 void release_context(
context& ctx) noexcept
73 release_context(*ctx);
95 for (
unsigned attempts = 0; attempts < 3; ++attempts)
102 if (!err && txn !=
nullptr)
105 release_context(ctx);
114 : env(
std::
move(env)), ctx{{}, ATOMIC_FLAG_INIT}
133 while (ctx.
lock.test_and_set());
151 acquire_context(ctx);
155 release_context(ctx);
162 return read_txn{new_txn->release()};
163 return new_txn.error();
170 release_context(ctx);
176 return do_create_txn(0);
184 release_context(ctx);
virtual ~database() noexcept
int mdb_env_set_mapsize(MDB_env *env, mdb_size_t size)
Set the size of the memory map to use for this environment.
expect< read_txn > create_read_txn(suspended_txn txn=nullptr) noexcept
#define ELECTRONEUM_LMDB_CHECK(...)
Executes a LMDB command, and returns errors via lmdb::error enum.
int mdb_txn_commit(MDB_txn *txn)
Commit all the operations of a transaction into the database.
void * mdb_env_get_userctx(MDB_env *env)
Get the application information associated with the MDB_env.
std::unique_ptr< MDB_txn, abort_txn > suspended_txn
int mdb_env_info(MDB_env *env, MDB_envinfo *stat)
Return information about the LMDB environment.
std::unique_ptr< MDB_txn, abort_write_txn > write_txn
int mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs)
Set the maximum number of named databases for the environment.
struct MDB_env MDB_env
Opaque structure for a database environment.
MDB_env * mdb_txn_env(MDB_txn *txn)
Returns the transaction's MDB_env.
expect< environment > open_environment(const char *path, MDB_dbi max_dbs) noexcept
std::unique_ptr< MDB_env, close_env > environment
database(environment env)
std::unique_ptr< MDB_txn, release_read_txn > read_txn
struct MDB_txn MDB_txn
Opaque structure for a transaction handle.
int mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode)
Open an environment handle.
Information about the environment.
expect< void > resize() noexcept
void mdb_txn_reset(MDB_txn *txn)
Reset a read-only transaction.
std::atomic< std::size_t > active
expect< write_txn > create_write_txn() noexcept
int mdb_txn_renew(MDB_txn *txn)
Renew a read-only transaction.
#define ELECTRONEUM_CHECK(...)
Check expect<void> and return errors in current scope.
expect< void > commit(write_txn txn) noexcept
Commit the read-write transaction.
unsigned int MDB_dbi
A handle for an individual database in the DB environment.
int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Create a transaction for use with the environment.
int mdb_env_create(MDB_env **env)
Create an LMDB environment handle.
expect< void > success() noexcept
const T & move(const T &t)
void operator()(MDB_txn *ptr) const noexcept
#define ELECTRONEUM_PRECOND(...)
If precondition fails, return ::error::kInvalidArgument in current scope.
int mdb_env_set_userctx(MDB_env *env, void *ctx)
Set application information associated with the MDB_env.
expect< suspended_txn > reset_txn(read_txn txn) noexcept
#define ELECTRONEUM_THROW(code, msg)
error
Tracks LMDB error codes.