Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/bdb.cpp
Show First 20 Lines • Show All 681 Lines • ▼ Show 20 Lines | if (!fDbEnvInit) { | ||||
fs::remove_all(fs::path(strPath) / "database"); | fs::remove_all(fs::path(strPath) / "database"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
bool BerkeleyDatabase::PeriodicFlush() { | bool BerkeleyDatabase::PeriodicFlush() { | ||||
// There's nothing to do for dummy databases. Return true. | |||||
if (IsDummy()) { | if (IsDummy()) { | ||||
return true; | return true; | ||||
} | } | ||||
bool ret = false; | |||||
// Don't flush if we can't acquire the lock. | |||||
TRY_LOCK(cs_db, lockDb); | TRY_LOCK(cs_db, lockDb); | ||||
if (lockDb) { | if (!lockDb) { | ||||
// Don't do this if any databases are in use | return false; | ||||
int nRefCount = 0; | } | ||||
std::map<std::string, int>::iterator mit = env->mapFileUseCount.begin(); | |||||
while (mit != env->mapFileUseCount.end()) { | // Don't flush if any databases are in use | ||||
nRefCount += (*mit).second; | for (auto it = env->mapFileUseCount.begin(); | ||||
mit++; | it != env->mapFileUseCount.end(); it++) { | ||||
if ((*it).second > 0) { | |||||
return false; | |||||
} | |||||
} | |||||
// Don't flush if there haven't been any batch writes for this database. | |||||
auto it = env->mapFileUseCount.find(strFile); | |||||
if (it == env->mapFileUseCount.end()) { | |||||
return false; | |||||
} | } | ||||
if (nRefCount == 0) { | |||||
std::map<std::string, int>::iterator mi = | |||||
env->mapFileUseCount.find(strFile); | |||||
if (mi != env->mapFileUseCount.end()) { | |||||
LogPrint(BCLog::WALLETDB, "Flushing %s\n", strFile); | LogPrint(BCLog::WALLETDB, "Flushing %s\n", strFile); | ||||
int64_t nStart = GetTimeMillis(); | int64_t nStart = GetTimeMillis(); | ||||
// Flush wallet file so it's self contained | // Flush wallet file so it's self contained | ||||
env->CloseDb(strFile); | env->CloseDb(strFile); | ||||
env->CheckpointLSN(strFile); | env->CheckpointLSN(strFile); | ||||
env->mapFileUseCount.erase(it); | |||||
env->mapFileUseCount.erase(mi++); | |||||
LogPrint(BCLog::WALLETDB, "Flushed %s %dms\n", strFile, | LogPrint(BCLog::WALLETDB, "Flushed %s %dms\n", strFile, | ||||
GetTimeMillis() - nStart); | GetTimeMillis() - nStart); | ||||
ret = true; | |||||
} | |||||
} | |||||
} | |||||
return ret; | return true; | ||||
} | } | ||||
bool BerkeleyDatabase::Backup(const std::string &strDest) const { | bool BerkeleyDatabase::Backup(const std::string &strDest) const { | ||||
if (IsDummy()) { | if (IsDummy()) { | ||||
return false; | return false; | ||||
} | } | ||||
while (true) { | while (true) { | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 126 Lines • Show Last 20 Lines |