5#ifndef BITCOIN_DBWRAPPER_H
6#define BITCOIN_DBWRAPPER_H
53 :
std::runtime_error(
msg) {}
71bool DestroyDB(
const std::string &path_str);
99 template <
typename K,
typename V>
void Write(
const K &key,
const V &value) {
109 template <
typename K>
void Erase(
const K &key) {
137 std::unique_ptr<IteratorImpl> _piter);
144 template <
typename K>
void Seek(
const K &key) {
153 template <
typename K>
bool GetKey(K &key) {
157 }
catch (
const std::exception &) {
168 }
catch (
const std::exception &) {
178 friend const std::vector<uint8_t> &
218 template <
typename K,
typename V>
bool Read(
const K &key, V &value)
const {
222 std::optional<std::string> strValue{
ReadImpl(ssKey)};
230 }
catch (
const std::exception &) {
236 template <
typename K,
typename V>
237 void Write(
const K &key,
const V &value,
bool fSync =
false) {
239 batch.
Write(key, value);
251 template <
typename K>
bool Exists(
const K &key)
const {
258 template <
typename K>
void Erase(
const K &key,
bool fSync =
false) {
276 template <
typename K>
#define Assert(val)
Identity function.
Batch of changes queued to be written to a CDBWrapper.
size_t SizeEstimate() const
const std::unique_ptr< WriteBatchImpl > m_impl_batch
void Write(const K &key, const V &value)
CDBBatch(const CDBWrapper &_parent)
void WriteImpl(Span< const std::byte > key, DataStream &ssValue_)
const CDBWrapper & parent
void EraseImpl(Span< const std::byte > key)
Span< const std::byte > GetKeyImpl() const
CDBIterator(const CDBWrapper &_parent, std::unique_ptr< IteratorImpl > _piter)
const std::unique_ptr< IteratorImpl > m_impl_iter
const CDBWrapper & parent
Span< const std::byte > GetValueImpl() const
void SeekImpl(Span< const std::byte > key)
CDBWrapper(const CDBWrapper &)=delete
size_t DynamicMemoryUsage() const
bool Read(const K &key, V &value) const
std::vector< uint8_t > CreateObfuscateKey() const
Returns a string (consisting of 8 random bytes) suitable for use as an obfuscating XOR key.
CDBIterator * NewIterator()
std::string m_name
the name of this database
bool Exists(const K &key) const
std::vector< uint8_t > obfuscate_key
a key used for optional XOR-obfuscation of the database
CDBWrapper(const DBParams ¶ms)
void Erase(const K &key, bool fSync=false)
static const unsigned int OBFUSCATE_KEY_NUM_BYTES
the length of the obfuscate key in number of bytes
static const std::string OBFUSCATE_KEY_KEY
the key under which the obfuscation key is stored
void WriteBatch(CDBBatch &batch, bool fSync=false)
const fs::path m_path
path to filesystem storage
std::optional< std::string > ReadImpl(Span< const std::byte > key) const
void Write(const K &key, const V &value, bool fSync=false)
std::unique_ptr< LevelDBContext > m_db_context
holds all leveldb-specific fields of this class
CDBWrapper & operator=(const CDBWrapper &)=delete
bool m_is_memory
whether or not the database resides in memory
auto & DBContext() const LIFETIMEBOUND
bool ExistsImpl(Span< const std::byte > key) const
bool IsEmpty()
Return true if the database managed by this class contains no entries.
size_t EstimateSizeImpl(Span< const std::byte > key1, Span< const std::byte > key2) const
std::optional< fs::path > StoragePath()
size_t EstimateSize(const K &key_begin, const K &key_end) const
Double ended buffer combining vector and stream-like interfaces.
void reserve(size_type n)
A Span is an object that can refer to a contiguous sequence of objects.
dbwrapper_error(const std::string &msg)
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE
bool DestroyDB(const std::string &path_str)
static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE
static const size_t DBWRAPPER_MAX_FILE_SIZE
These should be considered an implementation detail of the specific database.
const std::vector< uint8_t > & GetObfuscateKey(const CDBWrapper &w)
Work around circular dependency, as well as for testing in dbwrapper_tests.
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Span< const std::byte > MakeByteSpan(V &&v) noexcept
User-controlled performance and debug options.
bool force_compact
Compact database on startup.
Application-specific storage settings.
DBOptions options
Passed-through options.
bool obfuscate
If true, store data obfuscated via simple XOR.
bool wipe_data
If true, remove all existing data.
size_t cache_bytes
Configures various leveldb cache settings.
fs::path path
Location in the filesystem where leveldb data will be stored.
bool memory_only
If true, use leveldb's memory environment.