diff options
author | Andrew Chow <achow101-github@achow101.com> | 2020-06-15 17:59:24 -0400 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2020-07-14 11:07:16 -0400 |
commit | 27b27663849932971eb5deadb1f19234b9cd97ea (patch) | |
tree | f8fa0655e170c4c2b1edbc7eaa440cdc101295a7 /src/wallet/bdb.cpp | |
parent | 834ac4c0f50c0795b55f5586ecc4b1db251be58d (diff) | |
download | bitcoin-27b27663849932971eb5deadb1f19234b9cd97ea.tar.xz |
walletdb: Move BerkeleyDatabase::Flush(true) to Close()
Instead of having Flush optionally shutdown the database and
environment, add a Close() function that does that.
Diffstat (limited to 'src/wallet/bdb.cpp')
-rw-r--r-- | src/wallet/bdb.cpp | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/wallet/bdb.cpp b/src/wallet/bdb.cpp index 44d1bafaf6..0989dc21c3 100644 --- a/src/wallet/bdb.cpp +++ b/src/wallet/bdb.cpp @@ -324,6 +324,15 @@ void BerkeleyEnvironment::CheckpointLSN(const std::string& strFile) 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, bool fFlushOnCloseIn) : pdb(nullptr), activeTxn(nullptr), m_cursor(nullptr) { @@ -685,22 +694,17 @@ bool BerkeleyDatabase::Backup(const std::string& strDest) const } } -void BerkeleyDatabase::Flush(bool shutdown) +void BerkeleyDatabase::Flush() { if (!IsDummy()) { - env->Flush(shutdown); - 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); - } + env->Flush(false); + } +} + +void BerkeleyDatabase::Close() +{ + if (!IsDummy()) { + env->Flush(true); } } |