Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/bdb.cpp
Show First 20 Lines • Show All 356 Lines • ▼ Show 20 Lines | if (fCreate && !Exists(std::string("version"))) { | ||||
bool fTmp = fReadOnly; | bool fTmp = fReadOnly; | ||||
fReadOnly = false; | fReadOnly = false; | ||||
Write(std::string("version"), CLIENT_VERSION); | Write(std::string("version"), CLIENT_VERSION); | ||||
fReadOnly = fTmp; | fReadOnly = fTmp; | ||||
} | } | ||||
} | } | ||||
void BerkeleyDatabase::Open(const char *pszMode) { | void BerkeleyDatabase::Open(const char *pszMode) { | ||||
if (IsDummy()) { | |||||
return; | |||||
} | |||||
bool fCreate = strchr(pszMode, 'c') != nullptr; | bool fCreate = strchr(pszMode, 'c') != nullptr; | ||||
unsigned int nFlags = DB_THREAD; | unsigned int nFlags = DB_THREAD; | ||||
if (fCreate) { | if (fCreate) { | ||||
nFlags |= DB_CREATE; | nFlags |= DB_CREATE; | ||||
} | } | ||||
{ | { | ||||
LOCK(cs_db); | LOCK(cs_db); | ||||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | void BerkeleyEnvironment::ReloadDbEnv() { | ||||
// This will flush and close the environment | // This will flush and close the environment | ||||
Flush(true); | Flush(true); | ||||
Reset(); | Reset(); | ||||
bilingual_str open_err; | bilingual_str open_err; | ||||
Open(open_err); | Open(open_err); | ||||
} | } | ||||
bool BerkeleyDatabase::Rewrite(const char *pszSkip) { | bool BerkeleyDatabase::Rewrite(const char *pszSkip) { | ||||
if (IsDummy()) { | |||||
return true; | |||||
} | |||||
while (true) { | while (true) { | ||||
{ | { | ||||
LOCK(cs_db); | LOCK(cs_db); | ||||
if (m_refcount <= 0) { | if (m_refcount <= 0) { | ||||
// Flush log data to the dat file | // Flush log data to the dat file | ||||
env->CloseDb(strFile); | env->CloseDb(strFile); | ||||
env->CheckpointLSN(strFile); | env->CheckpointLSN(strFile); | ||||
m_refcount = -1; | m_refcount = -1; | ||||
▲ Show 20 Lines • Show All 142 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()) { | |||||
return true; | |||||
} | |||||
// Don't flush if we can't acquire the lock. | // Don't flush if we can't acquire the lock. | ||||
TRY_LOCK(cs_db, lockDb); | TRY_LOCK(cs_db, lockDb); | ||||
if (!lockDb) { | if (!lockDb) { | ||||
return false; | return false; | ||||
} | } | ||||
// Don't flush if any databases are in use | // Don't flush if any databases are in use | ||||
for (auto &it : env->m_databases) { | for (auto &it : env->m_databases) { | ||||
Show All 17 Lines | bool BerkeleyDatabase::PeriodicFlush() { | ||||
LogPrint(BCLog::WALLETDB, "Flushed %s %dms\n", strFile, | LogPrint(BCLog::WALLETDB, "Flushed %s %dms\n", strFile, | ||||
GetTimeMillis() - nStart); | GetTimeMillis() - nStart); | ||||
return true; | return true; | ||||
} | } | ||||
bool BerkeleyDatabase::Backup(const std::string &strDest) const { | bool BerkeleyDatabase::Backup(const std::string &strDest) const { | ||||
if (IsDummy()) { | |||||
return false; | |||||
} | |||||
while (true) { | while (true) { | ||||
{ | { | ||||
LOCK(cs_db); | LOCK(cs_db); | ||||
if (m_refcount <= 0) { | if (m_refcount <= 0) { | ||||
// Flush log data to the dat file | // Flush log data to the dat file | ||||
env->CloseDb(strFile); | env->CloseDb(strFile); | ||||
env->CheckpointLSN(strFile); | env->CheckpointLSN(strFile); | ||||
Show All 23 Lines | while (true) { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
UninterruptibleSleep(std::chrono::milliseconds{100}); | UninterruptibleSleep(std::chrono::milliseconds{100}); | ||||
} | } | ||||
} | } | ||||
void BerkeleyDatabase::Flush() { | void BerkeleyDatabase::Flush() { | ||||
if (!IsDummy()) { | |||||
env->Flush(false); | env->Flush(false); | ||||
} | } | ||||
} | |||||
void BerkeleyDatabase::Close() { | void BerkeleyDatabase::Close() { | ||||
if (!IsDummy()) { | |||||
env->Flush(true); | env->Flush(true); | ||||
} | } | ||||
} | |||||
void BerkeleyDatabase::ReloadDbEnv() { | void BerkeleyDatabase::ReloadDbEnv() { | ||||
if (!IsDummy()) { | |||||
env->ReloadDbEnv(); | env->ReloadDbEnv(); | ||||
} | } | ||||
} | |||||
bool BerkeleyBatch::StartCursor() { | bool BerkeleyBatch::StartCursor() { | ||||
assert(!m_cursor); | assert(!m_cursor); | ||||
if (!pdb) { | if (!pdb) { | ||||
return false; | return false; | ||||
} | } | ||||
int ret = pdb->cursor(nullptr, &m_cursor, 0); | int ret = pdb->cursor(nullptr, &m_cursor, 0); | ||||
return ret == 0; | return ret == 0; | ||||
▲ Show 20 Lines • Show All 150 Lines • Show Last 20 Lines |