summaryrefslogtreecommitdiffstats
path: root/lib/db/namespaced.go
diff options
context:
space:
mode:
authorSimon Frei <freisim93@gmail.com>2019-02-15 00:15:13 +0100
committerAudrius Butkevicius <audrius.butkevicius@gmail.com>2019-02-14 23:15:13 +0000
commitca3ae64bbf019ee68731dab8796f6a22c83509e9 (patch)
treea561d11f86325f7eec9cea1daf2a55506e91c8b4 /lib/db/namespaced.go
parente2204d007199a60e2adf7fc7ba6e720405e3e711 (diff)
lib/db: Flush batch based on size and refactor (fixes #5531) (#5536)
Flush the batch when exceeding a certain size, instead of when reaching a number of batched operations. Move batch to lowlevel to be able to use it in NamespacedKV. Increase the leveldb memory buffer from 4 to 16 MiB.
Diffstat (limited to 'lib/db/namespaced.go')
-rw-r--r--lib/db/namespaced.go16
1 files changed, 3 insertions, 13 deletions
diff --git a/lib/db/namespaced.go b/lib/db/namespaced.go
index fd6432726e..5cbe720bba 100644
--- a/lib/db/namespaced.go
+++ b/lib/db/namespaced.go
@@ -10,7 +10,6 @@ import (
"encoding/binary"
"time"
- "github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/util"
)
@@ -39,21 +38,12 @@ func NewNamespacedKV(db *Lowlevel, prefix string) *NamespacedKV {
func (n *NamespacedKV) Reset() {
it := n.db.NewIterator(util.BytesPrefix(n.prefix), nil)
defer it.Release()
- batch := new(leveldb.Batch)
+ batch := n.db.newBatch()
for it.Next() {
batch.Delete(it.Key())
- if batch.Len() > batchFlushSize {
- if err := n.db.Write(batch, nil); err != nil {
- panic(err)
- }
- batch.Reset()
- }
- }
- if batch.Len() > 0 {
- if err := n.db.Write(batch, nil); err != nil {
- panic(err)
- }
+ batch.checkFlush()
}
+ batch.flush()
}
// PutInt64 stores a new int64. Any existing value (even if of another type)