New NewGoLevelDBWithOpts() to pass opts down to goleveldb (#2293)

Closes: #2292
This commit is contained in:
Alessio Treglia
2018-08-29 08:44:55 +04:00
committed by Anton Kaliaev
parent bd531401a0
commit c43fb700e3
3 changed files with 27 additions and 1 deletions
+1
View File
@@ -23,6 +23,7 @@ BREAKING CHANGES:
FEATURES:
- [types] allow genesis file to have 0 validators ([#2015](https://github.com/tendermint/tendermint/issues/2015))
- [libs] allow passing options through when creating instances of leveldb dbs ([#2292](https://github.com/tendermint/tendermint/issues/2292))
IMPROVEMENTS:
- [docs] Lint documentation with `write-good` and `stop-words`.
+5 -1
View File
@@ -28,8 +28,12 @@ type GoLevelDB struct {
}
func NewGoLevelDB(name string, dir string) (*GoLevelDB, error) {
return NewGoLevelDBWithOpts(name, dir, nil)
}
func NewGoLevelDBWithOpts(name string, dir string, o *opt.Options) (*GoLevelDB, error) {
dbPath := filepath.Join(dir, name+".db")
db, err := leveldb.OpenFile(dbPath, nil)
db, err := leveldb.OpenFile(dbPath, o)
if err != nil {
return nil, err
}
+21
View File
@@ -6,9 +6,30 @@ import (
"fmt"
"testing"
"github.com/syndtr/goleveldb/leveldb/opt"
"github.com/stretchr/testify/require"
cmn "github.com/tendermint/tendermint/libs/common"
)
func TestNewGoLevelDB(t *testing.T) {
name := fmt.Sprintf("test_%x", cmn.RandStr(12))
// Test write locks
db, err := NewGoLevelDB(name, "")
require.Nil(t, err)
_, err = NewGoLevelDB(name, "")
require.NotNil(t, err)
db.Close() // Close the db to release the lock
// Open the db twice in a row to test read-only locks
ro1, err := NewGoLevelDBWithOpts(name, "", &opt.Options{ReadOnly: true})
defer ro1.Close()
require.Nil(t, err)
ro2, err := NewGoLevelDBWithOpts(name, "", &opt.Options{ReadOnly: true})
defer ro2.Close()
require.Nil(t, err)
}
func BenchmarkRandomReadsWrites(b *testing.B) {
b.StopTimer()