Merge pull request #388 from MachineShop-IOT/master
Add bucket fillPercent option for boltdb
This commit is contained in:
commit
58457e7d66
|
@ -33,11 +33,12 @@ const (
|
|||
)
|
||||
|
||||
type Store struct {
|
||||
path string
|
||||
bucket string
|
||||
db *bolt.DB
|
||||
noSync bool
|
||||
mo store.MergeOperator
|
||||
path string
|
||||
bucket string
|
||||
db *bolt.DB
|
||||
noSync bool
|
||||
fillPercent float64
|
||||
mo store.MergeOperator
|
||||
}
|
||||
|
||||
func New(mo store.MergeOperator, config map[string]interface{}) (store.KVStore, error) {
|
||||
|
@ -53,6 +54,11 @@ func New(mo store.MergeOperator, config map[string]interface{}) (store.KVStore,
|
|||
|
||||
noSync, _ := config["nosync"].(bool)
|
||||
|
||||
fillPercent, ok := config["fillPercent"].(float64)
|
||||
if !ok {
|
||||
fillPercent = bolt.DefaultFillPercent
|
||||
}
|
||||
|
||||
db, err := bolt.Open(path, 0600, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -69,11 +75,12 @@ func New(mo store.MergeOperator, config map[string]interface{}) (store.KVStore,
|
|||
}
|
||||
|
||||
rv := Store{
|
||||
path: path,
|
||||
bucket: bucket,
|
||||
db: db,
|
||||
mo: mo,
|
||||
noSync: noSync,
|
||||
path: path,
|
||||
bucket: bucket,
|
||||
db: db,
|
||||
mo: mo,
|
||||
noSync: noSync,
|
||||
fillPercent: fillPercent,
|
||||
}
|
||||
return &rv, nil
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
|
||||
"github.com/blevesearch/bleve/index/store"
|
||||
"github.com/blevesearch/bleve/index/store/test"
|
||||
"github.com/boltdb/bolt"
|
||||
)
|
||||
|
||||
func open(t *testing.T, mo store.MergeOperator) store.KVStore {
|
||||
|
@ -89,3 +90,52 @@ func TestBoltDBMerge(t *testing.T) {
|
|||
defer cleanup(t, s)
|
||||
test.CommonTestMerge(t, s)
|
||||
}
|
||||
|
||||
func TestBoltDBConfig(t *testing.T) {
|
||||
var tests = []struct {
|
||||
in map[string]interface{}
|
||||
path string
|
||||
bucket string
|
||||
noSync bool
|
||||
fillPercent float64
|
||||
}{
|
||||
{
|
||||
map[string]interface{}{"path": "test", "bucket": "mybucket", "nosync": true, "fillPercent": 0.75},
|
||||
"test",
|
||||
"mybucket",
|
||||
true,
|
||||
0.75,
|
||||
},
|
||||
{
|
||||
map[string]interface{}{"path": "test"},
|
||||
"test",
|
||||
"bleve",
|
||||
false,
|
||||
bolt.DefaultFillPercent,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
kv, err := New(nil, test.in)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bs, ok := kv.(*Store)
|
||||
if !ok {
|
||||
t.Fatal("failed type assertion to *boltdb.Store")
|
||||
}
|
||||
if bs.path != test.path {
|
||||
t.Fatalf("path: expected %q, got %q", test.path, bs.path)
|
||||
}
|
||||
if bs.bucket != test.bucket {
|
||||
t.Fatalf("bucket: expected %q, got %q", test.bucket, bs.bucket)
|
||||
}
|
||||
if bs.noSync != test.noSync {
|
||||
t.Fatalf("noSync: expected %t, got %t", test.noSync, bs.noSync)
|
||||
}
|
||||
if bs.fillPercent != test.fillPercent {
|
||||
t.Fatalf("fillPercent: expected %f, got %f", test.fillPercent, bs.fillPercent)
|
||||
}
|
||||
cleanup(t, kv)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ func (w *Writer) ExecuteBatch(batch store.KVBatch) error {
|
|||
}
|
||||
|
||||
bucket := tx.Bucket([]byte(w.store.bucket))
|
||||
bucket.FillPercent = w.store.fillPercent
|
||||
|
||||
for k, mergeOps := range emulatedBatch.Merger.Merges {
|
||||
kb := []byte(k)
|
||||
|
|
Loading…
Reference in New Issue
Block a user