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

adapter: Remove legacy builtin item migrations #31218

Merged

Conversation

jkosh44
Copy link
Contributor

@jkosh44 jkosh44 commented Jan 28, 2025

Previously, the adapter maintained two different implementations of the
builtin item migration framework. One that was used before 0dt and one
that was used with 0dt. The 0dt implementation still works when 0dt is
turned off, but we wanted to keep the legacy implementation around
while the 0dt implementation was still new. The 0dt implementation has
been around long enough in production to prove that it works. On the
other hand, the legacy implementation has not been tested in production
in a long time.

This commit removes the legacy implementation and always uses the new
implementation. This should reduce the maintenance burden of builtin
item migrations.

In the future, the builtin item migration framework should be
completely removed and replaced with ALTER TABLE.

Motivation

This PR refactors existing code.

Checklist

  • This PR has adequate test coverage / QA involvement has been duly considered. (trigger-ci for additional test/nightly runs)
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).
  • If this PR includes major user-facing behavior changes, I have pinged the relevant PM to schedule a changelog post.

@jkosh44 jkosh44 force-pushed the remove-legacy-builtin-migration branch from f0b8b24 to 8592941 Compare January 28, 2025 17:15
@jkosh44
Copy link
Contributor Author

jkosh44 commented Jan 28, 2025

This feels like a somewhat risky PR for my last week, but it also seems unlikely to get done after and potentially very helpful. It also has the added benefit that the upgrade checks are actually using the same logic that is used in prod.

@jkosh44 jkosh44 force-pushed the remove-legacy-builtin-migration branch from 8592941 to 480ae88 Compare January 28, 2025 17:32
@jkosh44 jkosh44 changed the title Remove legacy builtin migration adapter: Remove legacy builtin item migrations Jan 28, 2025
@jkosh44 jkosh44 force-pushed the remove-legacy-builtin-migration branch 3 times, most recently from f4b1444 to 4afd695 Compare January 28, 2025 19:42
Previously, the adapter maintained two different implementations of the
builtin item migration framework. One that was used before 0dt and one
that was used with 0dt. The 0dt implementation still works when 0dt is
turned off, but we wanted to keep the legacy implementation around
while the 0dt implementation was still new. The 0dt implementation has
been around long enough in production to prove that it works. On the
other hand, the legacy implementation has not been tested in production
in a long time.

This commit removes the legacy implementation and always uses the new
implementation. This should reduce the maintenance burden of builtin
item migrations.

In the future, the builtin item migration framework should be
completely removed and replaced with `ALTER TABLE`.
@jkosh44 jkosh44 force-pushed the remove-legacy-builtin-migration branch from 4afd695 to 9465baa Compare January 28, 2025 21:05
@jkosh44 jkosh44 requested review from aljoscha and ParkMyCar January 28, 2025 21:59
@jkosh44 jkosh44 marked this pull request as ready for review January 28, 2025 22:00
@jkosh44 jkosh44 requested review from a team as code owners January 28, 2025 22:00
Copy link
Contributor

@aljoscha aljoscha left a comment

Choose a reason for hiding this comment

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

Neat! I hadn't thought about this anymore but it's an excellent parting gift!

Had some inline questions, but I think the best testing we have is that we've used the other migration code path for so long now...

///
/// Note: These Collections will not be in the Catalog, and are only known about by
/// the storage controller, which is why we identify them by [`GlobalId`].
pub storage_collections_to_drop: BTreeSet<GlobalId>,
Copy link
Contributor

Choose a reason for hiding this comment

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

These are from the times when we had a separate "Stash" (is that the word we had for the things backing the Catalog before we used a persist shard) for storage, so the two could get out of sync and we would have to clean that up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually unrelated to the stash. The legacy migration framework worked by dropping all of the migrated items (and dependent items) and creating brand new items with new definitions. The new items would all have new GlobalIds and be treated as brand new items.

The new migration framework doesn't drop any items, but it swaps out the shards of existing items. So we do finalize shards, but we don't drop any items.

@@ -679,7 +558,7 @@ impl Catalog {
let mut txn = storage.transaction().await?;

storage_collections
.initialize_state(&mut txn, collections, storage_collections_to_drop)
.initialize_state(&mut txn, collections)
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting! We really never drop storage collections as part of migrations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting! We really never drop storage collections as part of migrations?

Yep no storage collections are dropped, but we do finalize shards and create new ones.

builtin_item_migration_config: BuiltinItemMigrationConfig {
// We don't actually want to write anything down, so use an in-memory persist
// client.
persist_client: PersistClient::new_for_tests().await,
Copy link
Contributor Author

@jkosh44 jkosh44 Jan 29, 2025

Choose a reason for hiding this comment

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

This is the scariest part of the PR IMO since it's hard (impossible?) to test the upgrade checks in the cloud repo.

Copy link
Member

@ParkMyCar ParkMyCar left a comment

Choose a reason for hiding this comment

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

LGTM!

@jkosh44 jkosh44 merged commit 8e5ad9d into MaterializeInc:main Jan 29, 2025
241 of 244 checks passed
@jkosh44 jkosh44 deleted the remove-legacy-builtin-migration branch January 29, 2025 15:17
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