mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-26 05:48:20 +01:00
Merge #19324: wallet: Move BerkeleyBatch static functions to BerkeleyDatabase
d8e9ca66d1walletdb: Move Rewrite into BerkeleyDatabase (Andrew Chow)91d109156dwalletdb: Move PeriodicFlush into WalletDatabase (Andrew Chow)8f1bcf8b7bwalletdb: Combine VerifyDatabaseFile and VerifyEnvironment (Andrew Chow) Pull request description: The `BerkeleyBatch` class has 4 static functions that operate on `BerkeleyDatabase` or `BerkeleyEnvironment`. It doesn't make sense for these to be standalone nor for them to be static functions. So instead, move them from `BerkeleyBatch` into `BerkeleyDatabase` and make them member functions instead of static. `BerkeleyBatch::VerifyEnvironment` and `BerkeleyBatch::VerifyDatabaseFile` are combined into a single `BerkeleyDatabase::Verify` function that operates on that `BerkeleyDatabase` object. `BerkeleyBatch::Rewrite` and `BerkeleyBatch::PeriodicFlush` both took a `BerkeleyDatabase` as an argument and did stuff on it. So we just make it a member function so it doesn't need to take a database as an argument. Part of #18971 ACKs for top commit: MarcoFalke: re-ACKd8e9ca66d1only change is test fixup 🤞 promag: Code review ACKd8e9ca66d1, good stuff. Tree-SHA512: 9847e55b13d98bf4e5636cc14bc3f5351d56737f7e320fafffaed128606240765599e5400382c5aecac06690f7e36265ca3e1031f3f6d8a9688f6d5cb1bacd2a
This commit is contained in:
@@ -292,11 +292,10 @@ BerkeleyBatch::SafeDbt::operator Dbt*()
|
||||
return &m_dbt;
|
||||
}
|
||||
|
||||
bool BerkeleyBatch::VerifyEnvironment(const fs::path& file_path, bilingual_str& errorStr)
|
||||
bool BerkeleyDatabase::Verify(bilingual_str& errorStr)
|
||||
{
|
||||
std::string walletFile;
|
||||
std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, walletFile);
|
||||
fs::path walletDir = env->Directory();
|
||||
fs::path file_path = walletDir / strFile;
|
||||
|
||||
LogPrintf("Using BerkeleyDB version %s\n", BerkeleyDatabaseVersion());
|
||||
LogPrintf("Using wallet %s\n", file_path.string());
|
||||
@@ -306,19 +305,10 @@ bool BerkeleyBatch::VerifyEnvironment(const fs::path& file_path, bilingual_str&
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BerkeleyBatch::VerifyDatabaseFile(const fs::path& file_path, bilingual_str& errorStr)
|
||||
{
|
||||
std::string walletFile;
|
||||
std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, walletFile);
|
||||
fs::path walletDir = env->Directory();
|
||||
|
||||
if (fs::exists(walletDir / walletFile))
|
||||
if (fs::exists(file_path))
|
||||
{
|
||||
if (!env->Verify(walletFile)) {
|
||||
errorStr = strprintf(_("%s corrupt. Try using the wallet tool bitcoin-wallet to salvage or restoring a backup."), walletFile);
|
||||
if (!env->Verify(strFile)) {
|
||||
errorStr = strprintf(_("%s corrupt. Try using the wallet tool bitcoin-wallet to salvage or restoring a backup."), file_path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -495,13 +485,11 @@ void BerkeleyEnvironment::ReloadDbEnv()
|
||||
Open(true);
|
||||
}
|
||||
|
||||
bool BerkeleyBatch::Rewrite(BerkeleyDatabase& database, const char* pszSkip)
|
||||
bool BerkeleyDatabase::Rewrite(const char* pszSkip)
|
||||
{
|
||||
if (database.IsDummy()) {
|
||||
if (IsDummy()) {
|
||||
return true;
|
||||
}
|
||||
BerkeleyEnvironment *env = database.env.get();
|
||||
const std::string& strFile = database.strFile;
|
||||
while (true) {
|
||||
{
|
||||
LOCK(cs_db);
|
||||
@@ -515,7 +503,7 @@ bool BerkeleyBatch::Rewrite(BerkeleyDatabase& database, const char* pszSkip)
|
||||
LogPrintf("BerkeleyBatch::Rewrite: Rewriting %s...\n", strFile);
|
||||
std::string strFileRes = strFile + ".rewrite";
|
||||
{ // surround usage of db with extra {}
|
||||
BerkeleyBatch db(database, "r");
|
||||
BerkeleyBatch db(*this, "r");
|
||||
std::unique_ptr<Db> pdbCopy = MakeUnique<Db>(env->dbenv.get(), 0);
|
||||
|
||||
int ret = pdbCopy->open(nullptr, // Txn pointer
|
||||
@@ -625,14 +613,12 @@ void BerkeleyEnvironment::Flush(bool fShutdown)
|
||||
}
|
||||
}
|
||||
|
||||
bool BerkeleyBatch::PeriodicFlush(BerkeleyDatabase& database)
|
||||
bool BerkeleyDatabase::PeriodicFlush()
|
||||
{
|
||||
if (database.IsDummy()) {
|
||||
if (IsDummy()) {
|
||||
return true;
|
||||
}
|
||||
bool ret = false;
|
||||
BerkeleyEnvironment *env = database.env.get();
|
||||
const std::string& strFile = database.strFile;
|
||||
TRY_LOCK(cs_db, lockDb);
|
||||
if (lockDb)
|
||||
{
|
||||
@@ -667,11 +653,6 @@ bool BerkeleyBatch::PeriodicFlush(BerkeleyDatabase& database)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool BerkeleyDatabase::Rewrite(const char* pszSkip)
|
||||
{
|
||||
return BerkeleyBatch::Rewrite(*this, pszSkip);
|
||||
}
|
||||
|
||||
bool BerkeleyDatabase::Backup(const std::string& strDest) const
|
||||
{
|
||||
if (IsDummy()) {
|
||||
|
||||
Reference in New Issue
Block a user