mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
refactor: Split dbwrapper CDBBatch::Write implementation
Keep the generic serialization in the header, while moving leveldb-specifics to the implementation file. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <logging.h>
|
||||
#include <random.h>
|
||||
#include <span.h>
|
||||
#include <streams.h>
|
||||
#include <tinyformat.h>
|
||||
#include <util/fs.h>
|
||||
#include <util/fs_helpers.h>
|
||||
@@ -23,7 +25,9 @@
|
||||
#include <leveldb/helpers/memenv/memenv.h>
|
||||
#include <leveldb/iterator.h>
|
||||
#include <leveldb/options.h>
|
||||
#include <leveldb/slice.h>
|
||||
#include <leveldb/status.h>
|
||||
#include <leveldb/write_batch.h>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
@@ -132,6 +136,22 @@ static leveldb::Options GetOptions(size_t nCacheSize)
|
||||
return options;
|
||||
}
|
||||
|
||||
void CDBBatch::WriteImpl(Span<const std::byte> ssKey, CDataStream& ssValue)
|
||||
{
|
||||
leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
|
||||
ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent));
|
||||
leveldb::Slice slValue(CharCast(ssValue.data()), ssValue.size());
|
||||
batch.Put(slKey, slValue);
|
||||
// LevelDB serializes writes as:
|
||||
// - byte: header
|
||||
// - varint: key length (1 byte up to 127B, 2 bytes up to 16383B, ...)
|
||||
// - byte[]: key
|
||||
// - varint: value length
|
||||
// - byte[]: value
|
||||
// The formula below assumes the key and value are both less than 16k.
|
||||
size_estimate += 3 + (slKey.size() > 127) + slKey.size() + (slValue.size() > 127) + slValue.size();
|
||||
}
|
||||
|
||||
CDBWrapper::CDBWrapper(const DBParams& params)
|
||||
: m_name{fs::PathToString(params.path.stem())}, m_path{params.path}, m_is_memory{params.memory_only}
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user