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

Add instance ID column to migration table #5909

Merged
merged 10 commits into from
Jun 28, 2024
Merged

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Jun 17, 2024

Currently, the migration table does not contain a way to directly
associate migrations with instances. An instance row's migration_id
is a foreign key into the migration table pointing at the currently
active migration, if one exists, but past migrations cannot be easily
associated with migrations. This is unfortunate, as it seems useful to
be able to easily list completed/failed migrations for an instance. This
is particularly important as we would like to change the behavior around
marking migration records as deleted, so that deleting an instance also
deletes any corresponding migration records. It may also be useful for
debugging tools and UIs that expose a migration's history.

This branch adds an instance ID column to the migration table. To avoid
having NULLs in this column, I've added a migration1 that deletes
the old migration table and creates a new one, rather than backfilling
migration IDs by trying to figure them out using the vmm records for
the migration records. This seemed fine, because (1) the migration
table hasn't been released to customers yet, and (2), we don't actually
use the data in that table for anything yet, so nuking it should be
okay. I've also added a query for listing migration records by instance
ID.

Now, we no longer mark migrations as deleted when they complete or fail,
and instead mark all migrations for an instance as deleted when the
instance itself is deleted.

Migration records are still marked as deleted when an instance-migrate
saga unwinds. I'm on the fence as to whether this is the Right Thing or
not, but I think it's fine, as those migration states won't be needed by
the instance-update saga (AFAIK so far). If that doesn't end up being
the case, we might consider adding a SagaUnwound state, similar to the
one for VMMs, so that we can distinguish between migrations that failed
because a VMM failed and migrations whose sagas unwound...

Footnotes

  1. A database migration, not a live migration migration. :)

@hawkw hawkw requested review from bnaecker and gjcolombo June 17, 2024 23:47
Copy link
Collaborator

@bnaecker bnaecker left a comment

Choose a reason for hiding this comment

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

Looks good to me! I have one question about the count of migrations per instance we expect, but it's mostly curiosity.

@@ -38,6 +42,22 @@ impl DataStore {
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))
}

/// List all migrations associated with the provided instance ID.
pub async fn migration_list_by_instance(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious, is there ever more than one entry here? We're filtering to non-deleted migrations, so I naively expected to see just a single value returned here.

Copy link
Member Author

Choose a reason for hiding this comment

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

There's never more than one entry yet. Right now, migrations are marked as deleted as soon as the migration completes. However, this will probably change in the future, and migrations will be deleted only when the instance itself is deleted (and possibly once they have been completed for a 'fairly long' period of time). I didn't make that part of the change in this PR to keep the diff small, but I suppose I could...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting, thanks for the explanation! Is the idea to keep them around in the future as an auditable log of migrations? I have no opinion on whether that should be added now, but I do think a quick comment that there may be more than one in the future might be helpful. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

That's part of the motivation, yeah. Additionally, though, migration records will be used by the instance-update saga to do things like determining which Propolis processes are no longer in use because their instance has been migrated out.

@hawkw hawkw force-pushed the eliza/historical-migration branch from 82345ea to 1e6cb9c Compare June 18, 2024 16:29
@hawkw hawkw requested review from gjcolombo and bnaecker June 18, 2024 17:44
@hawkw
Copy link
Member Author

hawkw commented Jun 18, 2024

Okay, @bnaecker and @gjcolombo, if you have a moment, I'd love another review, as I've made some additional changes: now, we no longer mark migrations as deleted when they complete or fail, and instead mark all migrations for an instance as deleted when the instance itself is deleted.

Migration records are still marked as deleted when an instance-migrate saga unwinds. I'm on the fence as to whether this is the Right Thing or not, but I think it's fine, as those migration states won't be needed by the instance-update saga (AFAIK so far). If that doesn't end up being the case, we might consider adding a SagaUnwound state, similar to the one for VMMs, so that we can distinguish between migrations that failed because a VMM failed and migrations whose sagas unwound...

@hawkw hawkw enabled auto-merge (squash) June 18, 2024 19:03
@hawkw hawkw merged commit 659130e into main Jun 28, 2024
19 checks passed
@hawkw hawkw deleted the eliza/historical-migration branch June 28, 2024 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants