mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
ethdb: add ValueSize to Batch
This commit is contained in:
parent
97beadd4fc
commit
1782adb95e
3 changed files with 19 additions and 2 deletions
|
|
@ -280,12 +280,14 @@ func (db *LDBDatabase) NewBatch() Batch {
|
|||
}
|
||||
|
||||
type ldbBatch struct {
|
||||
db *leveldb.DB
|
||||
b *leveldb.Batch
|
||||
db *leveldb.DB
|
||||
b *leveldb.Batch
|
||||
size int
|
||||
}
|
||||
|
||||
func (b *ldbBatch) Put(key, value []byte) error {
|
||||
b.b.Put(key, value)
|
||||
b.size += len(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -293,6 +295,10 @@ func (b *ldbBatch) Write() error {
|
|||
return b.db.Write(b.b, nil)
|
||||
}
|
||||
|
||||
func (b *ldbBatch) ValueSize() int {
|
||||
return b.size
|
||||
}
|
||||
|
||||
type table struct {
|
||||
db Database
|
||||
prefix string
|
||||
|
|
@ -348,3 +354,7 @@ func (tb *tableBatch) Put(key, value []byte) error {
|
|||
func (tb *tableBatch) Write() error {
|
||||
return tb.batch.Write()
|
||||
}
|
||||
|
||||
func (tb *tableBatch) ValueSize() int {
|
||||
return tb.batch.ValueSize()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,5 +39,6 @@ type Database interface {
|
|||
// when Write is called. Batch cannot be used concurrently.
|
||||
type Batch interface {
|
||||
Putter
|
||||
ValueSize() int // amount of data in the batch
|
||||
Write() error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,10 +101,12 @@ type kv struct{ k, v []byte }
|
|||
type memBatch struct {
|
||||
db *MemDatabase
|
||||
writes []kv
|
||||
size int
|
||||
}
|
||||
|
||||
func (b *memBatch) Put(key, value []byte) error {
|
||||
b.writes = append(b.writes, kv{common.CopyBytes(key), common.CopyBytes(value)})
|
||||
b.size += len(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -117,3 +119,7 @@ func (b *memBatch) Write() error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *memBatch) ValueSize() int {
|
||||
return b.size
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue