channeldb: don't use KeyN in latest migration
In this commit, we fix a bug in the latest migration that could cause the migration to end in a panic. Additionally, we modify the migration to exit early if the bucket wasn't found, as in this case, no migration is required. Fixes #1874.
This commit is contained in:
parent
e23f889639
commit
034198ffb7
@ -473,12 +473,9 @@ func migratePruneEdgeUpdateIndex(tx *bolt.Tx) error {
|
|||||||
if edges == nil {
|
if edges == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
edgeUpdateIndex, err := edges.CreateBucketIfNotExists(
|
edgeUpdateIndex := edges.Bucket(edgeUpdateIndexBucket)
|
||||||
edgeUpdateIndexBucket,
|
if edgeUpdateIndex == nil {
|
||||||
)
|
return nil
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unable to create/fetch edge update " +
|
|
||||||
"index bucket")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve some buckets that will be needed later on. These should
|
// Retrieve some buckets that will be needed later on. These should
|
||||||
@ -518,7 +515,6 @@ func migratePruneEdgeUpdateIndex(tx *bolt.Tx) error {
|
|||||||
|
|
||||||
// With the existing edge policies gathered, we'll recreate the index
|
// With the existing edge policies gathered, we'll recreate the index
|
||||||
// and populate it with the correct entries.
|
// and populate it with the correct entries.
|
||||||
oldNumEntries := edgeUpdateIndex.Stats().KeyN
|
|
||||||
if err := edges.DeleteBucket(edgeUpdateIndexBucket); err != nil {
|
if err := edges.DeleteBucket(edgeUpdateIndexBucket); err != nil {
|
||||||
return fmt.Errorf("unable to remove existing edge update "+
|
return fmt.Errorf("unable to remove existing edge update "+
|
||||||
"index: %v", err)
|
"index: %v", err)
|
||||||
@ -558,10 +554,6 @@ func migratePruneEdgeUpdateIndex(tx *bolt.Tx) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newNumEntries := edgeUpdateIndex.Stats().KeyN
|
|
||||||
log.Infof("Pruned %d stale entries from the edge update index",
|
|
||||||
oldNumEntries-newNumEntries)
|
|
||||||
|
|
||||||
log.Info("Migration to properly prune edge update index complete!")
|
log.Info("Migration to properly prune edge update index complete!")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user