@@ -10,7 +10,6 @@ import (
10
10
"bytes"
11
11
"context"
12
12
13
- "github.com/iotexproject/go-pkgs/cache"
14
13
"github.com/pkg/errors"
15
14
bolt "go.etcd.io/bbolt"
16
15
@@ -23,19 +22,17 @@ const fileMode = 0600
23
22
24
23
// boltDB is KVStore implementation based bolt DB
25
24
type boltDB struct {
26
- db * bolt.DB
27
- path string
28
- config config.DB
29
- fillPercent * cache.ThreadSafeLruCache // specific fill percent for certain buckets (for example, 1.0 for append-only)
25
+ db * bolt.DB
26
+ path string
27
+ config config.DB
30
28
}
31
29
32
30
// NewBoltDB instantiates an BoltDB with implements KVStore
33
31
func NewBoltDB (cfg config.DB ) KVStoreWithBucketFillPercent {
34
32
return & boltDB {
35
- db : nil ,
36
- path : cfg .DbPath ,
37
- config : cfg ,
38
- fillPercent : cache .NewThreadSafeLruCache (256 ),
33
+ db : nil ,
34
+ path : cfg .DbPath ,
35
+ config : cfg ,
39
36
}
40
37
}
41
38
@@ -67,9 +64,6 @@ func (b *boltDB) Put(namespace string, key, value []byte) (err error) {
67
64
if err != nil {
68
65
return err
69
66
}
70
- if p , ok := b .getBucketFillPercent (namespace ); ok {
71
- bucket .FillPercent = p
72
- }
73
67
return bucket .Put (key , value )
74
68
}); err == nil {
75
69
break
@@ -257,6 +251,15 @@ func (b *boltDB) Delete(namespace string, key []byte) (err error) {
257
251
258
252
// WriteBatch commits a batch
259
253
func (b * boltDB ) WriteBatch (kvsb batch.KVStoreBatch ) (err error ) {
254
+ return b .writeBatch (kvsb , 0.0 )
255
+ }
256
+
257
+ // WriteBatchWithFillPercent commits a batch with specified fill percent
258
+ func (b * boltDB ) WriteBatchWithFillPercent (kvsb batch.KVStoreBatch , percent float64 ) (err error ) {
259
+ return b .writeBatch (kvsb , percent )
260
+ }
261
+
262
+ func (b * boltDB ) writeBatch (kvsb batch.KVStoreBatch , percent float64 ) (err error ) {
260
263
succeed := true
261
264
kvsb .Lock ()
262
265
defer func () {
@@ -283,8 +286,8 @@ func (b *boltDB) WriteBatch(kvsb batch.KVStoreBatch) (err error) {
283
286
if e != nil {
284
287
return errors .Wrapf (e , errFmt , errArgs )
285
288
}
286
- if p , ok := b . getBucketFillPercent ( ns ); ok {
287
- bucket .FillPercent = p
289
+ if percent != 0.0 {
290
+ bucket .FillPercent = percent
288
291
}
289
292
if e := bucket .Put (write .Key (), write .Value ()); e != nil {
290
293
return errors .Wrapf (e , errFmt , errArgs )
@@ -312,19 +315,6 @@ func (b *boltDB) WriteBatch(kvsb batch.KVStoreBatch) (err error) {
312
315
return err
313
316
}
314
317
315
- // SetBucketFillPercent sets specified fill percent for a bucket
316
- func (b * boltDB ) SetBucketFillPercent (namespace string , percent float64 ) error {
317
- b .fillPercent .Add (namespace , percent )
318
- return nil
319
- }
320
-
321
- func (b * boltDB ) getBucketFillPercent (namespace string ) (float64 , bool ) {
322
- if p , hit := b .fillPercent .Get (namespace ); hit {
323
- return p .(float64 ), true
324
- }
325
- return 0 , false
326
- }
327
-
328
318
// ======================================
329
319
// below functions used by RangeIndex
330
320
// ======================================
0 commit comments