Bitcoin
Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
BerkeleyEnvironment Class Reference

#include <db.h>

Public Types

enum  VerifyResult { VerifyResult::VERIFY_OK, VerifyResult::RECOVER_OK, VerifyResult::RECOVER_FAIL }
 
typedef bool(* recoverFunc_type) (const fs::path &file_path, std::string &out_backup_filename)
 
typedef std::pair< std::vector< unsigned char >, std::vector< unsigned char > > KeyValPair
 

Public Member Functions

 BerkeleyEnvironment (const fs::path &env_directory)
 
 BerkeleyEnvironment ()
 Construct an in-memory mock Berkeley environment for testing and as a place-holder for g_dbenvs emplace. More...
 
 ~BerkeleyEnvironment ()
 
void Reset ()
 
bool IsMock () const
 
bool IsInitialized () const
 
bool IsDatabaseLoaded (const std::string &db_filename) const
 
fs::path Directory () const
 
VerifyResult Verify (const std::string &strFile, recoverFunc_type recoverFunc, std::string &out_backup_filename)
 
bool Salvage (const std::string &strFile, bool fAggressive, std::vector< KeyValPair > &vResult)
 
bool Open (bool retry)
 
void Close ()
 
void Flush (bool fShutdown)
 
void CheckpointLSN (const std::string &strFile)
 
void CloseDb (const std::string &strFile)
 
void ReloadDbEnv ()
 
DbTxn * TxnBegin (int flags=DB_TXN_WRITE_NOSYNC)
 

Public Attributes

std::unique_ptr< DbEnv > dbenv
 
std::map< std::string, int > mapFileUseCount
 
std::map< std::string, std::reference_wrapper< BerkeleyDatabase > > m_databases
 
std::unordered_map< std::string, WalletDatabaseFileIdm_fileids
 
std::condition_variable_any m_db_in_use
 

Private Attributes

bool fDbEnvInit
 
bool fMockDb
 
std::string strPath
 

Member Typedef Documentation

◆ KeyValPair

typedef std::pair<std::vector<unsigned char>, std::vector<unsigned char> > BerkeleyEnvironment::KeyValPair

Salvage data from a file that Verify says is bad. fAggressive sets the DB_AGGRESSIVE flag (see berkeley DB->verify() method documentation). Appends binary key/value pairs to vResult, returns true if successful. NOTE: reads the entire database into memory, so cannot be used for huge databases.

◆ recoverFunc_type

typedef bool(* BerkeleyEnvironment::recoverFunc_type) (const fs::path &file_path, std::string &out_backup_filename)

Member Enumeration Documentation

◆ VerifyResult

Verify that database file strFile is OK. If it is not, call the callback to try to recover. This must be called BEFORE strFile is opened. Returns true if strFile is OK.

Enumerator
VERIFY_OK 
RECOVER_OK 
RECOVER_FAIL 

Constructor & Destructor Documentation

◆ BerkeleyEnvironment() [1/2]

BerkeleyEnvironment::BerkeleyEnvironment ( const fs::path &  env_directory)

◆ BerkeleyEnvironment() [2/2]

BerkeleyEnvironment::BerkeleyEnvironment ( )

Construct an in-memory mock Berkeley environment for testing and as a place-holder for g_dbenvs emplace.

◆ ~BerkeleyEnvironment()

BerkeleyEnvironment::~BerkeleyEnvironment ( )

Member Function Documentation

◆ CheckpointLSN()

void BerkeleyEnvironment::CheckpointLSN ( const std::string &  strFile)

◆ Close()

void BerkeleyEnvironment::Close ( )

◆ CloseDb()

void BerkeleyEnvironment::CloseDb ( const std::string &  strFile)

◆ Directory()

fs::path BerkeleyEnvironment::Directory ( ) const
inline

◆ Flush()

void BerkeleyEnvironment::Flush ( bool  fShutdown)

◆ IsDatabaseLoaded()

bool BerkeleyEnvironment::IsDatabaseLoaded ( const std::string &  db_filename) const
inline

◆ IsInitialized()

bool BerkeleyEnvironment::IsInitialized ( ) const
inline

◆ IsMock()

bool BerkeleyEnvironment::IsMock ( ) const
inline

◆ Open()

bool BerkeleyEnvironment::Open ( bool  retry)

debug

◆ ReloadDbEnv()

void BerkeleyEnvironment::ReloadDbEnv ( )

◆ Reset()

void BerkeleyEnvironment::Reset ( )

◆ Salvage()

bool BerkeleyEnvironment::Salvage ( const std::string &  strFile,
bool  fAggressive,
std::vector< KeyValPair > &  vResult 
)

◆ TxnBegin()

DbTxn* BerkeleyEnvironment::TxnBegin ( int  flags = DB_TXN_WRITE_NOSYNC)
inline

◆ Verify()

BerkeleyEnvironment::VerifyResult BerkeleyEnvironment::Verify ( const std::string &  strFile,
recoverFunc_type  recoverFunc,
std::string &  out_backup_filename 
)

Member Data Documentation

◆ dbenv

std::unique_ptr<DbEnv> BerkeleyEnvironment::dbenv

◆ fDbEnvInit

bool BerkeleyEnvironment::fDbEnvInit
private

◆ fMockDb

bool BerkeleyEnvironment::fMockDb
private

◆ m_databases

std::map<std::string, std::reference_wrapper<BerkeleyDatabase> > BerkeleyEnvironment::m_databases

◆ m_db_in_use

std::condition_variable_any BerkeleyEnvironment::m_db_in_use

◆ m_fileids

std::unordered_map<std::string, WalletDatabaseFileId> BerkeleyEnvironment::m_fileids

◆ mapFileUseCount

std::map<std::string, int> BerkeleyEnvironment::mapFileUseCount

◆ strPath

std::string BerkeleyEnvironment::strPath
private

The documentation for this class was generated from the following files: