Skip to content

Commit

Permalink
testplanet: support snapshot based migration for storagenode
Browse files Browse the repository at this point in the history
Similar to the existing snapshot based tests of satellite/metabase db we make a migration here which is:
 * dedicated to unit tests
 * faster (with less steps)
 * but safe: additional unit test ensures that the snapshot based migration and normal prod migration have the same results.

Change-Id: Ie324b09f64b4553df02247a9461ece305a6cf832
  • Loading branch information
elek authored and Storj Robot committed Aug 22, 2022
1 parent 8ddd555 commit 6b27c64
Show file tree
Hide file tree
Showing 5 changed files with 520 additions and 1 deletion.
2 changes: 1 addition & 1 deletion private/testplanet/storagenode.go
Expand Up @@ -257,7 +257,7 @@ func (planet *Planet) newStorageNode(ctx context.Context, prefix string, index,
// Mark the peer's PieceDeleter as in testing mode, so it is easy to wait on the deleter
peer.Storage2.PieceDeleter.SetupTest()

err = db.MigrateToLatest(ctx)
err = db.TestMigrateToLatest(ctx)
if err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions storagenode/peer.go
Expand Up @@ -76,6 +76,10 @@ var (
type DB interface {
// MigrateToLatest initializes the database
MigrateToLatest(ctx context.Context) error

// TestMigrateToLatest is a fast migration with skipping test (not safe for production + old db state)
TestMigrateToLatest(ctx context.Context) error

// Close closes the database
Close() error

Expand Down
7 changes: 7 additions & 0 deletions storagenode/storagenodedb/database.go
Expand Up @@ -347,6 +347,13 @@ func (db *DB) MigrateToLatest(ctx context.Context) error {
return migration.Run(ctx, db.log.Named("migration"))
}

// TestMigrateToLatest creates any necessary tables from snapshot.
// it's faster for the testing but should be the same as MigrateToLatest.
func (db *DB) TestMigrateToLatest(ctx context.Context) error {
migration := db.Snapshot(ctx)
return migration.Run(ctx, db.log.Named("migration"))
}

// Preflight conducts a pre-flight check to ensure correct schemas and minimal read+write functionality of the database tables.
func (db *DB) Preflight(ctx context.Context) (err error) {
for dbName, dbContainer := range db.SQLDBs {
Expand Down

1 comment on commit 6b27c64

@storjrobot
Copy link

Choose a reason for hiding this comment

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

This commit has been mentioned on Storj Community Forum (official). There might be relevant details there:

https://forum.storj.io/t/release-preparation-v1-63/19558/1

Please sign in to comment.