diff options
Diffstat (limited to 'src/dbwrapper.cpp')
-rw-r--r-- | src/dbwrapper.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index b74c645b8f..ff2bc8b4e8 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -4,8 +4,10 @@ #include <dbwrapper.h> +#include <clientversion.h> #include <logging.h> #include <random.h> +#include <serialize.h> #include <span.h> #include <streams.h> #include <tinyformat.h> @@ -136,12 +138,28 @@ static leveldb::Options GetOptions(size_t nCacheSize) return options; } +struct CDBBatch::WriteBatchImpl { + leveldb::WriteBatch batch; +}; + +CDBBatch::CDBBatch(const CDBWrapper& _parent) : parent(_parent), + m_impl_batch{std::make_unique<CDBBatch::WriteBatchImpl>()}, + ssValue(SER_DISK, CLIENT_VERSION){}; + +CDBBatch::~CDBBatch() = default; + +void CDBBatch::Clear() +{ + m_impl_batch->batch.Clear(); + size_estimate = 0; +} + 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); + m_impl_batch->batch.Put(slKey, slValue); // LevelDB serializes writes as: // - byte: header // - varint: key length (1 byte up to 127B, 2 bytes up to 16383B, ...) @@ -155,7 +173,7 @@ void CDBBatch::WriteImpl(Span<const std::byte> ssKey, CDataStream& ssValue) void CDBBatch::EraseImpl(Span<const std::byte> ssKey) { leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size()); - batch.Delete(slKey); + m_impl_batch->batch.Delete(slKey); // LevelDB serializes erases as: // - byte: header // - varint: key length @@ -241,7 +259,7 @@ bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync) if (log_memory) { mem_before = DynamicMemoryUsage() / 1024.0 / 1024; } - leveldb::Status status = pdb->Write(fSync ? syncoptions : writeoptions, &batch.batch); + leveldb::Status status = pdb->Write(fSync ? syncoptions : writeoptions, &batch.m_impl_batch->batch); dbwrapper_private::HandleError(status); if (log_memory) { double mem_after = DynamicMemoryUsage() / 1024.0 / 1024; |