|
|
|
@ -39,22 +39,31 @@ void CDBEnv::EnvShutdown()
@@ -39,22 +39,31 @@ void CDBEnv::EnvShutdown()
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
fDbEnvInit = false; |
|
|
|
|
int ret = dbenv.close(0); |
|
|
|
|
int ret = dbenv->close(0); |
|
|
|
|
if (ret != 0) |
|
|
|
|
LogPrintf("CDBEnv::EnvShutdown: Error %d shutting down database environment: %s\n", ret, DbEnv::strerror(ret)); |
|
|
|
|
if (!fMockDb) |
|
|
|
|
DbEnv(0).remove(path.string().c_str(), 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CDBEnv::CDBEnv() : dbenv(DB_CXX_NO_EXCEPTIONS) |
|
|
|
|
void CDBEnv::Reset() |
|
|
|
|
{ |
|
|
|
|
delete dbenv; |
|
|
|
|
dbenv = new DbEnv(DB_CXX_NO_EXCEPTIONS); |
|
|
|
|
fDbEnvInit = false; |
|
|
|
|
fMockDb = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CDBEnv::CDBEnv() : dbenv(NULL) |
|
|
|
|
{ |
|
|
|
|
Reset(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CDBEnv::~CDBEnv() |
|
|
|
|
{ |
|
|
|
|
EnvShutdown(); |
|
|
|
|
delete dbenv; |
|
|
|
|
dbenv = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CDBEnv::Close() |
|
|
|
@ -79,17 +88,17 @@ bool CDBEnv::Open(const boost::filesystem::path& pathIn)
@@ -79,17 +88,17 @@ bool CDBEnv::Open(const boost::filesystem::path& pathIn)
|
|
|
|
|
if (GetBoolArg("-privdb", true)) |
|
|
|
|
nEnvFlags |= DB_PRIVATE; |
|
|
|
|
|
|
|
|
|
dbenv.set_lg_dir(pathLogDir.string().c_str()); |
|
|
|
|
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(path.string().c_str(), |
|
|
|
|
dbenv->set_lg_dir(pathLogDir.string().c_str()); |
|
|
|
|
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(path.string().c_str(), |
|
|
|
|
DB_CREATE | |
|
|
|
|
DB_INIT_LOCK | |
|
|
|
|
DB_INIT_LOG | |
|
|
|
@ -116,14 +125,14 @@ void CDBEnv::MakeMock()
@@ -116,14 +125,14 @@ void CDBEnv::MakeMock()
|
|
|
|
|
|
|
|
|
|
LogPrint("db", "CDBEnv::MakeMock\n"); |
|
|
|
|
|
|
|
|
|
dbenv.set_cachesize(1, 0, 1); |
|
|
|
|
dbenv.set_lg_bsize(10485760 * 4); |
|
|
|
|
dbenv.set_lg_max(10485760); |
|
|
|
|
dbenv.set_lk_max_locks(10000); |
|
|
|
|
dbenv.set_lk_max_objects(10000); |
|
|
|
|
dbenv.set_flags(DB_AUTO_COMMIT, 1); |
|
|
|
|
dbenv.log_set_config(DB_LOG_IN_MEMORY, 1); |
|
|
|
|
int ret = dbenv.open(NULL, |
|
|
|
|
dbenv->set_cachesize(1, 0, 1); |
|
|
|
|
dbenv->set_lg_bsize(10485760 * 4); |
|
|
|
|
dbenv->set_lg_max(10485760); |
|
|
|
|
dbenv->set_lk_max_locks(10000); |
|
|
|
|
dbenv->set_lk_max_objects(10000); |
|
|
|
|
dbenv->set_flags(DB_AUTO_COMMIT, 1); |
|
|
|
|
dbenv->log_set_config(DB_LOG_IN_MEMORY, 1); |
|
|
|
|
int ret = dbenv->open(NULL, |
|
|
|
|
DB_CREATE | |
|
|
|
|
DB_INIT_LOCK | |
|
|
|
|
DB_INIT_LOG | |
|
|
|
@ -144,7 +153,7 @@ CDBEnv::VerifyResult CDBEnv::Verify(std::string strFile, bool (*recoverFunc)(CDB
@@ -144,7 +153,7 @@ CDBEnv::VerifyResult CDBEnv::Verify(std::string strFile, bool (*recoverFunc)(CDB
|
|
|
|
|
LOCK(cs_db); |
|
|
|
|
assert(mapFileUseCount.count(strFile) == 0); |
|
|
|
|
|
|
|
|
|
Db db(&dbenv, 0); |
|
|
|
|
Db db(dbenv, 0); |
|
|
|
|
int result = db.verify(strFile.c_str(), NULL, NULL, 0); |
|
|
|
|
if (result == 0) |
|
|
|
|
return VERIFY_OK; |
|
|
|
@ -167,7 +176,7 @@ bool CDBEnv::Salvage(std::string strFile, bool fAggressive, std::vector<CDBEnv::
@@ -167,7 +176,7 @@ bool CDBEnv::Salvage(std::string strFile, bool fAggressive, std::vector<CDBEnv::
|
|
|
|
|
|
|
|
|
|
stringstream strDump; |
|
|
|
|
|
|
|
|
|
Db db(&dbenv, 0); |
|
|
|
|
Db db(dbenv, 0); |
|
|
|
|
int result = db.verify(strFile.c_str(), NULL, &strDump, flags); |
|
|
|
|
if (result == DB_VERIFY_BAD) { |
|
|
|
|
LogPrintf("CDBEnv::Salvage: Database salvage found errors, all data may not be recoverable.\n"); |
|
|
|
@ -208,10 +217,10 @@ bool CDBEnv::Salvage(std::string strFile, bool fAggressive, std::vector<CDBEnv::
@@ -208,10 +217,10 @@ bool CDBEnv::Salvage(std::string strFile, bool fAggressive, std::vector<CDBEnv::
|
|
|
|
|
|
|
|
|
|
void CDBEnv::CheckpointLSN(const std::string& strFile) |
|
|
|
|
{ |
|
|
|
|
dbenv.txn_checkpoint(0, 0, 0); |
|
|
|
|
dbenv->txn_checkpoint(0, 0, 0); |
|
|
|
|
if (fMockDb) |
|
|
|
|
return; |
|
|
|
|
dbenv.lsn_reset(strFile.c_str(), 0); |
|
|
|
|
dbenv->lsn_reset(strFile.c_str(), 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -237,7 +246,7 @@ CDB::CDB(const std::string& strFilename, const char* pszMode, bool fFlushOnClose
@@ -237,7 +246,7 @@ CDB::CDB(const std::string& strFilename, const char* pszMode, bool fFlushOnClose
|
|
|
|
|
++bitdb.mapFileUseCount[strFile]; |
|
|
|
|
pdb = bitdb.mapDb[strFile]; |
|
|
|
|
if (pdb == NULL) { |
|
|
|
|
pdb = new Db(&bitdb.dbenv, 0); |
|
|
|
|
pdb = new Db(bitdb.dbenv, 0); |
|
|
|
|
|
|
|
|
|
bool fMockDb = bitdb.IsMock(); |
|
|
|
|
if (fMockDb) { |
|
|
|
@ -284,7 +293,7 @@ void CDB::Flush()
@@ -284,7 +293,7 @@ void CDB::Flush()
|
|
|
|
|
if (fReadOnly) |
|
|
|
|
nMinutes = 1; |
|
|
|
|
|
|
|
|
|
bitdb.dbenv.txn_checkpoint(nMinutes ? GetArg("-dblogsize", 100) * 1024 : 0, nMinutes, 0); |
|
|
|
|
bitdb.dbenv->txn_checkpoint(nMinutes ? GetArg("-dblogsize", 100) * 1024 : 0, nMinutes, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CDB::Close() |
|
|
|
@ -324,7 +333,7 @@ bool CDBEnv::RemoveDb(const string& strFile)
@@ -324,7 +333,7 @@ bool CDBEnv::RemoveDb(const string& strFile)
|
|
|
|
|
this->CloseDb(strFile); |
|
|
|
|
|
|
|
|
|
LOCK(cs_db); |
|
|
|
|
int rc = dbenv.dbremove(NULL, strFile.c_str(), NULL, DB_AUTO_COMMIT); |
|
|
|
|
int rc = dbenv->dbremove(NULL, strFile.c_str(), NULL, DB_AUTO_COMMIT); |
|
|
|
|
return (rc == 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -344,7 +353,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
@@ -344,7 +353,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
|
|
|
|
|
string strFileRes = strFile + ".rewrite"; |
|
|
|
|
{ // surround usage of db with extra {}
|
|
|
|
|
CDB db(strFile.c_str(), "r"); |
|
|
|
|
Db* pdbCopy = new Db(&bitdb.dbenv, 0); |
|
|
|
|
Db* pdbCopy = new Db(bitdb.dbenv, 0); |
|
|
|
|
|
|
|
|
|
int ret = pdbCopy->open(NULL, // Txn pointer
|
|
|
|
|
strFileRes.c_str(), // Filename
|
|
|
|
@ -394,10 +403,10 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
@@ -394,10 +403,10 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (fSuccess) { |
|
|
|
|
Db dbA(&bitdb.dbenv, 0); |
|
|
|
|
Db dbA(bitdb.dbenv, 0); |
|
|
|
|
if (dbA.remove(strFile.c_str(), NULL, 0)) |
|
|
|
|
fSuccess = false; |
|
|
|
|
Db dbB(&bitdb.dbenv, 0); |
|
|
|
|
Db dbB(bitdb.dbenv, 0); |
|
|
|
|
if (dbB.rename(strFileRes.c_str(), NULL, strFile.c_str(), 0)) |
|
|
|
|
fSuccess = false; |
|
|
|
|
} |
|
|
|
@ -430,10 +439,10 @@ void CDBEnv::Flush(bool fShutdown)
@@ -430,10 +439,10 @@ void CDBEnv::Flush(bool fShutdown)
|
|
|
|
|
// Move log data to the dat file
|
|
|
|
|
CloseDb(strFile); |
|
|
|
|
LogPrint("db", "CDBEnv::Flush: %s checkpoint\n", strFile); |
|
|
|
|
dbenv.txn_checkpoint(0, 0, 0); |
|
|
|
|
dbenv->txn_checkpoint(0, 0, 0); |
|
|
|
|
LogPrint("db", "CDBEnv::Flush: %s detach\n", strFile); |
|
|
|
|
if (!fMockDb) |
|
|
|
|
dbenv.lsn_reset(strFile.c_str(), 0); |
|
|
|
|
dbenv->lsn_reset(strFile.c_str(), 0); |
|
|
|
|
LogPrint("db", "CDBEnv::Flush: %s closed\n", strFile); |
|
|
|
|
mapFileUseCount.erase(mi++); |
|
|
|
|
} else |
|
|
|
@ -443,7 +452,7 @@ void CDBEnv::Flush(bool fShutdown)
@@ -443,7 +452,7 @@ void CDBEnv::Flush(bool fShutdown)
|
|
|
|
|
if (fShutdown) { |
|
|
|
|
char** listp; |
|
|
|
|
if (mapFileUseCount.empty()) { |
|
|
|
|
dbenv.log_archive(&listp, DB_ARCH_REMOVE); |
|
|
|
|
dbenv->log_archive(&listp, DB_ARCH_REMOVE); |
|
|
|
|
Close(); |
|
|
|
|
if (!fMockDb) |
|
|
|
|
boost::filesystem::remove_all(path / "database"); |
|
|
|
|