diff options
Diffstat (limited to 'src/db.cpp')
-rw-r--r-- | src/db.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/db.cpp b/src/db.cpp index 907dba535f..3133d99bf8 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -38,7 +38,7 @@ void CDBEnv::EnvShutdown() if (ret != 0) printf("EnvShutdown exception: %s (%d)\n", DbEnv::strerror(ret), ret); if (!fMockDb) - DbEnv(0).remove(strPath.c_str(), 0); + DbEnv(0).remove(path.string().c_str(), 0); } CDBEnv::CDBEnv() : dbenv(DB_CXX_NO_EXCEPTIONS) @@ -57,15 +57,14 @@ void CDBEnv::Close() EnvShutdown(); } -bool CDBEnv::Open(const boost::filesystem::path& path) +bool CDBEnv::Open(const boost::filesystem::path& pathIn) { if (fDbEnvInit) return true; - if (fShutdown) - return false; + boost::this_thread::interruption_point(); - strPath = path.string(); + path = pathIn; filesystem::path pathLogDir = path / "database"; filesystem::create_directory(pathLogDir); filesystem::path pathErrorFile = path / "db.log"; @@ -75,18 +74,17 @@ bool CDBEnv::Open(const boost::filesystem::path& path) if (GetBoolArg("-privdb", true)) nEnvFlags |= DB_PRIVATE; - unsigned int nDbCache = GetArg("-dbcache", 25); dbenv.set_lg_dir(pathLogDir.string().c_str()); - dbenv.set_cachesize(nDbCache / 1024, (nDbCache % 1024)*1048576, 1); - dbenv.set_lg_bsize(1048576); - dbenv.set_lg_max(10485760); + dbenv.set_cachesize(0, 0x100000, 1); // 1 MiB should be enough for just the wallet + dbenv.set_lg_bsize(0x10000); + dbenv.set_lg_max(1048576); dbenv.set_lk_max_locks(40000); dbenv.set_lk_max_objects(40000); dbenv.set_errfile(fopen(pathErrorFile.string().c_str(), "a")); /// debug dbenv.set_flags(DB_AUTO_COMMIT, 1); dbenv.set_flags(DB_TXN_WRITE_NOSYNC, 1); dbenv.log_set_config(DB_LOG_AUTO_REMOVE, 1); - int ret = dbenv.open(strPath.c_str(), + int ret = dbenv.open(path.string().c_str(), DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | @@ -109,8 +107,7 @@ void CDBEnv::MakeMock() if (fDbEnvInit) throw runtime_error("CDBEnv::MakeMock(): already initialized"); - if (fShutdown) - throw runtime_error("CDBEnv::MakeMock(): during shutdown"); + boost::this_thread::interruption_point(); printf("CDBEnv::MakeMock()\n"); @@ -337,7 +334,7 @@ bool CDBEnv::RemoveDb(const string& strFile) bool CDB::Rewrite(const string& strFile, const char* pszSkip) { - while (!fShutdown) + while (true) { { LOCK(bitdb.cs_db); @@ -423,7 +420,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) return fSuccess; } } - Sleep(100); + MilliSleep(100); } return false; } @@ -468,6 +465,8 @@ void CDBEnv::Flush(bool fShutdown) { dbenv.log_archive(&listp, DB_ARCH_REMOVE); Close(); + if (!fMockDb) + boost::filesystem::remove_all(path / "database"); } } } |