43#if (UINTPTR_MAX == 0xffffffff)
45static const size_t LMDB_DB_SIZE = 2147483648;
46#elif (UINTPTR_MAX == 0xffffffffffffffff)
48static const size_t LMDB_DB_SIZE = 107374182400;
105 rc = mdb_txn_renew(sdata->
txn);
107 rc = mdb_txn_begin(sdata->
env, NULL, MDB_RDONLY, &sdata->
txn);
109 if (rc == MDB_SUCCESS)
116 sdata->
txn ?
"mdb_txn_renew" :
"mdb_txn_begin", mdb_strerror(rc));
135 mdb_txn_abort(sdata->
txn);
138 int rc = mdb_txn_begin(sdata->
env, NULL, 0, &sdata->
txn);
139 if (rc == MDB_SUCCESS)
155 if (!create && access(path, F_OK) != 0)
162 int rc = mdb_env_create(&sdata->
env);
163 if (rc != MDB_SUCCESS)
170 mdb_env_set_mapsize(sdata->
env, LMDB_DB_SIZE);
172 rc = mdb_env_open(sdata->
env, path, MDB_NOSUBDIR, 0644);
173 if (rc != MDB_SUCCESS)
180 if (rc != MDB_SUCCESS)
186 rc = mdb_dbi_open(sdata->
txn, NULL, MDB_CREATE, &sdata->
db);
187 if (rc != MDB_SUCCESS)
193 mdb_txn_reset(sdata->
txn);
199 mdb_txn_abort(sdata->
txn);
204 mdb_env_close(sdata->
env);
217 MDB_val dkey = { 0 };
218 MDB_val data = { 0 };
223 dkey.mv_data = (
void *) key;
228 if (rc != MDB_SUCCESS)
234 rc = mdb_get(sdata->
txn, sdata->
db, &dkey, &data);
235 if (rc == MDB_NOTFOUND)
239 if (rc != MDB_SUCCESS)
245 *vlen = data.mv_size;
261 void *value,
size_t vlen)
266 MDB_val dkey = { 0 };
267 MDB_val databuf = { 0 };
272 dkey.mv_data = (
void *) key;
274 databuf.mv_data = value;
275 databuf.mv_size = vlen;
277 if (rc != MDB_SUCCESS)
282 rc = mdb_put(sdata->
txn, sdata->
db, &dkey, &databuf, 0);
283 if (rc != MDB_SUCCESS)
286 mdb_txn_abort(sdata->
txn);
301 MDB_val dkey = { 0 };
306 dkey.mv_data = (
void *) key;
309 if (rc != MDB_SUCCESS)
314 rc = mdb_del(sdata->
txn, sdata->
db, &dkey, NULL);
315 if ((rc != MDB_SUCCESS) && (rc != MDB_NOTFOUND))
318 mdb_txn_abort(sdata->
txn);
340 mdb_txn_commit(sdata->
txn);
342 mdb_txn_abort(sdata->
txn);
348 mdb_env_close(sdata->
env);
357 return "lmdb " MDB_VERSION_STRING;
#define mutt_debug(LEVEL,...)
static void store_lmdb_close(StoreHandle **ptr)
Close a Store connection - Implements StoreOps::close() -.
static int store_lmdb_delete_record(StoreHandle *store, const char *key, size_t klen)
Delete a record from the Store - Implements StoreOps::delete_record() -.
static void * store_lmdb_fetch(StoreHandle *store, const char *key, size_t klen, size_t *vlen)
Fetch a Value from the Store - Implements StoreOps::fetch() -.
static void store_lmdb_free(StoreHandle *store, void **ptr)
Free a Value returned by fetch() - Implements StoreOps::free() -.
static StoreHandle * store_lmdb_open(const char *path, bool create)
Open a connection to a Store - Implements StoreOps::open() -.
static int store_lmdb_store(StoreHandle *store, const char *key, size_t klen, void *value, size_t vlen)
Write a Value to the Store - Implements StoreOps::store() -.
static const char * store_lmdb_version(void)
Get a Store version string - Implements StoreOps::version() -.
static struct LmdbStoreData * lmdb_sdata_new(void)
Create new Lmdb Store Data.
static int lmdb_get_write_txn(struct LmdbStoreData *sdata)
Get an LMDB write transaction.
static void lmdb_sdata_free(struct LmdbStoreData **ptr)
Free Lmdb Store Data.
static int lmdb_get_read_txn(struct LmdbStoreData *sdata)
Get an LMDB read transaction.
LmdbTxnMode
The maximum size of the database file (2GiB).
@ TXN_READ
Read transaction in progress.
@ TXN_WRITE
Write transaction in progress.
@ TXN_UNINITIALIZED
Transaction is uninitialised.
@ LL_DEBUG2
Log at debug level 2.
#define MUTT_MEM_CALLOC(n, type)
Convenience wrapper for the library headers.
void StoreHandle
Opaque type for store backend.
#define STORE_BACKEND_OPS(_name)
enum LmdbTxnMode txn_mode