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

AO3-6893 Use rebuild_constraints to modify foreign keys #5066

Merged
merged 1 commit into from
Feb 15, 2025

Conversation

redsummernight
Copy link
Member

@redsummernight redsummernight commented Feb 15, 2025

Issue

https://otwarchive.atlassian.net/browse/AO3-6893

Purpose

@zz9pzza referenced this blog post. Our options:

  • rebuild_constraints is safest but slow since it involves copying data from the old to the new table.
  • drop_swap is fast but risky and not rollback friendly.
  • auto is not a real third option, it picks between the first two by estimating how long it takes to copy data between the two tables.

Since we're using MariaDB, rebuilding constraints as an online operation can be fast (not requiring a full table copy) as long as we disable foreign_key_checks:

InnoDB supports adding foreign key constraints to a table with ALGORITHM set to INPLACE. In order to add a new foreign key constraint to a table with ALGORITHM set to INPLACE, the foreign_key_checks system variable needs to be set to OFF. If it is set to ON, then ALGORITHM=COPY is required.

This operation only changes the table's metadata, so the table does not have to be rebuilt.

We would need to set:

--alter-foreign-keys-method=rebuild_constraints
--set-vars=foreign_key_checks=0

However, the version of pt-osc we use (3.5.4) has percona/percona-toolkit#483, which set foreign_key_checks=0 only briefly when running alter table. That means we can simply set:

--alter-foreign-keys-method=rebuild_constraints

Testing Instructions

Retry the migrations in #5039.

@redsummernight redsummernight added Priority: High - Broken on Test Merge immediately after approval Awaiting Review Has Production Config Changes Modifies the config file and needs special attention when deploying labels Feb 15, 2025
@zz9pzza zz9pzza merged commit 0e6ac7f into otwcode:master Feb 15, 2025
29 checks passed
@redsummernight redsummernight deleted the AO3-6893-alter-fk branch February 15, 2025 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Has Production Config Changes Modifies the config file and needs special attention when deploying Priority: High - Broken on Test Merge immediately after approval Reviewed: Ready to Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants