NeoMutt  2024-04-25-85-g27bab4
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 <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 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

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

78{
79 FREE(ptr);
80}
#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 86 of file lmdb.c.

87{
88 return mutt_mem_calloc(1, sizeof(struct LmdbStoreData));
89}
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:66
+ 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 96 of file lmdb.c.

97{
98 int rc;
99
100 if (sdata->txn && ((sdata->txn_mode == TXN_READ) || (sdata->txn_mode == TXN_WRITE)))
101 return MDB_SUCCESS;
102
103 if (sdata->txn)
104 rc = mdb_txn_renew(sdata->txn);
105 else
106 rc = mdb_txn_begin(sdata->env, NULL, MDB_RDONLY, &sdata->txn);
107
108 if (rc == MDB_SUCCESS)
109 {
110 sdata->txn_mode = TXN_READ;
111 }
112 else
113 {
114 mutt_debug(LL_DEBUG2, "%s: %s\n",
115 sdata->txn ? "mdb_txn_renew" : "mdb_txn_begin", mdb_strerror(rc));
116 }
117
118 return rc;
119}
#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:68
MDB_env * env
Definition: lmdb.c:67
enum LmdbTxnMode txn_mode
Definition: lmdb.c:70
+ 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 126 of file lmdb.c.

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