Merge pull request #1886 from Roasbeef/lax-migration-assumptions

channeldb: relax bucket assumptions for latest db migration
This commit is contained in:
Olaoluwa Osuntokun 2018-09-11 19:18:03 -07:00 committed by GitHub
commit ea5a18f4e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"crypto/sha256" "crypto/sha256"
"encoding/binary" "encoding/binary"
"errors"
"fmt" "fmt"
"github.com/coreos/bbolt" "github.com/coreos/bbolt"
@ -474,20 +473,24 @@ func migratePruneEdgeUpdateIndex(tx *bolt.Tx) error {
if edges == nil { if edges == nil {
return nil return nil
} }
edgeUpdateIndex := edges.Bucket(edgeUpdateIndexBucket) edgeUpdateIndex, err := edges.CreateBucketIfNotExists(
if edgeUpdateIndex == nil { edgeUpdateIndexBucket,
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
// 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 := edges.Bucket(edgeIndexBucket) edgeIndex, err := edges.CreateBucketIfNotExists(edgeIndexBucket)
if edgeIndex == nil { if edgeIndex == nil {
return errors.New("edge index should exist but does not") return fmt.Errorf("unable to create/fetch edge index " +
"bucket")
} }
nodes := tx.Bucket(nodeBucket) nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
if nodes == nil { if err != nil {
return errors.New("node bucket should exist but does not") return fmt.Errorf("unable to make node bucket")
} }
log.Info("Migrating database to properly prune edge update index") log.Info("Migrating database to properly prune edge update index")
@ -496,7 +499,7 @@ func migratePruneEdgeUpdateIndex(tx *bolt.Tx) error {
// update index. To do so, we'll gather all of the existing policies // update index. To do so, we'll gather all of the existing policies
// within the graph to re-populate them later on. // within the graph to re-populate them later on.
var edgeKeys [][]byte var edgeKeys [][]byte
err := edges.ForEach(func(edgeKey, edgePolicyBytes []byte) error { err = edges.ForEach(func(edgeKey, edgePolicyBytes []byte) error {
// All valid entries are indexed by a public key (33 bytes) // All valid entries are indexed by a public key (33 bytes)
// followed by a channel ID (8 bytes), so we'll skip any entries // followed by a channel ID (8 bytes), so we'll skip any entries
// with keys that do not match this. // with keys that do not match this.