Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

channeldb: remove older migrations #3485

Merged
merged 2 commits into from
Sep 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 24 additions & 71 deletions channeldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,72 +37,6 @@ var (
// for retrieving all migration function that are need to apply to the
// current db.
dbVersions = []version{
{
joostjager marked this conversation as resolved.
Show resolved Hide resolved
// The base DB version requires no migration.
number: 0,
migration: nil,
},
{
// The version of the database where two new indexes
// for the update time of node and channel updates were
// added.
number: 1,
migration: migrateNodeAndEdgeUpdateIndex,
},
{
// The DB version that added the invoice event time
// series.
number: 2,
migration: migrateInvoiceTimeSeries,
},
{
// The DB version that updated the embedded invoice in
// outgoing payments to match the new format.
number: 3,
migration: migrateInvoiceTimeSeriesOutgoingPayments,
},
{
// The version of the database where every channel
// always has two entries in the edges bucket. If
// a policy is unknown, this will be represented
// by a special byte sequence.
number: 4,
migration: migrateEdgePolicies,
},
{
// The DB version where we persist each attempt to send
// an HTLC to a payment hash, and track whether the
// payment is in-flight, succeeded, or failed.
number: 5,
migration: paymentStatusesMigration,
},
{
// The DB version that properly prunes stale entries
// from the edge update index.
number: 6,
migration: migratePruneEdgeUpdateIndex,
},
{
// The DB version that migrates the ChannelCloseSummary
// to a format where optional fields are indicated with
// boolean flags.
number: 7,
migration: migrateOptionalChannelCloseSummaryFields,
},
{
// The DB version that changes the gossiper's message
// store keys to account for the message's type and
// ShortChannelID.
number: 8,
migration: migrateGossipMessageStoreKeys,
},
{
// The DB version where the payments and payment
// statuses are moved to being stored in a combined
// bucket.
number: 9,
migration: migrateOutgoingPayments,
},
{
// The DB version where we started to store legacy
// payload information for all routes, as well as the
Expand Down Expand Up @@ -266,10 +200,6 @@ func createChannelDB(dbPath string) error {
return err
}

if _, err := tx.CreateBucket(paymentBucket); err != nil {
return err
}

if _, err := tx.CreateBucket(nodeInfoBucket); err != nil {
return err
}
Expand Down Expand Up @@ -1111,8 +1041,10 @@ func (d *DB) syncVersions(versions []version) error {
}

latestVersion := getLatestDBVersion(versions)
minUpgradeVersion := getMinUpgradeVersion(versions)
log.Infof("Checking for schema update: latest_version=%v, "+
"db_version=%v", latestVersion, meta.DbVersionNumber)
"min_upgrade_version=%v, db_version=%v", latestVersion,
minUpgradeVersion, meta.DbVersionNumber)

switch {

Expand All @@ -1125,6 +1057,12 @@ func (d *DB) syncVersions(versions []version) error {
latestVersion)
return ErrDBReversion

case meta.DbVersionNumber < minUpgradeVersion:
log.Errorf("Refusing to upgrade from db_version=%d to "+
"latest_version=%d. Upgrade via intermediate major "+
"release(s).", meta.DbVersionNumber, latestVersion)
return ErrDBVersionTooLow

// If the current database version matches the latest version number,
// then we don't need to perform any migrations.
case meta.DbVersionNumber == latestVersion:
Expand Down Expand Up @@ -1168,6 +1106,21 @@ func getLatestDBVersion(versions []version) uint32 {
return versions[len(versions)-1].number
}

// getMinUpgradeVersion returns the minimum version required to upgrade the
// database.
func getMinUpgradeVersion(versions []version) uint32 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a blocker, but now that we're removing migrations, this logic should probably be able to handle the case where there are no migrations in a given release. would need a similar change to getLatestDBVersion as well

firstMigrationVersion := versions[0].number

// If we can upgrade from the base version with this version of lnd,
// return the base version as the minimum required version.
if firstMigrationVersion == 0 {
return 0
}

// Otherwise require the version that the first migration upgrades from.
return firstMigrationVersion - 1
}

// getMigrationsToApply retrieves the migration function that should be
// applied to the database.
func getMigrationsToApply(versions []version, version uint32) ([]migration, []uint32) {
Expand Down
4 changes: 4 additions & 0 deletions channeldb/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ var (
// prior database version.
ErrDBReversion = fmt.Errorf("channel db cannot revert to prior version")

// ErrDBVersionTooLow is returned when detecting an attempt to upgrade a
// version for which migration is no longer supported.
ErrDBVersionTooLow = fmt.Errorf("channel db version too old to upgrade")

// ErrLinkNodesNotFound is returned when node info bucket hasn't been
// created.
ErrLinkNodesNotFound = fmt.Errorf("no link nodes exist")
Expand Down
55 changes: 0 additions & 55 deletions channeldb/legacy_serialization.go

This file was deleted.

Loading