eth: fixed chaindb upgrade

pull/2834/head
zsfelfoldi 8 years ago
parent a4c4125b11
commit 56efed71b5
  1. 13
      eth/db_upgrade.go

@ -93,6 +93,9 @@ func upgradeSequentialKeys(db ethdb.Database) (stopFn func()) {
func upgradeSequentialCanonicalNumbers(db ethdb.Database, stopFn func() bool) (error, bool) { func upgradeSequentialCanonicalNumbers(db ethdb.Database, stopFn func() bool) (error, bool) {
prefix := []byte("block-num-") prefix := []byte("block-num-")
it := db.(*ethdb.LDBDatabase).NewIterator() it := db.(*ethdb.LDBDatabase).NewIterator()
defer func() {
it.Release()
}()
it.Seek(prefix) it.Seek(prefix)
cnt := 0 cnt := 0
for bytes.HasPrefix(it.Key(), prefix) { for bytes.HasPrefix(it.Key(), prefix) {
@ -100,6 +103,9 @@ func upgradeSequentialCanonicalNumbers(db ethdb.Database, stopFn func() bool) (e
if len(keyPtr) < 20 { if len(keyPtr) < 20 {
cnt++ cnt++
if cnt%100000 == 0 { if cnt%100000 == 0 {
it.Release()
it = db.(*ethdb.LDBDatabase).NewIterator()
it.Seek(keyPtr)
glog.V(logger.Info).Infof("converting %d canonical numbers...", cnt) glog.V(logger.Info).Infof("converting %d canonical numbers...", cnt)
} }
number := big.NewInt(0).SetBytes(keyPtr[10:]).Uint64() number := big.NewInt(0).SetBytes(keyPtr[10:]).Uint64()
@ -130,6 +136,9 @@ func upgradeSequentialCanonicalNumbers(db ethdb.Database, stopFn func() bool) (e
func upgradeSequentialBlocks(db ethdb.Database, stopFn func() bool) (error, bool) { func upgradeSequentialBlocks(db ethdb.Database, stopFn func() bool) (error, bool) {
prefix := []byte("block-") prefix := []byte("block-")
it := db.(*ethdb.LDBDatabase).NewIterator() it := db.(*ethdb.LDBDatabase).NewIterator()
defer func() {
it.Release()
}()
it.Seek(prefix) it.Seek(prefix)
cnt := 0 cnt := 0
for bytes.HasPrefix(it.Key(), prefix) { for bytes.HasPrefix(it.Key(), prefix) {
@ -137,6 +146,9 @@ func upgradeSequentialBlocks(db ethdb.Database, stopFn func() bool) (error, bool
if len(keyPtr) >= 38 { if len(keyPtr) >= 38 {
cnt++ cnt++
if cnt%10000 == 0 { if cnt%10000 == 0 {
it.Release()
it = db.(*ethdb.LDBDatabase).NewIterator()
it.Seek(keyPtr)
glog.V(logger.Info).Infof("converting %d blocks...", cnt) glog.V(logger.Info).Infof("converting %d blocks...", cnt)
} }
// convert header, body, td and block receipts // convert header, body, td and block receipts
@ -175,6 +187,7 @@ func upgradeSequentialBlocks(db ethdb.Database, stopFn func() bool) (error, bool
func upgradeSequentialOrphanedReceipts(db ethdb.Database, stopFn func() bool) (error, bool) { func upgradeSequentialOrphanedReceipts(db ethdb.Database, stopFn func() bool) (error, bool) {
prefix := []byte("receipts-block-") prefix := []byte("receipts-block-")
it := db.(*ethdb.LDBDatabase).NewIterator() it := db.(*ethdb.LDBDatabase).NewIterator()
defer it.Release()
it.Seek(prefix) it.Seek(prefix)
cnt := 0 cnt := 0
for bytes.HasPrefix(it.Key(), prefix) { for bytes.HasPrefix(it.Key(), prefix) {

Loading…
Cancel
Save