channeldb/migrations: improve performance of edge update migration
This commit modifies the edge update index migration to avoid repetitive calls to Cursor.First(). Instead, we construct a set of all edge update keys to remove, and then do a second pass to remove each from the bucket. Additional log messages are included to notify users on progress, as some have reported long migration times.
This commit is contained in:
parent
3b2c807288
commit
974ec02d24
@ -514,19 +514,34 @@ func migratePruneEdgeUpdateIndex(tx *bolt.Tx) error {
|
|||||||
err)
|
err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// With the existing edge policies gathered, we'll recreate the index
|
log.Info("Constructing set of edge update entries to purge.")
|
||||||
// and populate it with the correct entries.
|
|
||||||
//
|
// Build the set of keys that we will remove from the edge update index.
|
||||||
// NOTE: In bolt DB, calling Delete() on an iterator will actually move
|
// This will include all keys contained within the bucket.
|
||||||
// it to the NEXT item. As a result, we call First() here again to go
|
var updateKeysToRemove [][]byte
|
||||||
// back to the front after the item has been deleted.
|
err = edgeUpdateIndex.ForEach(func(updKey, _ []byte) error {
|
||||||
updateCursor := edgeUpdateIndex.Cursor()
|
updateKeysToRemove = append(updateKeysToRemove, updKey)
|
||||||
for k, _ := updateCursor.First(); k != nil; k, _ = updateCursor.First() {
|
return nil
|
||||||
if err := updateCursor.Delete(); err != nil {
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to gather existing edge updates: %v",
|
||||||
|
err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("Removing %d entries from edge update index.",
|
||||||
|
len(updateKeysToRemove))
|
||||||
|
|
||||||
|
// With the set of keys contained in the edge update index constructed,
|
||||||
|
// we'll proceed in purging all of them from the index.
|
||||||
|
for _, updKey := range updateKeysToRemove {
|
||||||
|
if err := edgeUpdateIndex.Delete(updKey); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Infof("Repopulating edge update index with %d valid entries.",
|
||||||
|
len(edgeKeys))
|
||||||
|
|
||||||
// For each edge key, we'll retrieve the policy, deserialize it, and
|
// For each edge key, we'll retrieve the policy, deserialize it, and
|
||||||
// re-add it to the different buckets. By doing so, we'll ensure that
|
// re-add it to the different buckets. By doing so, we'll ensure that
|
||||||
// all existing edge policies are serialized correctly within their
|
// all existing edge policies are serialized correctly within their
|
||||||
|
Loading…
Reference in New Issue
Block a user