NeoMutt  2021-02-05-666-ge300cd
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 "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 }
 LMDB transaction state. 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...
 

Variables

const size_t LMDB_DB_SIZE = 2147483648
 The maximum size of the database file (2GiB). 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

LMDB transaction state.

Enumerator
TXN_UNINITIALIZED 

Transaction is uninitialised.

TXN_READ 

Read transaction in progress.

TXN_WRITE 

Write transaction in progress.

Definition at line 46 of file lmdb.c.

47 {
49  TXN_READ,
50  TXN_WRITE,
51 };
Write transaction in progress.
Definition: lmdb.c:50
Read transaction in progress.
Definition: lmdb.c:49
Transaction is uninitialised.
Definition: lmdb.c:48

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 69 of file lmdb.c.

70 {
71  int rc;
72 
73  if (ctx->txn && ((ctx->txn_mode == TXN_READ) || (ctx->txn_mode == TXN_WRITE)))
74  return MDB_SUCCESS;
75 
76  if (ctx->txn)
77  rc = mdb_txn_renew(ctx->txn);
78  else
79  rc = mdb_txn_begin(ctx->env, NULL, MDB_RDONLY, &ctx->txn);
80 
81  if (rc == MDB_SUCCESS)
82  ctx->txn_mode = TXN_READ;
83  else
84  {
85  mutt_debug(LL_DEBUG2, "%s: %s\n",
86  ctx->txn ? "mdb_txn_renew" : "mdb_txn_begin", mdb_strerror(rc));
87  }
88 
89  return rc;
90 }
enum MdbTxnMode txn_mode
Definition: lmdb.c:61
MDB_env * env
Definition: lmdb.c:58
MDB_txn * txn
Definition: lmdb.c:59
Log at debug level 2.
Definition: logging.h:41
Write transaction in progress.
Definition: lmdb.c:50
Read transaction in progress.
Definition: lmdb.c:49
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
+ 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 97 of file lmdb.c.

98 {
99  int rc;
100 
101  if (ctx->txn)
102  {
103  if (ctx->txn_mode == TXN_WRITE)
104  return MDB_SUCCESS;
105 
106  /* Free up the memory for readonly or reset transactions */
107  mdb_txn_abort(ctx->txn);
108  }
109 
110  rc = mdb_txn_begin(ctx->env, NULL, 0, &ctx->txn);
111  if (rc == MDB_SUCCESS)
112  ctx->txn_mode = TXN_WRITE;
113  else
114  mutt_debug(LL_DEBUG2, "mdb_txn_begin: %s\n", mdb_strerror(rc));
115 
116  return rc;
117 }
enum MdbTxnMode txn_mode
Definition: lmdb.c:61
MDB_env * env
Definition: lmdb.c:58
MDB_txn * txn
Definition: lmdb.c:59
Log at debug level 2.
Definition: logging.h:41
Write transaction in progress.
Definition: lmdb.c:50
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
+ Here is the caller graph for this function:

Variable Documentation

◆ LMDB_DB_SIZE

const size_t LMDB_DB_SIZE = 2147483648

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

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

Definition at line 41 of file lmdb.c.