Open a connection to a Store.
More...
Open a connection to a Store.
- Parameters
-
| [in] | path | Path to the database file |
| [in] | create | Create the file if it's not there? |
- Return values
-
| ptr | Success, Store pointer |
| NULL | Failure |
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.
◆ 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
54 db = gdbm_open((char *) path, pagesize, GDBM_READER, 00600, NULL);
55 }
56
57
59}
void StoreHandle
Opaque type for store backend.
◆ 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
161
162 int rc = mdb_env_create(&sdata->
env);
163 if (rc != MDB_SUCCESS)
164 {
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 {
176 goto fail_env;
177 }
178
180 if (rc != MDB_SUCCESS)
181 {
183 goto fail_env;
184 }
185
186 rc = mdb_dbi_open(sdata->
txn, NULL, MDB_CREATE, &sdata->
db);
187 if (rc != MDB_SUCCESS)
188 {
190 goto fail_dbi;
191 }
192
193 mdb_txn_reset(sdata->
txn);
195
197
198fail_dbi:
199 mdb_txn_abort(sdata->
txn);
202
203fail_env:
204 mdb_env_close(sdata->
env);
206 return NULL;
207}
#define mutt_debug(LEVEL,...)
static struct LmdbStoreData * lmdb_sdata_new(void)
Create new Lmdb Store Data.
static void lmdb_sdata_free(struct LmdbStoreData **ptr)
Free Lmdb Store Data.
static int lmdb_get_read_txn(struct LmdbStoreData *sdata)
Get an LMDB read transaction.
@ TXN_UNINITIALIZED
Transaction is uninitialised.
@ LL_DEBUG2
Log at debug level 2.
MDB_txn * txn
LMDB transaction.
MDB_env * env
LMDB environment.
enum LmdbTxnMode txn_mode
Transaction mode.
◆ 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
83
84
86
87
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
97 rocksdb_readoptions_set_verify_checksums(sdata->
read_options, 1);
98
99
103
104 rocksdb_options_set_compression(sdata->
options, rocksdb_no_compression);
105
106
107 sdata->
db = rocksdb_open(sdata->
options, path, &sdata->
err);
109 {
110 rocksdb_options_destroy(sdata->
options);
114 return NULL;
115 }
116
117
119}
static struct RocksDbStoreData * rocksdb_sdata_new(void)
Create new RocksDb Store Data.
static void rocksdb_sdata_free(struct RocksDbStoreData **ptr)
Free RocksDb Store Data.
rocksdb_options_t * options
Database options.
rocksdb_t * db
RocksDB database.
rocksdb_readoptions_t * read_options
Read options.
rocksdb_writeoptions_t * write_options
Write options.
◆ 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
48
49
50
51 const int flags = TDB_NOLOCK | TDB_INCOMPATIBLE_HASH | TDB_NOSYNC;
52 const int hash_size = 33533;
53
54 struct tdb_context *db = tdb_open(path, hash_size, flags,
55 (create ? O_CREAT : 0) | O_RDWR, 00600);
56
57
59}