Merge pull request #821 from karalabe/nodedb-fix

p2p/discover: fix api issues caused by leveldb update
This commit is contained in:
Jeffrey Wilcke 2015-04-28 04:07:14 -07:00
commit a6a49ccbf7
1 changed files with 6 additions and 4 deletions

View File

@ -14,8 +14,10 @@ import (
"github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/iterator" "github.com/syndtr/goleveldb/leveldb/iterator"
"github.com/syndtr/goleveldb/leveldb/storage" "github.com/syndtr/goleveldb/leveldb/storage"
"github.com/syndtr/goleveldb/leveldb/util"
) )
var ( var (
@ -71,7 +73,7 @@ func newMemoryNodeDB() (*nodeDB, error) {
func newPersistentNodeDB(path string, version int) (*nodeDB, error) { func newPersistentNodeDB(path string, version int) (*nodeDB, error) {
// Try to open the cache, recovering any corruption // Try to open the cache, recovering any corruption
db, err := leveldb.OpenFile(path, nil) db, err := leveldb.OpenFile(path, nil)
if _, iscorrupted := err.(leveldb.ErrCorrupted); iscorrupted { if _, iscorrupted := err.(*errors.ErrCorrupted); iscorrupted {
db, err = leveldb.RecoverFile(path, nil) db, err = leveldb.RecoverFile(path, nil)
} }
if err != nil { if err != nil {
@ -227,9 +229,9 @@ func (db *nodeDB) expireNodes() error {
continue continue
} }
// Otherwise delete all associated information // Otherwise delete all associated information
prefix := makeKey(id, "") deleter := db.lvl.NewIterator(util.BytesPrefix(makeKey(id, "")), nil)
for ok := it.Seek(prefix); ok && bytes.HasPrefix(it.Key(), prefix); ok = it.Next() { for deleter.Next() {
if err := db.lvl.Delete(it.Key(), nil); err != nil { if err := db.lvl.Delete(deleter.Key(), nil); err != nil {
return err return err
} }
} }