MCPcopy Create free account
hub / github.com/LUX-Core/lux / CDB

Method CDB

src/db.cpp:271–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269}
270
271CDB::CDB(const std::string& strFilename, const char* pszMode, bool fFlushOnCloseIn) : pdb(NULL), activeTxn(NULL)
272{
273 int ret;
274 fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w'));
275 fFlushOnClose = fFlushOnCloseIn;
276 if (strFilename.empty())
277 return;
278
279 bool fCreate = strchr(pszMode, 'c') != NULL;
280 unsigned int nFlags = DB_THREAD;
281 if (fCreate)
282 nFlags |= DB_CREATE;
283
284 {
285 LOCK(bitdb.cs_db);
286 if (!bitdb.Open(GetDataDir()))
287 throw runtime_error("CDB : Failed to open database environment.");
288
289 strFile = strFilename;
290 ++bitdb.mapFileUseCount[strFile];
291 pdb = bitdb.mapDb[strFile];
292 if (pdb == NULL) {
293 pdb = new Db(bitdb.dbenv, 0);
294
295 bool fMockDb = bitdb.IsMock();
296 if (fMockDb) {
297 DbMpoolFile* mpf = pdb->get_mpf();
298 ret = mpf->set_flags(DB_MPOOL_NOFILE, 1);
299 if (ret != 0)
300 throw runtime_error(strprintf("CDB : Failed to configure for no temp file backing for database %s", strFile));
301 }
302
303 ret = pdb->open(NULL, // Txn pointer
304 fMockDb ? NULL : strFile.c_str(), // Filename
305 fMockDb ? strFile.c_str() : "main", // Logical db name
306 DB_BTREE, // Database type
307 nFlags, // Flags
308 0);
309
310 if (ret != 0) {
311 delete pdb;
312 pdb = NULL;
313 --bitdb.mapFileUseCount[strFile];
314 strFile = "";
315 throw runtime_error(strprintf("CDB : Error %d, can't open database %s", ret, strFile));
316 }
317
318 if (fCreate && !Exists(string("version"))) {
319 bool fTmp = fReadOnly;
320 fReadOnly = false;
321 WriteVersion(CLIENT_VERSION);
322 fReadOnly = fTmp;
323 }
324
325 bitdb.mapDb[strFile] = pdb;
326 }
327 }
328}

Callers

nothing calls this directly

Calls 4

IsMockMethod · 0.80
emptyMethod · 0.45
OpenMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected