Backport of 'Drop detached ai_events_counts partitions before the table'
What does this MR do and why?
Backports !272133 (merged) to 19.6.
Related to #642088 (S1, customers blocked on the upgrade to 19.6).
DropAiEventsCounts shipped in 19.6.0. It fails with PG::DependentObjectsStillExist on an instance that still has ai_events_counts partitions that the partition manager detached but DropDetachedPartitionsWorker has not dropped yet, because those tables still use ai_events_counts_id_seq. Detached partitions are kept for a week, so an instance that upgrades through the 19.5 stop to 19.6 within a week of a detach, or where the worker did not run, hits this. The fix drops those detached tables first, after their foreign keys, and removes their detached_partitions rows.
Reported in !268857 (comment 4263464533). The backport was requested in the database review of !272133 (merged).
- Cherry-pick of 941a2d70 (the squash commit of !272133 (merged)), with
-x. - The migrations, the spec and
db/docs/deleted_tables/ai_events_counts.ymlare identical to the default branch. - The only conflict was
.rubocop_todo/rspec/spec_file_path_format.yml: the stable branch's list differs from the default branch, so this MR keeps the stable branch's file and adds only the new spec path.
Data deletion
- Records affected: only
ai_events_counts_*partitions that the partition manager already detached andDropDetachedPartitionsWorkerhasn't dropped yet, plus theirdetached_partitionsrows. The worker would delete them within a week anyway. On GitLab.com, none: the migration already ran and nothing was left. The rest of the table is dropped by !268857 (merged), see its data deletion section. - User impact: none. Nothing reads
ai_events_countssince 19.5. - Recovery: not needed, this data was already scheduled for deletion. Rolling back recreates the empty table, as before.
Same as !272133 (merged).
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
- This MR is backporting a bug fix, documentation update, or spec fix, previously merged in the default branch.
- The MR that fixed the bug on the default branch has been deployed to GitLab.com (not applicable for documentation or spec changes).
- The MR title is descriptive (e.g. "Backport of 'title of default branch MR'"). This is important, since the title will be copied to the patch blog post.
- Required labels have been applied to this merge request
- severity label and bug subtype labels (if applicable)
- If this MR fixes a bug that affects customers, the customer label has been applied.
- This MR has been approved by a maintainer (only one approval is required).
- Ensure the
E2E Omnibus GitLab EEpipeline (triggered by thee2e:test-on-omnibus-eejob) has succeeded. If it has failed (or shows warnings), investigate the failures. If you determine the failures are unrelated, you may proceed. If you need assistance investigating, request help in the #s_developer_experience Slack channel to confirm the failures are unrelated to the merge request.
Note to the merge request author and maintainer
If you have questions about the patch release process, please:
- Refer to the patch release runbook for engineers and maintainers for guidance.
- Ask questions on the
#releasesSlack channel (internal only). - Once the backport has been merged, the commit changes will be automatically deployed to a release environment that can be used for manual validation. See after merging runbook for details.