Browse Source

Merge pull request #140 from tendermint/sdk2-hashers-and-simple-map

Sdk2 hashers and simple map
pull/1842/head
Anton Kaliaev 7 years ago
committed by GitHub
parent
commit
95b53c80e1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 20 deletions
  1. +3
    -3
      db/backend_test.go
  2. +2
    -2
      db/c_level_db.go
  3. +2
    -2
      db/c_level_db_test.go
  4. +1
    -1
      db/common_test.go
  5. +10
    -8
      db/db.go
  6. +1
    -1
      db/fsdb.go
  7. +2
    -2
      db/go_level_db.go
  8. +1
    -1
      db/mem_db.go

+ 3
- 3
db/backend_test.go View File

@ -15,7 +15,7 @@ func cleanupDBDir(dir, name string) {
os.RemoveAll(filepath.Join(dir, name) + ".db")
}
func testBackendGetSetDelete(t *testing.T, backend string) {
func testBackendGetSetDelete(t *testing.T, backend dbBackendType) {
// Default
dir, dirname := cmn.Tempdir(fmt.Sprintf("test_backend_%s_", backend))
defer dir.Close()
@ -141,9 +141,9 @@ func TestBackendsNilKeys(t *testing.T) {
}
}
func TestGoLevelDBBackendStr(t *testing.T) {
func TestGoLevelDBBackend(t *testing.T) {
name := cmn.Fmt("test_%x", cmn.RandStr(12))
db := NewDB(name, GoLevelDBBackendStr, "")
db := NewDB(name, GoLevelDBBackend, "")
defer cleanupDBDir("", name)
_, ok := db.(*GoLevelDB)


+ 2
- 2
db/c_level_db.go View File

@ -14,8 +14,8 @@ func init() {
dbCreator := func(name string, dir string) (DB, error) {
return NewCLevelDB(name, dir)
}
registerDBCreator(LevelDBBackendStr, dbCreator, true)
registerDBCreator(CLevelDBBackendStr, dbCreator, false)
registerDBCreator(LevelDBBackend, dbCreator, true)
registerDBCreator(CLevelDBBackend, dbCreator, false)
}
var _ DB = (*CLevelDB)(nil)


+ 2
- 2
db/c_level_db_test.go View File

@ -86,9 +86,9 @@ func bytes2Int64(buf []byte) int64 {
}
*/
func TestCLevelDBBackendStr(t *testing.T) {
func TestCLevelDBBackend(t *testing.T) {
name := cmn.Fmt("test_%x", cmn.RandStr(12))
db := NewDB(name, LevelDBBackendStr, "")
db := NewDB(name, LevelDBBackend, "")
defer cleanupDBDir("", name)
_, ok := db.(*CLevelDB)


+ 1
- 1
db/common_test.go View File

@ -45,7 +45,7 @@ func checkValuePanics(t *testing.T, itr Iterator) {
assert.Panics(t, func() { itr.Key() }, "checkValuePanics expected panic but didn't")
}
func newTempDB(t *testing.T, backend string) (db DB) {
func newTempDB(t *testing.T, backend dbBackendType) (db DB) {
dir, dirname := cmn.Tempdir("test_go_iterator")
db = NewDB("testdb", backend, dirname)
dir.Close()


+ 10
- 8
db/db.go View File

@ -5,19 +5,21 @@ import "fmt"
//----------------------------------------
// Main entry
type dbBackendType string
const (
LevelDBBackendStr = "leveldb" // legacy, defaults to goleveldb unless +gcc
CLevelDBBackendStr = "cleveldb"
GoLevelDBBackendStr = "goleveldb"
MemDBBackendStr = "memdb"
FSDBBackendStr = "fsdb" // using the filesystem naively
LevelDBBackend dbBackendType = "leveldb" // legacy, defaults to goleveldb unless +gcc
CLevelDBBackend dbBackendType = "cleveldb"
GoLevelDBBackend dbBackendType = "goleveldb"
MemDBBackend dbBackendType = "memdb"
FSDBBackend dbBackendType = "fsdb" // using the filesystem naively
)
type dbCreator func(name string, dir string) (DB, error)
var backends = map[string]dbCreator{}
var backends = map[dbBackendType]dbCreator{}
func registerDBCreator(backend string, creator dbCreator, force bool) {
func registerDBCreator(backend dbBackendType, creator dbCreator, force bool) {
_, ok := backends[backend]
if !force && ok {
return
@ -25,7 +27,7 @@ func registerDBCreator(backend string, creator dbCreator, force bool) {
backends[backend] = creator
}
func NewDB(name string, backend string, dir string) DB {
func NewDB(name string, backend dbBackendType, dir string) DB {
db, err := backends[backend](name, dir)
if err != nil {
panic(fmt.Sprintf("Error initializing DB: %v", err))


+ 1
- 1
db/fsdb.go View File

@ -19,7 +19,7 @@ const (
)
func init() {
registerDBCreator(FSDBBackendStr, func(name string, dir string) (DB, error) {
registerDBCreator(FSDBBackend, func(name string, dir string) (DB, error) {
dbPath := filepath.Join(dir, name+".db")
return NewFSDB(dbPath), nil
}, false)


+ 2
- 2
db/go_level_db.go View File

@ -17,8 +17,8 @@ func init() {
dbCreator := func(name string, dir string) (DB, error) {
return NewGoLevelDB(name, dir)
}
registerDBCreator(LevelDBBackendStr, dbCreator, false)
registerDBCreator(GoLevelDBBackendStr, dbCreator, false)
registerDBCreator(LevelDBBackend, dbCreator, false)
registerDBCreator(GoLevelDBBackend, dbCreator, false)
}
var _ DB = (*GoLevelDB)(nil)


+ 1
- 1
db/mem_db.go View File

@ -7,7 +7,7 @@ import (
)
func init() {
registerDBCreator(MemDBBackendStr, func(name string, dir string) (DB, error) {
registerDBCreator(MemDBBackend, func(name string, dir string) (DB, error) {
return NewMemDB(), nil
}, false)
}


Loading…
Cancel
Save