catch up to new goleveldb
This commit is contained in:
parent
6b18796af7
commit
6578e7345f
1 changed files with 10 additions and 10 deletions
|
@ -65,7 +65,7 @@ func init() {
|
||||||
func OpenDB(dbpath string) (btcdb.Db, error) {
|
func OpenDB(dbpath string) (btcdb.Db, error) {
|
||||||
log = btcdb.GetLog()
|
log = btcdb.GetLog()
|
||||||
|
|
||||||
db, err := openDB(dbpath, 0)
|
db, err := openDB(dbpath, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ blocknarrow:
|
||||||
|
|
||||||
var CurrentDBVersion int32 = 1
|
var CurrentDBVersion int32 = 1
|
||||||
|
|
||||||
func openDB(dbpath string, flag opt.OptionsFlag) (pbdb btcdb.Db, err error) {
|
func openDB(dbpath string, create bool) (pbdb btcdb.Db, err error) {
|
||||||
var db LevelDb
|
var db LevelDb
|
||||||
var tlDb *leveldb.DB
|
var tlDb *leveldb.DB
|
||||||
var dbversion int32
|
var dbversion int32
|
||||||
|
@ -143,7 +143,7 @@ func openDB(dbpath string, flag opt.OptionsFlag) (pbdb btcdb.Db, err error) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if flag&opt.OFCreateIfMissing == opt.OFCreateIfMissing {
|
if create == true {
|
||||||
err = os.Mkdir(dbpath, 0750)
|
err = os.Mkdir(dbpath, 0750)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("mkdir failed %v %v", dbpath, err)
|
log.Errorf("mkdir failed %v %v", dbpath, err)
|
||||||
|
@ -168,22 +168,22 @@ func openDB(dbpath string, flag opt.OptionsFlag) (pbdb btcdb.Db, err error) {
|
||||||
dbversion = ^0
|
dbversion = ^0
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if flag&opt.OFCreateIfMissing != 0 {
|
if create == true {
|
||||||
needVersionFile = true
|
needVersionFile = true
|
||||||
dbversion = CurrentDBVersion
|
dbversion = CurrentDBVersion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
myCache := cache.NewEmptyCache()
|
myCache := cache.NewEmptyCache()
|
||||||
opts := &opt.Options{Flag: flag,
|
opts := &opt.Options{
|
||||||
BlockCache: myCache,
|
BlockCache: myCache,
|
||||||
MaxOpenFiles: 256,
|
MaxOpenFiles: 256,
|
||||||
CompressionType: opt.NoCompression,
|
Compression: opt.NoCompression,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch dbversion {
|
switch dbversion {
|
||||||
case 0:
|
case 0:
|
||||||
opts = &opt.Options{Flag: flag}
|
opts = &opt.Options{}
|
||||||
case 1:
|
case 1:
|
||||||
// uses defaults from above
|
// uses defaults from above
|
||||||
default:
|
default:
|
||||||
|
@ -220,7 +220,7 @@ func CreateDB(dbpath string) (btcdb.Db, error) {
|
||||||
log = btcdb.GetLog()
|
log = btcdb.GetLog()
|
||||||
|
|
||||||
// No special setup needed, just OpenBB
|
// No special setup needed, just OpenBB
|
||||||
db, err := openDB(dbpath, opt.OFCreateIfMissing)
|
db, err := openDB(dbpath, true)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ldb := db.(*LevelDb)
|
ldb := db.(*LevelDb)
|
||||||
ldb.lastBlkIdx = -1
|
ldb.lastBlkIdx = -1
|
||||||
|
|
Loading…
Add table
Reference in a new issue