 |
Bitcoin Core
21.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
55 std::map<std::string, std::reference_wrapper<BerkeleyDatabase>>
m_databases;
56 std::unordered_map<std::string, WalletDatabaseFileId>
m_fileids;
70 void Flush(
bool fShutdown);
73 void CloseDb(
const std::string& strFile);
78 DbTxn* ptxn =
nullptr;
79 int ret =
dbenv->txn_begin(
nullptr, &ptxn,
flags);
80 if (!ptxn || ret != 0)
87 std::shared_ptr<BerkeleyEnvironment>
GetBerkeleyEnv(
const fs::path& env_directory);
103 auto inserted = this->env->m_databases.emplace(
strFile, std::ref(*
this));
110 void Open()
override;
114 bool Rewrite(
const char* pszSkip=
nullptr)
override;
123 bool Backup(
const std::string& strDest)
const override;
127 void Flush()
override;
131 void Close()
override;
146 std::string
Format()
override {
return "bdb"; }
156 std::shared_ptr<BerkeleyEnvironment>
env;
164 std::unique_ptr<DatabaseBatch>
MakeBatch(
bool flush_on_close =
true)
override;
179 SafeDbt(
void* data,
size_t size);
213 void Flush()
override;
214 void Close()
override;
233 #endif // BITCOIN_WALLET_BDB_H
BerkeleyEnvironment()
Construct an in-memory mock Berkeley environment for testing.
std::unique_ptr< DbEnv > dbenv
std::shared_ptr< BerkeleyEnvironment > GetBerkeleyEnv(const fs::path &env_directory)
Get BerkeleyEnvironment given a directory path.
bool BerkeleyDatabaseSanityCheck()
Perform sanity check of runtime BDB version versus linked BDB version.
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 automatically cleanses its data on destruction.
An instance of this class represents one database.
void AddRef() override
Indicate the a new database user has began using the database.
BerkeleyBatch & operator=(const BerkeleyBatch &)=delete
bool Rewrite(const char *pszSkip=nullptr) override
Rewrite the entire database on disk, with the exception of key pszSkip if non-zero.
bool ReadKey(CDataStream &&key, CDataStream &value) override
std::condition_variable_any m_db_in_use
std::unique_ptr< Db > m_db
Database pointer.
bool operator==(const WalletDatabaseFileId &rhs) const
BerkeleyBatch(BerkeleyDatabase &database, const bool fReadOnly, bool fFlushOnCloseIn=true)
std::shared_ptr< BerkeleyEnvironment > env
Pointer to shared database environment.
~BerkeleyBatch() override
std::unordered_map< std::string, WalletDatabaseFileId > m_fileids
An instance of this class represents one database.
void Flush(bool fShutdown)
const void * get_data() const
bool Verify(bilingual_str &error)
Verifies the environment and database file.
bool WriteKey(CDataStream &&key, CDataStream &&value, bool overwrite=true) override
~BerkeleyDatabase() override
void ReloadDbEnv() override
bool IsInitialized() const
fs::path Directory() const
std::string BerkeleyDatabaseVersion()
RAII class that provides access to a WalletDatabase.
bool HasKey(CDataStream &&key) override
bool EraseKey(CDataStream &&key) override
static const bool DEFAULT_WALLET_PRIVDB
BerkeleyDatabase & m_database
u_int8_t value[DB_FILE_ID_LEN]
bool PeriodicFlush() override
RAII class that provides access to a Berkeley database.
bool StartCursor() override
std::map< std::string, std::reference_wrapper< BerkeleyDatabase > > m_databases
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.
void CheckpointLSN(const std::string &strFile)
u_int32_t get_size() const
std::string Format() override
bool Backup(const std::string &strDest) const override
Back up the entire database to a file.
Double ended buffer combining vector and stream-like interfaces.
BerkeleyEnvironment * env
bool TxnCommit() override
BerkeleyDatabase()=delete
void IncrementUpdateCounter() override
bool error(const char *fmt, const Args &... args)
bool Open(bilingual_str &error)
void CloseCursor() override
std::string Filename() override
Return path to main database filename.
void Close() override
Flush to the database file and close the database.
void RemoveRef() override
Indicate that database user has stopped using the database and that it could be flushed or closed.
BerkeleyDatabase(std::shared_ptr< BerkeleyEnvironment > env, std::string filename)
Create DB handle to real database.
assert(std::addressof(::ChainstateActive().CoinsTip())==std::addressof(coins_cache))
static const unsigned int DEFAULT_WALLET_DBLOGSIZE
void CloseDb(const std::string &strFile)
bool ReadAtCursor(CDataStream &ssKey, CDataStream &ssValue, bool &complete) override
std::unique_ptr< DatabaseBatch > MakeBatch(bool flush_on_close=true) override
Make a BerkeleyBatch connected to this database.
DbTxn * TxnBegin(int flags=DB_TXN_WRITE_NOSYNC)