Add sharding key to merge_request_diff_commits source table (Step 1.9)

What

Prior to enqueuing the backfill of the partitioned merge_request_diff_commits table, we will need to add the sharding key column and update both the table sync trigger and the application to start writing the sharding key.

Why

If we don't, then we will never have a safe point to switch over from unpartitioned table to partitioned table.

Details

We are here: MR1

  • N (MR1): Add the project_id column
  • N (MR1): Post deploy: Change the trigger to include project_id
  • N (MR1): Change rails to include project_id
  • N (MR3): Post deploy: Queue backfill (Draft: Backfill partitioned merge_request_diff_... (!168897 - closed))
  • N+? (MR4): Switch reads with feature flag (this can happen any time after backfill finishes on .com, SM won't ever use this)
  • N+RS (MR5): Finalize backfill, has to be after at least one required stop, maybe two
  • N+RS (MR6): Remove feature flag, which changes code path back to original table name
  • N+RS (MR6): Post deploy (tag release managers): Drop trigger, rename merge_request_diff_commits to merge_request_diff_commits_orig, rename merge_request_diff_commits_b5377a7a34 to merge_request_diff_commits in same transaction, making sure down migration works so release managers can undo if necessary

Diagram

flowchart TB
    app_old("Application Using Old Table<br>(Without Sharding Key)")
    app_old --> old_table_sync("Old Table<br>(Syncing Without Sharding Key)")
    old_table_sync -- Add Sharding Key --> old_table_sharding("Old Table<br>With Sharding Key")
    old_table_sharding -- Replace Table Sync Trigger --> old_table_sharding_syncing("Old Table<br>(Sync Includes Sharding Key)")
    old_table_sharding -- No Sharding Key --> new_table
    old_table_sharding_syncing -- Change Application to Write Sharding Key --> app_old_sharding("Application Using Old Table<br>(With Sharding Key)")
    app_old_sharding -- Queue Backfill --> backfill("Backfill Old to New")
    backfill -- Switchover --> app_new("Application Using New Table")
    old_table_sharding_syncing -- With Sharding Key --> new_table
    old_table_sync -- No Sharding Key --> new_table("New Table<br>(With Sharding Key)")
    app_new --> new_table

/cc @kerrizor @stomlinson

Edited by 🤖 GitLab Bot 🤖