From 14c9d116be476d08dd18f2e9f4a8ed251a6bbf79 Mon Sep 17 00:00:00 2001 From: Gregory Maxwell Date: Sun, 24 Mar 2013 12:59:03 -0700 Subject: Make explicitly requested salvage operations keep going when there is an error. In my tests corrupted wallets would often result in BDB dropping an error just due to duplicate records being found, which appears harmless. --- src/db.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/db.cpp') diff --git a/src/db.cpp b/src/db.cpp index 94629f3ca..907dba535 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -167,9 +167,18 @@ bool CDBEnv::Salvage(std::string strFile, bool fAggressive, Db db(&dbenv, 0); int result = db.verify(strFile.c_str(), NULL, &strDump, flags); - if (result != 0) + if (result == DB_VERIFY_BAD) { - printf("ERROR: db salvage failed\n"); + printf("Error: Salvage found errors, all data may not be recoverable.\n"); + if (!fAggressive) + { + printf("Error: Rerun with aggressive mode to ignore errors and continue.\n"); + return false; + } + } + if (result != 0 && result != DB_VERIFY_BAD) + { + printf("ERROR: db salvage failed: %d\n",result); return false; } -- cgit v1.2.3 From ccda03b57022369c4352d0f5a816cff9ace833e6 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 24 Apr 2013 00:43:14 +0200 Subject: Remove database/ after clean shutdown --- src/db.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/db.cpp') diff --git a/src/db.cpp b/src/db.cpp index 35d6cca89..52d613bc3 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,14 +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; 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"; @@ -84,7 +84,7 @@ bool CDBEnv::Open(const boost::filesystem::path& path) 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 | @@ -456,6 +456,8 @@ void CDBEnv::Flush(bool fShutdown) { dbenv.log_archive(&listp, DB_ARCH_REMOVE); Close(); + if (!fMockDb) + boost::filesystem::remove_all(path / "database"); } } } -- cgit v1.2.3 From 98ab2b5a265e4794d6a9d22212d992bfd1f9c1f1 Mon Sep 17 00:00:00 2001 From: Robert Backhaus Date: Wed, 29 May 2013 10:33:36 +1000 Subject: Don't attempt to resize vector to negative size. --- src/db.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/db.cpp') diff --git a/src/db.cpp b/src/db.cpp index 3133d99bf..fd4c67d55 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -541,6 +541,8 @@ bool CAddrDB::Read(CAddrMan& addr) // use file size to size memory buffer int fileSize = GetFilesize(filein); int dataSize = fileSize - sizeof(uint256); + //Don't try to resize to a negative number if file is small + if ( dataSize < 0 ) dataSize = 0; vector vchData; vchData.resize(dataSize); uint256 hashIn; -- cgit v1.2.3