 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
6 #ifndef BITCOIN_WALLET_BDB_H
7 #define BITCOIN_WALLET_BDB_H
20 #include <unordered_map>
23 #if defined(__GNUC__) && !defined(__clang__)
24 #pragma GCC diagnostic push
25 #pragma GCC diagnostic ignored "-Wsuggest-override"
28 #if defined(__GNUC__) && !defined(__clang__)
29 #pragma GCC diagnostic pop
56 std::map<std::string, std::reference_wrapper<BerkeleyDatabase>>
m_databases;
57 std::unordered_map<std::string, WalletDatabaseFileId>
m_fileids;
71 void Flush(
bool fShutdown);
74 void CloseDb(
const std::string& strFile);
79 DbTxn* ptxn =
nullptr;
80 int ret =
dbenv->txn_begin(
nullptr, &ptxn,
flags);
81 if (!ptxn || ret != 0)
104 auto inserted = this->env->m_databases.emplace(
strFile, std::ref(*
this));
111 void Open()
override;
115 bool Rewrite(
const char* pszSkip=
nullptr)
override;
124 bool Backup(
const std::string& strDest)
const override;
128 void Flush()
override;
132 void Close()
override;
147 std::string
Format()
override {
return "bdb"; }
157 std::shared_ptr<BerkeleyEnvironment>
env;
165 std::unique_ptr<DatabaseBatch>
MakeBatch(
bool flush_on_close =
true)
override;
180 SafeDbt(
void* data,
size_t size);
214 void Flush()
override;
215 void Close()
override;
235 #endif // BITCOIN_WALLET_BDB_H
static const bool DEFAULT_WALLET_PRIVDB
An instance of this class represents one database.
std::map< std::string, std::reference_wrapper< BerkeleyDatabase > > m_databases
bool Verify(bilingual_str &error)
Verifies the environment and database file.
std::unique_ptr< BerkeleyDatabase > MakeBerkeleyDatabase(const fs::path &path, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
Return object giving access to Berkeley database at specified path.
BerkeleyDatabase()=delete
void CheckpointLSN(const std::string &strFile)
bool ReadKey(CDataStream &&key, CDataStream &value) override
bool operator==(const WalletDatabaseFileId &rhs) const
static const unsigned int DEFAULT_WALLET_DBLOGSIZE
void Flush() override
Make sure all changes are flushed to database file.
void Open() override
Open the database if it is not already opened.
RAII class that provides access to a WalletDatabase.
std::string Filename() override
Return path to main database filename.
~BerkeleyDatabase() override
static std::string PathToString(const path &path)
Convert path object to a byte string.
An instance of this class represents one database.
BerkeleyEnvironment()
Construct an in-memory mock Berkeley environment for testing.
BerkeleyBatch & operator=(const BerkeleyBatch &)=delete
RAII class that automatically cleanses its data on destruction.
std::shared_ptr< BerkeleyEnvironment > GetBerkeleyEnv(const fs::path &env_directory)
Get BerkeleyEnvironment given a directory path.
BerkeleyDatabase & m_database
std::unique_ptr< Db > m_db
Database pointer.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
bool Rewrite(const char *pszSkip=nullptr) override
Rewrite the entire database on disk, with the exception of key pszSkip if non-zero.
const void * get_data() const
void Close() override
Flush to the database file and close the database.
static path PathFromString(const std::string &string)
Convert byte string to path object.
std::condition_variable_any m_db_in_use
fs::path Directory() const
void IncrementUpdateCounter() override
u_int8_t value[DB_FILE_ID_LEN]
bool PeriodicFlush() override
void CloseCursor() override
std::shared_ptr< BerkeleyEnvironment > env
Pointer to shared database environment.
~BerkeleyBatch() override
void RemoveRef() override
Indicate that database user has stopped using the database and that it could be flushed or closed.
void Flush(bool fShutdown)
bool BerkeleyDatabaseSanityCheck()
Perform sanity check of runtime BDB version versus linked BDB version.
bool HasKey(CDataStream &&key) override
BerkeleyDatabase(std::shared_ptr< BerkeleyEnvironment > env, std::string filename)
Create DB handle to real database.
std::unique_ptr< DbEnv > dbenv
void CloseDb(const std::string &strFile)
std::string BerkeleyDatabaseVersion()
bool StartCursor() override
Double ended buffer combining vector and stream-like interfaces.
RAII class that provides access to a Berkeley database.
bool WriteKey(CDataStream &&key, CDataStream &&value, bool overwrite=true) override
DbTxn * TxnBegin(int flags=DB_TXN_WRITE_NOSYNC)
bool EraseKey(CDataStream &&key) override
void AddRef() override
Indicate that a new database user has begun using the database.
bool error(const char *fmt, const Args &... args)
std::string Format() override
bool Open(bilingual_str &error)
BerkeleyBatch(BerkeleyDatabase &database, const bool fReadOnly, bool fFlushOnCloseIn=true)
u_int32_t get_size() const
std::unordered_map< std::string, WalletDatabaseFileId > m_fileids
void ReloadDbEnv() override
std::unique_ptr< DatabaseBatch > MakeBatch(bool flush_on_close=true) override
Make a BerkeleyBatch connected to this database.
bool IsInitialized() const
bool TxnCommit() override
bool ReadAtCursor(CDataStream &ssKey, CDataStream &ssValue, bool &complete) override
bool Backup(const std::string &strDest) const override
Back up the entire database to a file.
BerkeleyEnvironment * env