NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lmdb.c File Reference

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

#include "config.h"
#include <lmdb.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <unistd.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  LmdbStoreData
 LMDB store. More...
 

Enumerations

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

Functions

static void lmdb_sdata_free (struct LmdbStoreData **ptr)
 Free Lmdb Store Data.
 
static struct LmdbStoreDatalmdb_sdata_new (void)
 Create new Lmdb Store Data.
 
static int lmdb_get_read_txn (struct LmdbStoreData *sdata)
 Get an LMDB read transaction.
 
static int lmdb_get_write_txn (struct LmdbStoreData *sdata)
 Get an LMDB write transaction.
 
static StoreHandlestore_lmdb_open (const char *path, bool create)
 Open a connection to a Store - Implements StoreOps::open() -.
 
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 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 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_close (StoreHandle **ptr)
 Close a Store connection - Implements StoreOps::close() -.
 
static const char * store_lmdb_version (void)
 Get a Store version string - Implements StoreOps::version() -.
 

Detailed Description

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

Authors
  • Pietro Cerutti
  • Richard Russon
  • Ian Zimmerman

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

◆ LmdbTxnMode

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

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

Function Documentation

◆ lmdb_sdata_free()

static void lmdb_sdata_free ( struct LmdbStoreData **  ptr)
static

Free Lmdb Store Data.

Parameters
ptrLmdb Store Data to free

Definition at line 78 of file lmdb.c.

79{
80 FREE(ptr);
81}
#define FREE(x)
Definition: memory.h:45
+ Here is the caller graph for this function:

◆ lmdb_sdata_new()

static struct LmdbStoreData * lmdb_sdata_new ( void  )
static

Create new Lmdb Store Data.

Return values
ptrNew Lmdb Store Data

Definition at line 87 of file lmdb.c.

88{
89 return mutt_mem_calloc(1, sizeof(struct LmdbStoreData));
90}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
LMDB store.
Definition: lmdb.c:67
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lmdb_get_read_txn()

static int lmdb_get_read_txn ( struct LmdbStoreData sdata)
static

Get an LMDB read transaction.

Parameters
sdataLMDB store
Return values
numLMDB return code, e.g. MDB_SUCCESS

Definition at line 97 of file lmdb.c.

98{
99 int rc;
100
101 if (sdata->txn && ((sdata->txn_mode == TXN_READ) || (sdata->txn_mode == TXN_WRITE)))
102 return MDB_SUCCESS;
103
104 if (sdata->txn)
105 rc = mdb_txn_renew(sdata->txn);
106 else
107 rc = mdb_txn_begin(sdata->env, NULL, MDB_RDONLY, &sdata->txn);
108
109 if (rc == MDB_SUCCESS)
110 {
111 sdata->txn_mode = TXN_READ;
112 }
113 else
114 {
115 mutt_debug(LL_DEBUG2, "%s: %s\n",
116 sdata->txn ? "mdb_txn_renew" : "mdb_txn_begin", mdb_strerror(rc));
117 }
118
119 return rc;
120}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
MDB_txn * txn
Definition: lmdb.c:69
MDB_env * env
Definition: lmdb.c:68
enum LmdbTxnMode txn_mode
Definition: lmdb.c:71
+ Here is the caller graph for this function:

◆ lmdb_get_write_txn()

static int lmdb_get_write_txn ( struct LmdbStoreData sdata)
static

Get an LMDB write transaction.

Parameters
sdataLMDB store
Return values
numLMDB return code, e.g. MDB_SUCCESS

Definition at line 127 of file lmdb.c.

128{
129 if (sdata->txn)
130 {
131 if (sdata->txn_mode == TXN_WRITE)
132 return MDB_SUCCESS;
133
134 /* Free up the memory for readonly or reset transactions */
135 mdb_txn_abort(sdata->txn);
136 }
137
138 int rc = mdb_txn_begin(sdata->env, NULL, 0, &sdata->txn);
139 if (rc == MDB_SUCCESS)
140 sdata->txn_mode = TXN_WRITE;
141 else
142 mutt_debug(LL_DEBUG2, "mdb_txn_begin: %s\n", mdb_strerror(rc));
143
144 return rc;
145}
+ Here is the caller graph for this function: