From 53f81574e30c7d6401ebe4ef21fe47e314f1c839 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Tue, 26 Oct 2021 16:20:56 +0800 Subject: [PATCH] ethdb: more accurate batch size calculation (#23790) This PR also counts the size of the key when calculating the size of a db batch --- ethdb/leveldb/leveldb.go | 2 +- ethdb/memorydb/memorydb.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ethdb/leveldb/leveldb.go b/ethdb/leveldb/leveldb.go index 9ff1a2ce1d..9a782dedbe 100644 --- a/ethdb/leveldb/leveldb.go +++ b/ethdb/leveldb/leveldb.go @@ -455,7 +455,7 @@ type batch struct { // Put inserts the given value into the batch for later committing. func (b *batch) Put(key, value []byte) error { b.b.Put(key, value) - b.size += len(value) + b.size += len(key) + len(value) return nil } diff --git a/ethdb/memorydb/memorydb.go b/ethdb/memorydb/memorydb.go index fedc9e326c..78181e860c 100644 --- a/ethdb/memorydb/memorydb.go +++ b/ethdb/memorydb/memorydb.go @@ -204,7 +204,7 @@ type batch struct { // Put inserts the given value into the batch for later committing. func (b *batch) Put(key, value []byte) error { b.writes = append(b.writes, keyvalue{common.CopyBytes(key), common.CopyBytes(value), false}) - b.size += len(value) + b.size += len(key) + len(value) return nil }