Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/bdb.cpp
Show First 20 Lines • Show All 328 Lines • ▼ Show 20 Lines | |||||
void BerkeleyEnvironment::CheckpointLSN(const std::string &strFile) { | void BerkeleyEnvironment::CheckpointLSN(const std::string &strFile) { | ||||
dbenv->txn_checkpoint(0, 0, 0); | dbenv->txn_checkpoint(0, 0, 0); | ||||
if (fMockDb) { | if (fMockDb) { | ||||
return; | return; | ||||
} | } | ||||
dbenv->lsn_reset(strFile.c_str(), 0); | dbenv->lsn_reset(strFile.c_str(), 0); | ||||
} | } | ||||
BerkeleyDatabase::~BerkeleyDatabase() { | |||||
if (env) { | |||||
LOCK(cs_db); | |||||
size_t erased = env->m_databases.erase(strFile); | |||||
assert(erased == 1); | |||||
env->m_fileids.erase(strFile); | |||||
} | |||||
} | |||||
BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase &database, const char *pszMode, | BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase &database, const char *pszMode, | ||||
bool fFlushOnCloseIn) | bool fFlushOnCloseIn) | ||||
: pdb(nullptr), activeTxn(nullptr), m_cursor(nullptr) { | : pdb(nullptr), activeTxn(nullptr), m_cursor(nullptr) { | ||||
fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w')); | fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w')); | ||||
fFlushOnClose = fFlushOnCloseIn; | fFlushOnClose = fFlushOnCloseIn; | ||||
env = database.env.get(); | env = database.env.get(); | ||||
if (database.IsDummy()) { | if (database.IsDummy()) { | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 407 Lines • ▼ Show 20 Lines | while (true) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
UninterruptibleSleep(std::chrono::milliseconds{100}); | UninterruptibleSleep(std::chrono::milliseconds{100}); | ||||
} | } | ||||
} | } | ||||
void BerkeleyDatabase::Flush(bool shutdown) { | void BerkeleyDatabase::Flush() { | ||||
if (!IsDummy()) { | if (!IsDummy()) { | ||||
env->Flush(shutdown); | env->Flush(false); | ||||
if (shutdown) { | |||||
LOCK(cs_db); | |||||
g_dbenvs.erase(env->Directory().string()); | |||||
env = nullptr; | |||||
} else { | |||||
// TODO: To avoid g_dbenvs.erase erasing the environment prematurely | |||||
// after the first database shutdown when multiple databases are | |||||
// open in the same environment, should replace raw database `env` | |||||
// pointers with shared or weak pointers, or else separate the | |||||
// database and environment shutdowns so environments can be shut | |||||
// down after databases. | |||||
env->m_fileids.erase(strFile); | |||||
} | } | ||||
} | } | ||||
void BerkeleyDatabase::Close() { | |||||
if (!IsDummy()) { | |||||
env->Flush(true); | |||||
} | |||||
} | } | ||||
void BerkeleyDatabase::ReloadDbEnv() { | void BerkeleyDatabase::ReloadDbEnv() { | ||||
if (!IsDummy()) { | if (!IsDummy()) { | ||||
env->ReloadDbEnv(); | env->ReloadDbEnv(); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 140 Lines • Show Last 20 Lines |