mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-15 12:40:41 +02:00
Add MakeBerkeleyRODatabase
Implements MakeBerkeleyRODatabase and adds DatabaseFormat::BERKELEY_RO so that MakeDatabase can use BerkeleyRO as the backend database.
This commit is contained in:
parent
6e50bee67d
commit
dd57713f6e
@ -183,6 +183,7 @@ public:
|
|||||||
enum class DatabaseFormat {
|
enum class DatabaseFormat {
|
||||||
BERKELEY,
|
BERKELEY,
|
||||||
SQLITE,
|
SQLITE,
|
||||||
|
BERKELEY_RO,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DatabaseOptions {
|
struct DatabaseOptions {
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <crypto/common.h> // For ReadBE32
|
#include <crypto/common.h> // For ReadBE32
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
|
#include <util/translation.h>
|
||||||
#include <wallet/migrate.h>
|
#include <wallet/migrate.h>
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@ -748,4 +749,18 @@ std::unique_ptr<DatabaseCursor> BerkeleyROBatch::GetNewPrefixCursor(Span<const s
|
|||||||
{
|
{
|
||||||
return std::make_unique<BerkeleyROCursor>(m_database, prefix);
|
return std::make_unique<BerkeleyROCursor>(m_database, prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<BerkeleyRODatabase> MakeBerkeleyRODatabase(const fs::path& path, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error)
|
||||||
|
{
|
||||||
|
fs::path data_file = BDBDataFile(path);
|
||||||
|
try {
|
||||||
|
std::unique_ptr<BerkeleyRODatabase> db = std::make_unique<BerkeleyRODatabase>(data_file);
|
||||||
|
status = DatabaseStatus::SUCCESS;
|
||||||
|
return db;
|
||||||
|
} catch (const std::runtime_error& e) {
|
||||||
|
error.original = e.what();
|
||||||
|
status = DatabaseStatus::FAILED_LOAD;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace wallet
|
} // namespace wallet
|
||||||
|
@ -116,6 +116,9 @@ public:
|
|||||||
bool TxnCommit() override { return false; }
|
bool TxnCommit() override { return false; }
|
||||||
bool TxnAbort() override { return false; }
|
bool TxnAbort() override { return false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! Return object giving access to Berkeley Read Only database at specified path.
|
||||||
|
std::unique_ptr<BerkeleyRODatabase> MakeBerkeleyRODatabase(const fs::path& path, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error);
|
||||||
} // namespace wallet
|
} // namespace wallet
|
||||||
|
|
||||||
#endif // BITCOIN_WALLET_MIGRATE_H
|
#endif // BITCOIN_WALLET_MIGRATE_H
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#ifdef USE_BDB
|
#ifdef USE_BDB
|
||||||
#include <wallet/bdb.h>
|
#include <wallet/bdb.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <wallet/migrate.h>
|
||||||
#ifdef USE_SQLITE
|
#ifdef USE_SQLITE
|
||||||
#include <wallet/sqlite.h>
|
#include <wallet/sqlite.h>
|
||||||
#endif
|
#endif
|
||||||
@ -1389,6 +1390,11 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If BERKELEY was the format, then change the format from BERKELEY to BERKELEY_RO
|
||||||
|
if (format && options.require_format && format == DatabaseFormat::BERKELEY && options.require_format == DatabaseFormat::BERKELEY_RO) {
|
||||||
|
format = DatabaseFormat::BERKELEY_RO;
|
||||||
|
}
|
||||||
|
|
||||||
// A db already exists so format is set, but options also specifies the format, so make sure they agree
|
// A db already exists so format is set, but options also specifies the format, so make sure they agree
|
||||||
if (format && options.require_format && format != options.require_format) {
|
if (format && options.require_format && format != options.require_format) {
|
||||||
error = Untranslated(strprintf("Failed to load database path '%s'. Data is not in required format.", fs::PathToString(path)));
|
error = Untranslated(strprintf("Failed to load database path '%s'. Data is not in required format.", fs::PathToString(path)));
|
||||||
@ -1422,6 +1428,10 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (format == DatabaseFormat::BERKELEY_RO) {
|
||||||
|
return MakeBerkeleyRODatabase(path, options, status, error);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_BDB
|
#ifdef USE_BDB
|
||||||
if constexpr (true) {
|
if constexpr (true) {
|
||||||
return MakeBerkeleyDatabase(path, options, status, error);
|
return MakeBerkeleyDatabase(path, options, status, error);
|
||||||
|
Loading…
Reference in New Issue
Block a user