NeoMutt  2024-03-23-23-gec7045
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 <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  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)
 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 54 of file lmdb.c.

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

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

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

86{
87 return mutt_mem_calloc(1, sizeof(struct LmdbStoreData));
88}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
LMDB store.
Definition: lmdb.c:65
+ 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 95 of file lmdb.c.

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

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