Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
CDBWrapper Class Reference

#include <dbwrapper.h>

Inheritance diagram for CDBWrapper:
[legend]
Collaboration diagram for CDBWrapper:
[legend]

Classes

struct  ReadFailure

Public Types

using ReadStatus = util::Expected<bool, ReadFailure>

Public Member Functions

 CDBWrapper (const DBParams &params)
 ~CDBWrapper ()
 CDBWrapper (const CDBWrapper &)=delete
CDBWrapper & operator= (const CDBWrapper &)=delete
template<typename K, typename V>
ReadStatus TryRead (const K &key, V &value) const
 Read and deserialize a value from the database, with explicit error discrimination.
template<typename K, typename V>
bool Read (const K &key, V &value) const
 Wrapper around TryRead() that preserves the original Read() semantics: returns true on success, false if the key is absent or deserialization fails, and throws dbwrapper_error on an internal DB error.
template<typename K, typename V>
void Write (const K &key, const V &value, bool fSync=false)
template<typename K>
bool Exists (const K &key) const
template<typename K>
void Erase (const K &key, bool fSync=false)
void WriteBatch (CDBBatch &batch, bool fSync=false)
void CompactFull ()
 Perform a blocking full compaction of the underlying LevelDB.
std::optional< std::string > GetProperty (const std::string &property) const
 Return a LevelDB property value, if available.
size_t DynamicMemoryUsage () const
CDBIterator * NewIterator ()
bool IsEmpty ()
 Return true if the database managed by this class contains no entries.
template<typename K>
size_t EstimateSize (const K &key_begin, const K &key_end) const

Static Public Member Functions

static bool HasKeyStartingWith (const fs::path &path, uint8_t prefix)

Private Member Functions

std::optional< std::string > ReadImpl (std::span< const std::byte > key) const
bool ExistsImpl (std::span< const std::byte > key) const
size_t EstimateSizeImpl (std::span< const std::byte > key1, std::span< const std::byte > key2) const
auto & DBContext () const LIFETIMEBOUND

Private Attributes

std::unique_ptr< LevelDBContext > m_db_context
 holds all leveldb-specific fields of this class
std::string m_name
 the name of this database
Obfuscation m_obfuscation
 optional XOR-obfuscation of the database

Static Private Attributes

static const std::string OBFUSCATION_KEY {"\000obfuscate_key", 14}
 obfuscation key storage key, null-prefixed to avoid collisions

Friends

const Obfuscation & dbwrapper_private::GetObfuscation (const CDBWrapper &)

Detailed Description

Definition at line 192 of file dbwrapper.h.

Member Typedef Documentation

◆ ReadStatus

Definition at line 230 of file dbwrapper.h.

Constructor & Destructor Documentation

◆ CDBWrapper() [1/2]

CDBWrapper::CDBWrapper ( const DBParams & params)

Definition at line 244 of file dbwrapper.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~CDBWrapper()

CDBWrapper::~CDBWrapper ( )

Definition at line 298 of file dbwrapper.cpp.

Here is the call graph for this function:

◆ CDBWrapper() [2/2]

CDBWrapper::CDBWrapper ( const CDBWrapper & )
delete
Here is the call graph for this function:

Member Function Documentation

◆ CompactFull()

void CDBWrapper::CompactFull ( )

Perform a blocking full compaction of the underlying LevelDB.

Definition at line 334 of file dbwrapper.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DBContext()

auto & CDBWrapper::DBContext ( ) const
inlineprivate

Definition at line 211 of file dbwrapper.h.

Here is the caller graph for this function:

◆ DynamicMemoryUsage()

size_t CDBWrapper::DynamicMemoryUsage ( ) const

Definition at line 336 of file dbwrapper.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Erase()

template<typename K>
void CDBWrapper::Erase ( const K & key,
bool fSync = false )
inline

Definition at line 316 of file dbwrapper.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EstimateSize()

template<typename K>
size_t CDBWrapper::EstimateSize ( const K & key_begin,
const K & key_end ) const
inline

Definition at line 347 of file dbwrapper.h.

Here is the call graph for this function:

◆ EstimateSizeImpl()

size_t CDBWrapper::EstimateSizeImpl ( std::span< const std::byte > key1,
std::span< const std::byte > key2 ) const
private

Definition at line 375 of file dbwrapper.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Exists()

template<typename K>
bool CDBWrapper::Exists ( const K & key) const
inline

Definition at line 307 of file dbwrapper.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExistsImpl()

bool CDBWrapper::ExistsImpl ( std::span< const std::byte > key) const
private

Definition at line 360 of file dbwrapper.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetProperty()

std::optional< std::string > CDBWrapper::GetProperty ( const std::string & property) const

Return a LevelDB property value, if available.

Definition at line 328 of file dbwrapper.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HasKeyStartingWith()

bool CDBWrapper::HasKeyStartingWith ( const fs::path & path,
uint8_t prefix )
static

Probe an unopened database for a key prefix. Return true if a database at path exists and contains at least 1 entry beginning with prefix; missing or empty databases return false, and database errors throw dbwrapper_error.

Definition at line 156 of file dbwrapper.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsEmpty()

bool CDBWrapper::IsEmpty ( )

Return true if the database managed by this class contains no entries.

Definition at line 385 of file dbwrapper.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NewIterator()

CDBIterator * CDBWrapper::NewIterator ( )

Definition at line 404 of file dbwrapper.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

CDBWrapper & CDBWrapper::operator= ( const CDBWrapper & )
delete
Here is the call graph for this function:

◆ Read()

template<typename K, typename V>
bool CDBWrapper::Read ( const K & key,
V & value ) const
inline

Wrapper around TryRead() that preserves the original Read() semantics: returns true on success, false if the key is absent or deserialization fails, and throws dbwrapper_error on an internal DB error.

Prefer TryRead() when the caller needs to distinguish between a missing key and a corrupt value.

Definition at line 287 of file dbwrapper.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadImpl()

std::optional< std::string > CDBWrapper::ReadImpl ( std::span< const std::byte > key) const
private

Definition at line 346 of file dbwrapper.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TryRead()

template<typename K, typename V>
ReadStatus CDBWrapper::TryRead ( const K & key,
V & value ) const
inlinenodiscard

Read and deserialize a value from the database, with explicit error discrimination.

Unlike Read(), this method distinguishes between a missing key, a deserialization failure (DeserializationError), and an internal DB error (DatabaseError), enabling callers to treat data corruption differently from an absent entry.

Note
Callers are expected to provide well-formed keys; key serialization is the only operation that may throw.
Parameters
[in]keyThe key to look up.
[out]valuePopulated with the deserialized value when the returned Expected holds true; indeterminate otherwise.
Returns
On success, true if the key was found (value populated) or false if the key was absent. On failure, a ReadFailure describing the error.

Definition at line 249 of file dbwrapper.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Write()

template<typename K, typename V>
void CDBWrapper::Write ( const K & key,
const V & value,
bool fSync = false )
inline

Definition at line 299 of file dbwrapper.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteBatch()

void CDBWrapper::WriteBatch ( CDBBatch & batch,
bool fSync = false )

Definition at line 312 of file dbwrapper.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbwrapper_private::GetObfuscation

Member Data Documentation

◆ m_db_context

std::unique_ptr<LevelDBContext> CDBWrapper::m_db_context
private

holds all leveldb-specific fields of this class

Definition at line 197 of file dbwrapper.h.

◆ m_name

std::string CDBWrapper::m_name
private

the name of this database

Definition at line 200 of file dbwrapper.h.

◆ m_obfuscation

Obfuscation CDBWrapper::m_obfuscation
private

optional XOR-obfuscation of the database

Definition at line 203 of file dbwrapper.h.

◆ OBFUSCATION_KEY

const std::string CDBWrapper::OBFUSCATION_KEY {"\000obfuscate_key", 14}
inlinestaticprivate

obfuscation key storage key, null-prefixed to avoid collisions

Definition at line 206 of file dbwrapper.h.


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