Browse Source

Move cleveldb to own file w/ build tag condition 'gcc'

pull/1842/head
Jae Kwon 8 years ago
parent
commit
5ab5538d6c
6 changed files with 84 additions and 68 deletions
  1. +27
    -19
      c_level_db.go
  2. +3
    -1
      c_level_db_test.go
  3. +22
    -28
      db.go
  4. +25
    -19
      go_level_db.go
  5. +1
    -1
      go_level_db_test.go
  6. +6
    -0
      mem_db.go

level_db2.go → c_level_db.go View File


level_db2_test.go → c_level_db_test.go View File


+ 22
- 28
db.go View File

@ -1,10 +1,6 @@
package db
import (
"path"
. "github.com/tendermint/go-common"
)
import . "github.com/tendermint/go-common"
type DB interface {
Get([]byte) []byte
@ -27,30 +23,28 @@ type Batch interface {
//-----------------------------------------------------------------------------
// Database types
const DBBackendMemDB = "memdb"
const DBBackendLevelDB = "leveldb"
const DBBackendLevelDB2 = "leveldb2"
const (
CLevelDBBackendStr = "goleveldb"
GoLevelDBBackendStr = "cleveldb"
MemDBBackendStr = "memdb"
)
type dbCreator func(name string, dir string) (DB, error)
var backends map[string]dbCreator
func registerDBCreator(backend string, creator dbCreator, force bool) {
_, ok := backends[backend]
if !force && ok {
return
}
backends[backend] = creator
}
func NewDB(name string, backend string, dir string) DB {
switch backend {
case DBBackendMemDB:
db := NewMemDB()
return db
case DBBackendLevelDB:
db, err := NewLevelDB(path.Join(dir, name+".db"))
if err != nil {
PanicCrisis(err)
}
return db
case DBBackendLevelDB2:
db, err := NewLevelDB2(path.Join(dir, name+".db"))
if err != nil {
PanicCrisis(err)
}
return db
default:
PanicSanity(Fmt("Unknown DB backend: %v", backend))
db, err := backends[backend](name, dir)
if err != nil {
PanicSanity(Fmt("Error initializing DB: %v", err))
}
return nil
return db
}

level_db.go → go_level_db.go View File


level_db_test.go → go_level_db_test.go View File


+ 6
- 0
mem_db.go View File

@ -5,6 +5,12 @@ import (
"sync"
)
func init() {
registerDBCreator(MemDBBackendStr, func(name string, dir string) (DB, error) {
return NewMemDB(), nil
}, false)
}
type MemDB struct {
mtx sync.Mutex
db map[string][]byte


Loading…
Cancel
Save