Skip to content

Commit

Permalink
channeldb: fix bug in migration from 0.4 to 0.5
Browse files Browse the repository at this point in the history
In this commit, we fix a bug in the latest database migration when
migrating from 0.4 to 0.5. There's an issue in bolt db where if one
deletes a bucket that has a key with a nil value, it thinks that's a sub
bucket and attempts a bucket deletion. This will fail as it's not
actually a sub-bucket.  We get around this by using a cursor to manually
delete items in the
bucket.

Fixes #1907.
  • Loading branch information
Roasbeef committed Sep 14, 2018
1 parent 48d016b commit 3b2c807
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions channeldb/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ func migratePruneEdgeUpdateIndex(tx *bolt.Tx) error {
}

// Retrieve some buckets that will be needed later on. These should
// already exist given the assumption that the buckets above do as well.
// already exist given the assumption that the buckets above do as
// well.
edgeIndex, err := edges.CreateBucketIfNotExists(edgeIndexBucket)
if edgeIndex == nil {
return fmt.Errorf("unable to create/fetch edge index " +
Expand Down Expand Up @@ -515,16 +516,15 @@ func migratePruneEdgeUpdateIndex(tx *bolt.Tx) error {

// With the existing edge policies gathered, we'll recreate the index
// and populate it with the correct entries.
if err := edges.DeleteBucket(edgeUpdateIndexBucket); err != nil {
return fmt.Errorf("unable to remove existing edge update "+
"index: %v", err)
}
edgeUpdateIndex, err = edges.CreateBucketIfNotExists(
edgeUpdateIndexBucket,
)
if err != nil {
return fmt.Errorf("unable to recreate edge update index: %v",
err)
//
// NOTE: In bolt DB, calling Delete() on an iterator will actually move
// it to the NEXT item. As a result, we call First() here again to go
// back to the front after the item has been deleted.
updateCursor := edgeUpdateIndex.Cursor()
for k, _ := updateCursor.First(); k != nil; k, _ = updateCursor.First() {
if err := updateCursor.Delete(); err != nil {
return err
}
}

// For each edge key, we'll retrieve the policy, deserialize it, and
Expand Down

0 comments on commit 3b2c807

Please sign in to comment.