NeoMutt  2022-04-29-81-g9c5a59
Teaching an old dog new tricks
DOXYGEN
lmdb.c File Reference

Lightning Memory-Mapped Database (LMDB) backend for the key/value Store. More...

#include "config.h"
#include <stddef.h>
#include <lmdb.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "lib.h"
+ Include dependency graph for lmdb.c:

Go to the source code of this file.

Data Structures

struct  StoreLmdbCtx
 LMDB context. More...
 

Enumerations

enum  MdbTxnMode { TXN_UNINITIALIZED , TXN_READ , TXN_WRITE }
 The maximum size of the database file (2GiB). More...
 

Functions

static int mdb_get_r_txn (struct StoreLmdbCtx *ctx)
 Get an LMDB read transaction. More...
 
static int mdb_get_w_txn (struct StoreLmdbCtx *ctx)
 Get an LMDB write transaction. More...
 
static void * store_lmdb_open (const char *path)
 Implements StoreOps::open() -. More...
 
static void * store_lmdb_fetch (void *store, const char *key, size_t klen, size_t *vlen)
 Implements StoreOps::fetch() -. More...
 
static void store_lmdb_free (void *store, void **ptr)
 Implements StoreOps::free() -. More...
 
static int store_lmdb_store (void *store, const char *key, size_t klen, void *value, size_t vlen)
 Implements StoreOps::store() -. More...
 
static int store_lmdb_delete_record (void *store, const char *key, size_t klen)
 Implements StoreOps::delete_record() -. More...
 
static void store_lmdb_close (void **ptr)
 Implements StoreOps::close() -. More...
 
static const char * store_lmdb_version (void)
 Implements StoreOps::version() -. More...
 

Detailed Description

Lightning Memory-Mapped Database (LMDB) backend for the key/value Store.

Authors
  • Thomas Glanzmann
  • Tobias Werth
  • Brian Fundakowski Feldman
  • Pietro Cerutti

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file lmdb.c.

Enumeration Type Documentation

◆ MdbTxnMode

enum MdbTxnMode

The maximum size of the database file (2GiB).

The file is mmap(2)'d into memory. LMDB transaction state

Enumerator
TXN_UNINITIALIZED 

Transaction is uninitialised.

TXN_READ 

Read transaction in progress.

TXN_WRITE 

Write transaction in progress.

Definition at line 55 of file lmdb.c.

56 {
58  TXN_READ,
59  TXN_WRITE,
60 };
@ TXN_READ
Read transaction in progress.
Definition: lmdb.c:58
@ TXN_WRITE
Write transaction in progress.
Definition: lmdb.c:59
@ TXN_UNINITIALIZED
Transaction is uninitialised.
Definition: lmdb.c:57

Function Documentation

◆ mdb_get_r_txn()

static int mdb_get_r_txn ( struct StoreLmdbCtx ctx)
static

Get an LMDB read transaction.

Parameters
ctxLMDB context
Return values
numLMDB return code, e.g. MDB_SUCCESS

Definition at line 78 of file lmdb.c.

79 {
80  int rc;
81 
82  if (ctx->txn && ((ctx->txn_mode == TXN_READ) || (ctx->txn_mode == TXN_WRITE)))
83  return MDB_SUCCESS;
84 
85  if (ctx->txn)
86  rc = mdb_txn_renew(ctx->txn);
87  else
88  rc = mdb_txn_begin(ctx->env, NULL, MDB_RDONLY, &ctx->txn);
89 
90  if (rc == MDB_SUCCESS)
91  ctx->txn_mode = TXN_READ;
92  else
93  {
94  mutt_debug(LL_DEBUG2, "%s: %s\n",
95  ctx->txn ? "mdb_txn_renew" : "mdb_txn_begin", mdb_strerror(rc));
96  }
97 
98  return rc;
99 }
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
MDB_txn * txn
Definition: lmdb.c:68
enum MdbTxnMode txn_mode
Definition: lmdb.c:70
MDB_env * env
Definition: lmdb.c:67
+ Here is the caller graph for this function:

◆ mdb_get_w_txn()

static int mdb_get_w_txn ( struct StoreLmdbCtx ctx)
static

Get an LMDB write transaction.

Parameters
ctxLMDB context
Return values
numLMDB return code, e.g. MDB_SUCCESS

Definition at line 106 of file lmdb.c.

107 {
108  int rc;
109 
110  if (ctx->txn)
111  {
112  if (ctx->txn_mode == TXN_WRITE)
113  return MDB_SUCCESS;
114 
115  /* Free up the memory for readonly or reset transactions */
116  mdb_txn_abort(ctx->txn);
117  }
118 
119  rc = mdb_txn_begin(ctx->env, NULL, 0, &ctx->txn);
120  if (rc == MDB_SUCCESS)
121  ctx->txn_mode = TXN_WRITE;
122  else
123  mutt_debug(LL_DEBUG2, "mdb_txn_begin: %s\n", mdb_strerror(rc));
124 
125  return rc;
126 }
+ Here is the caller graph for this function: