Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/db.cpp
Show First 20 Lines • Show All 596 Lines • ▼ Show 20 Lines | void BerkeleyBatch::Close() { | ||||
} | } | ||||
activeTxn = nullptr; | activeTxn = nullptr; | ||||
pdb = nullptr; | pdb = nullptr; | ||||
if (fFlushOnClose) { | if (fFlushOnClose) { | ||||
Flush(); | Flush(); | ||||
} | } | ||||
{ | |||||
LOCK(cs_db); | LOCK(cs_db); | ||||
--env->mapFileUseCount[strFile]; | --env->mapFileUseCount[strFile]; | ||||
} | } | ||||
env->m_db_in_use.notify_all(); | |||||
} | |||||
void BerkeleyEnvironment::CloseDb(const std::string &strFile) { | void BerkeleyEnvironment::CloseDb(const std::string &strFile) { | ||||
LOCK(cs_db); | LOCK(cs_db); | ||||
if (mapDb[strFile] != nullptr) { | if (mapDb[strFile] != nullptr) { | ||||
// Close the database handle | // Close the database handle | ||||
Db *pdb = mapDb[strFile]; | Db *pdb = mapDb[strFile]; | ||||
pdb->close(0); | pdb->close(0); | ||||
delete pdb; | delete pdb; | ||||
mapDb[strFile] = nullptr; | mapDb[strFile] = nullptr; | ||||
} | } | ||||
} | } | ||||
void BerkeleyEnvironment::ReloadDbEnv() { | |||||
// Make sure that no Db's are in use | |||||
AssertLockNotHeld(cs_db); | |||||
std::unique_lock<CCriticalSection> lock(cs_db); | |||||
m_db_in_use.wait(lock, [this]() { | |||||
for (auto &count : mapFileUseCount) { | |||||
if (count.second > 0) { | |||||
return false; | |||||
} | |||||
} | |||||
return true; | |||||
}); | |||||
std::vector<std::string> filenames; | |||||
for (auto it : mapDb) { | |||||
filenames.push_back(it.first); | |||||
} | |||||
// Close the individual Db's | |||||
for (const std::string &filename : filenames) { | |||||
CloseDb(filename); | |||||
} | |||||
// Reset the environment | |||||
// This will flush and close the environment | |||||
Flush(true); | |||||
Reset(); | |||||
Open(true); | |||||
} | |||||
bool BerkeleyBatch::Rewrite(BerkeleyDatabase &database, const char *pszSkip) { | bool BerkeleyBatch::Rewrite(BerkeleyDatabase &database, const char *pszSkip) { | ||||
if (database.IsDummy()) { | if (database.IsDummy()) { | ||||
return true; | return true; | ||||
} | } | ||||
BerkeleyEnvironment *env = database.env; | BerkeleyEnvironment *env = database.env; | ||||
const std::string &strFile = database.strFile; | const std::string &strFile = database.strFile; | ||||
while (true) { | while (true) { | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | if (!fDbEnvInit) { | ||||
if (fShutdown) { | if (fShutdown) { | ||||
char **listp; | char **listp; | ||||
if (mapFileUseCount.empty()) { | if (mapFileUseCount.empty()) { | ||||
dbenv->log_archive(&listp, DB_ARCH_REMOVE); | dbenv->log_archive(&listp, DB_ARCH_REMOVE); | ||||
Close(); | Close(); | ||||
if (!fMockDb) { | if (!fMockDb) { | ||||
fs::remove_all(fs::path(strPath) / "database"); | fs::remove_all(fs::path(strPath) / "database"); | ||||
} | } | ||||
g_dbenvs.erase(strPath); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
bool BerkeleyBatch::PeriodicFlush(BerkeleyDatabase &database) { | bool BerkeleyBatch::PeriodicFlush(BerkeleyDatabase &database) { | ||||
if (database.IsDummy()) { | if (database.IsDummy()) { | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | while (true) { | ||||
MilliSleep(100); | MilliSleep(100); | ||||
} | } | ||||
} | } | ||||
void BerkeleyDatabase::Flush(bool shutdown) { | void BerkeleyDatabase::Flush(bool shutdown) { | ||||
if (!IsDummy()) { | if (!IsDummy()) { | ||||
env->Flush(shutdown); | env->Flush(shutdown); | ||||
if (shutdown) { | if (shutdown) { | ||||
LOCK(cs_db); | |||||
g_dbenvs.erase(env->Directory().string()); | |||||
env = nullptr; | env = nullptr; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void BerkeleyDatabase::ReloadDbEnv() { | |||||
if (!IsDummy()) { | |||||
env->ReloadDbEnv(); | |||||
} | |||||
} |