6#ifndef BITCOIN_WALLET_BDB_H
7#define BITCOIN_WALLET_BDB_H
17#include <condition_variable>
21#include <unordered_map>
33#define BDB_DB_FILE_ID_LEN 20
55 std::map<fs::path, std::reference_wrapper<BerkeleyDatabase>>
m_databases;
56 std::unordered_map<std::string, WalletDatabaseFileId>
m_fileids;
71 void Flush(
bool fShutdown);
103 bool Rewrite(
const char* pszSkip=
nullptr)
override;
112 bool Backup(
const std::string& strDest)
const override;
116 void Flush()
override;
120 void Close()
override;
135 std::string
Format()
override {
return "bdb"; }
145 std::shared_ptr<BerkeleyEnvironment>
env;
157 std::unique_ptr<DatabaseBatch>
MakeBatch(
bool flush_on_close =
true)
override;
203 void Flush()
override;
204 void Close()
override;
206 std::unique_ptr<DatabaseCursor>
GetNewCursor()
override;
#define BDB_DB_FILE_ID_LEN
Double ended buffer combining vector and stream-like interfaces.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
RAII class that provides access to a Berkeley database.
bool ReadKey(DataStream &&key, DataStream &value) override
bool HasKey(DataStream &&key) override
BerkeleyDatabase & m_database
bool EraseKey(DataStream &&key) override
~BerkeleyBatch() override
BerkeleyBatch(BerkeleyDatabase &database, const bool fReadOnly, bool fFlushOnCloseIn=true)
std::unique_ptr< DatabaseCursor > GetNewPrefixCursor(Span< const std::byte > prefix) override
bool HasActiveTxn() override
BerkeleyBatch & operator=(const BerkeleyBatch &)=delete
bool TxnCommit() override
BerkeleyEnvironment * env
std::unique_ptr< DatabaseCursor > GetNewCursor() override
BerkeleyBatch(const BerkeleyBatch &)=delete
bool ErasePrefix(Span< const std::byte > prefix) override
bool WriteKey(DataStream &&key, DataStream &&value, bool overwrite=true) override
~BerkeleyCursor() override
std::vector< std::byte > m_key_prefix
BerkeleyCursor(BerkeleyDatabase &database, const BerkeleyBatch &batch, Span< const std::byte > prefix={})
Status Next(DataStream &key, DataStream &value) override
An instance of this class represents one database.
bool Rewrite(const char *pszSkip=nullptr) override
Rewrite the entire database on disk, with the exception of key pszSkip if non-zero.
void Open() override
Open the database if it is not already opened.
bool Backup(const std::string &strDest) const override
Back up the entire database to a file.
void RemoveRef() override
Indicate that database user has stopped using the database and that it could be flushed or closed.
std::string Format() override
std::shared_ptr< BerkeleyEnvironment > env
Pointer to shared database environment.
void IncrementUpdateCounter() override
void ReloadDbEnv() override
void AddRef() override
Indicate that a new database user has begun using the database.
std::string Filename() override
Return path to main database filename.
BerkeleyDatabase()=delete
std::unique_ptr< Db > m_db
Database pointer.
void Flush() override
Make sure all changes are flushed to database file.
bool PeriodicFlush() override
std::unique_ptr< DatabaseBatch > MakeBatch(bool flush_on_close=true) override
Make a BerkeleyBatch connected to this database.
bool Verify(bilingual_str &error)
Verifies the environment and database file.
~BerkeleyDatabase() override
void Close() override
Flush to the database file and close the database.
fs::path Directory() const
std::condition_variable_any m_db_in_use
void CloseDb(const fs::path &filename)
std::unique_ptr< DbEnv > dbenv
BerkeleyEnvironment()
Construct an in-memory mock Berkeley environment for testing.
bool IsInitialized() const
void CheckpointLSN(const std::string &strFile)
std::unordered_map< std::string, WalletDatabaseFileId > m_fileids
void Flush(bool fShutdown)
DbTxn * TxnBegin(int flags)
bool Open(bilingual_str &error)
std::map< fs::path, std::reference_wrapper< BerkeleyDatabase > > m_databases
RAII class that provides access to a WalletDatabase.
An instance of this class represents one database.
static std::string PathToString(const path &path)
Convert path object to a byte string.
static path PathFromString(const std::string &string)
Convert byte string to path object.
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.
std::string BerkeleyDatabaseVersion()
std::shared_ptr< BerkeleyEnvironment > GetBerkeleyEnv(const fs::path &env_directory, bool use_shared_memory)
Get BerkeleyEnvironment given a directory path.
bool BerkeleyDatabaseSanityCheck()
Perform sanity check of runtime BDB version versus linked BDB version.
bool operator==(const WalletDatabaseFileId &rhs) const
uint8_t value[BDB_DB_FILE_ID_LEN]