NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches

Open a connection to a Store. More...

+ Collaboration diagram for open():

Functions

static StoreHandlestore_gdbm_open (const char *path, bool create)
 Open a connection to a Store - Implements StoreOps::open() -.
 
static StoreHandlestore_lmdb_open (const char *path, bool create)
 Open a connection to a Store - Implements StoreOps::open() -.
 
static StoreHandlestore_rocksdb_open (const char *path, bool create)
 Open a connection to a Store - Implements StoreOps::open() -.
 
static StoreHandlestore_tdb_open (const char *path, bool create)
 Open a connection to a Store - Implements StoreOps::open() -.
 

Detailed Description

Open a connection to a Store.

Parameters
[in]pathPath to the database file
[in]createCreate the file if it's not there?
Return values
ptrSuccess, Store pointer
NULLFailure

The open function has the purpose of opening a backend-specific connection to the database file specified by the path parameter. Backends MUST return non-NULL specific handle information on success.

Function Documentation

◆ store_gdbm_open()

static StoreHandle * store_gdbm_open ( const char * path,
bool create )
static

Open a connection to a Store - Implements StoreOps::open() -.

Definition at line 42 of file gdbm.c.

43{
44 if (!path)
45 return NULL;
46
47 const int pagesize = 4096;
48
49 GDBM_FILE db = gdbm_open((char *) path, pagesize,
50 create ? GDBM_WRCREAT : GDBM_WRITER, 00600, NULL);
51 if (!db)
52 {
53 /* if rw failed try ro */
54 db = gdbm_open((char *) path, pagesize, GDBM_READER, 00600, NULL);
55 }
56
57 // Return an opaque pointer
58 return (StoreHandle *) db;
59}
void StoreHandle
Opaque type for store backend.
Definition lib.h:58

◆ store_lmdb_open()

static StoreHandle * store_lmdb_open ( const char * path,
bool create )
static

Open a connection to a Store - Implements StoreOps::open() -.

Definition at line 150 of file lmdb.c.

151{
152 if (!path)
153 return NULL;
154
155 if (!create && access(path, F_OK) != 0)
156 {
157 return NULL;
158 }
159
160 struct LmdbStoreData *sdata = lmdb_sdata_new();
161
162 int rc = mdb_env_create(&sdata->env);
163 if (rc != MDB_SUCCESS)
164 {
165 mutt_debug(LL_DEBUG2, "mdb_env_create: %s\n", mdb_strerror(rc));
166 lmdb_sdata_free(&sdata);
167 return NULL;
168 }
169
170 mdb_env_set_mapsize(sdata->env, LMDB_DB_SIZE);
171
172 rc = mdb_env_open(sdata->env, path, MDB_NOSUBDIR, 0600);
173 if (rc != MDB_SUCCESS)
174 {
175 mutt_debug(LL_DEBUG2, "mdb_env_open: %s\n", mdb_strerror(rc));
176 goto fail_env;
177 }
178
179 rc = lmdb_get_read_txn(sdata);
180 if (rc != MDB_SUCCESS)
181 {
182 mutt_debug(LL_DEBUG2, "mdb_txn_begin: %s\n", mdb_strerror(rc));
183 goto fail_env;
184 }
185
186 rc = mdb_dbi_open(sdata->txn, NULL, MDB_CREATE, &sdata->db);
187 if (rc != MDB_SUCCESS)
188 {
189 mutt_debug(LL_DEBUG2, "mdb_dbi_open: %s\n", mdb_strerror(rc));
190 goto fail_dbi;
191 }
192
193 mdb_txn_reset(sdata->txn);
195 // Return an opaque pointer
196 return (StoreHandle *) sdata;
197
198fail_dbi:
199 mdb_txn_abort(sdata->txn);
201 sdata->txn = NULL;
202
203fail_env:
204 mdb_env_close(sdata->env);
205 lmdb_sdata_free(&sdata);
206 return NULL;
207}
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static struct LmdbStoreData * lmdb_sdata_new(void)
Create new Lmdb Store Data.
Definition lmdb.c:87
static void lmdb_sdata_free(struct LmdbStoreData **ptr)
Free Lmdb Store Data.
Definition lmdb.c:78
static int lmdb_get_read_txn(struct LmdbStoreData *sdata)
Get an LMDB read transaction.
Definition lmdb.c:97
@ TXN_UNINITIALIZED
Transaction is uninitialised.
Definition lmdb.c:58
@ LL_DEBUG2
Log at debug level 2.
Definition logging2.h:46
LMDB store.
Definition lmdb.c:67
MDB_txn * txn
LMDB transaction.
Definition lmdb.c:69
MDB_env * env
LMDB environment.
Definition lmdb.c:68
MDB_dbi db
LMDB database.
Definition lmdb.c:70
enum LmdbTxnMode txn_mode
Transaction mode.
Definition lmdb.c:71
+ Here is the call graph for this function:

◆ store_rocksdb_open()

static StoreHandle * store_rocksdb_open ( const char * path,
bool create )
static

Open a connection to a Store - Implements StoreOps::open() -.

Definition at line 77 of file rocksdb.c.

78{
79 if (!path)
80 return NULL;
81
82 struct RocksDbStoreData *sdata = rocksdb_sdata_new();
83
84 /* RocksDB stores errors in form of strings */
85 sdata->err = NULL;
86
87 /* setup generic options, create new db and limit log to one file */
88 sdata->options = rocksdb_options_create();
89 if (create)
90 {
91 rocksdb_options_set_create_if_missing(sdata->options, 1);
92 }
93 rocksdb_options_set_keep_log_file_num(sdata->options, 1);
94
95 /* setup read options, we verify with checksums */
96 sdata->read_options = rocksdb_readoptions_create();
97 rocksdb_readoptions_set_verify_checksums(sdata->read_options, 1);
98
99 /* setup write options, no sync needed, disable WAL */
100 sdata->write_options = rocksdb_writeoptions_create();
101 rocksdb_writeoptions_set_sync(sdata->write_options, 0);
102 rocksdb_writeoptions_disable_WAL(sdata->write_options, 1);
103
104 rocksdb_options_set_compression(sdata->options, rocksdb_no_compression);
105
106 /* open database and check for error in sdata->error */
107 sdata->db = rocksdb_open(sdata->options, path, &sdata->err);
108 if (sdata->err)
109 {
110 rocksdb_options_destroy(sdata->options);
111 rocksdb_readoptions_destroy(sdata->read_options);
112 rocksdb_writeoptions_destroy(sdata->write_options);
113 rocksdb_sdata_free(&sdata);
114 return NULL;
115 }
116
117 // Return an opaque pointer
118 return (StoreHandle *) sdata;
119}
static struct RocksDbStoreData * rocksdb_sdata_new(void)
Create new RocksDb Store Data.
Definition rocksdb.c:69
static void rocksdb_sdata_free(struct RocksDbStoreData **ptr)
Free RocksDb Store Data.
Definition rocksdb.c:54
RocksDB store.
Definition rocksdb.c:42
rocksdb_options_t * options
Database options.
Definition rocksdb.c:44
rocksdb_t * db
RocksDB database.
Definition rocksdb.c:43
rocksdb_readoptions_t * read_options
Read options.
Definition rocksdb.c:45
rocksdb_writeoptions_t * write_options
Write options.
Definition rocksdb.c:46
char * err
Error message.
Definition rocksdb.c:47
+ Here is the call graph for this function:

◆ store_tdb_open()

static StoreHandle * store_tdb_open ( const char * path,
bool create )
static

Open a connection to a Store - Implements StoreOps::open() -.

Definition at line 42 of file tdb.c.

43{
44 if (!path)
45 return NULL;
46
47 /* TDB_NOLOCK - Don't do any locking
48 * TDB_NOSYNC - Don't use synchronous transactions
49 * TDB_INCOMPATIBLE_HASH - Better hashing
50 */
51 const int flags = TDB_NOLOCK | TDB_INCOMPATIBLE_HASH | TDB_NOSYNC;
52 const int hash_size = 33533; // Based on test timings for 100K emails
53
54 struct tdb_context *db = tdb_open(path, hash_size, flags,
55 (create ? O_CREAT : 0) | O_RDWR, 00600);
56
57 // Return an opaque pointer
58 return (StoreHandle *) db;
59}