mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
refactor: Delegate to LevelDB for CDBBatch size estimation
Serialized batch size can be queried via the underlying LevelDB implementation calling the native `leveldb::WriteBatch::ApproximateSize()`. The previous manual calculation was added ine66dbde6d1as part of https://github.com/bitcoin/bitcoin/pull/10195. At that time (April 2017), the version of LevelDB used by Bitcoin Core (and even the latest source) lacked a native function for this. LevelDB added this capability in69e2bd224b, merged later that year. The old manual estimation method (`SizeEstimate()`) is kept temporarily in this commit, and assertions are added in `txdb.cpp` to verify its results against `ApproximateSize()` during batch writes. This ensures the native function behaves as expected before removing the manual calculation in the subsequent commit.
This commit is contained in:
@@ -200,6 +200,11 @@ void CDBBatch::EraseImpl(std::span<const std::byte> key)
|
||||
size_estimate += 2 + (slKey.size() > 127) + slKey.size();
|
||||
}
|
||||
|
||||
size_t CDBBatch::ApproximateSize() const
|
||||
{
|
||||
return m_impl_batch->batch.ApproximateSize();
|
||||
}
|
||||
|
||||
struct LevelDBContext {
|
||||
//! custom environment this database is using (may be nullptr in case of default environment)
|
||||
leveldb::Env* penv;
|
||||
|
||||
Reference in New Issue
Block a user