Browse Source

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

Closes: #2292
pull/2250/merge
Alessio Treglia 6 years ago
committed by Anton Kaliaev
parent
commit
c43fb700e3
3 changed files with 27 additions and 1 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +5
    -1
      libs/db/go_level_db.go
  3. +21
    -0
      libs/db/go_level_db_test.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -23,6 +23,7 @@ BREAKING CHANGES:
FEATURES: FEATURES:
- [types] allow genesis file to have 0 validators ([#2015](https://github.com/tendermint/tendermint/issues/2015)) - [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: IMPROVEMENTS:
- [docs] Lint documentation with `write-good` and `stop-words`. - [docs] Lint documentation with `write-good` and `stop-words`.


+ 5
- 1
libs/db/go_level_db.go View File

@ -28,8 +28,12 @@ type GoLevelDB struct {
} }
func NewGoLevelDB(name string, dir string) (*GoLevelDB, error) { 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") dbPath := filepath.Join(dir, name+".db")
db, err := leveldb.OpenFile(dbPath, nil)
db, err := leveldb.OpenFile(dbPath, o)
if err != nil { if err != nil {
return nil, err return nil, err
} }


+ 21
- 0
libs/db/go_level_db_test.go View File

@ -6,9 +6,30 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/syndtr/goleveldb/leveldb/opt"
"github.com/stretchr/testify/require"
cmn "github.com/tendermint/tendermint/libs/common" 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) { func BenchmarkRandomReadsWrites(b *testing.B) {
b.StopTimer() b.StopTimer()


Loading…
Cancel
Save