[Feature flag] Rollout of `partition_pruning`
Summary
This issue is to rollout partition pruning on production,
that is currently behind the partition_pruning
feature flag.
This flag will make the PartitionManagement
worker detach old partitions, but will not drop those detached tables. As such, if something goes wrong, we can ALTER TABLE ... ATTACH PARTITION
and flip this feature flag.
Previously we enabled the partition_pruning_dry_run
feature flag (#335315 (closed)), which simply logged which partitions would be detached.
Owners
- Team: Database
- Most appropriate slack channel to reach out to:
#g_database
- Best individual to reach out to: @stomlinson
- PM: @fzimmer
Stakeholders
The Rollout Plan
- Enable the
partition_pruning
feature flag on Gitlab.com - Verify that the correct partitions have been detached
- Enable the
drop_detached_partitions
feature flag to drop these detached tables. (will link when I write the issue) - Remove this feature flag
Testing Groups/Projects/Users
This flag is not specific to a group/project/user, so it will be toggled globally only.
Expectations
What are we expecting to happen?
Once the feature flag is toggled, the PartitionManagementWorker
, which runs periodically and when the application starts, will detach partitions of the web_hook_logs
table that are more than 3 months old. It will insert a row in the detached_partitions
table for each of these detached tables with a drop_after
value of one week in the future.
What might happen if this goes wrong?
If the wrong partitions are selected to be detached, we could see errors and other issues because data will be removed from the web_hook_logs table that shouldn't be. If this happens, we should:
- Turn off the feature flag before doing anything else. If it's still on, any re-attaching of partitions will be undone the next time the scheduled job runs.
- Identify the partitions that were incorrectly detached.
- For each of them, re-attach the partition, using a check constraint so we do not take a lock on the parent table
- run
alter table <partition_name> add constraint temp_partition_constraint CHECK (created_at >= <min> AND created_at < <max>) NOT VALID
- Validate the constraint:
alter table <partition_name> validate constraint temp_partition_constraint
- Attach the partition:
alter table <table> attach partition <partition_name> for values from (<min>) to (<max>)
- Drop the constraint:
alter table <partition_name> DROP CONSTRAINT temp_partition_constraint
- run
- Remove the rows for these flags from the
detached_partitions
table so that the deletion worker won't try to drop the tables.- This deletion is behind the seperate feature flag
drop_detached_partitions
and also checks that the partition is not attached to a table and does not drop if it is, so this is not urgent, but it will generate errors and could cause data loss if there is a second bug in the drop_detached_partitions code that makes it skip the check.
- This deletion is behind the seperate feature flag
What can we monitor to detect problems with this?
Kibana search for partition detach events: here
We should only see detach events for the web_hook_logs table, and only for partitions that are over 3 months old.
Rollout Steps
Rollout on non-production environments
-
Ensure that the feature MRs have been deployed to non-production environments. -
/chatops run auto_deploy status <merge-commit-of-your-feature>
-
-
Enable the feature globally on non-production environments. -
/chatops run feature set partition_pruning true --dev
-
/chatops run feature set partition_pruning true --staging
-
-
Verify that the feature works as expected. Posting the QA result in this issue is preferable.
Preparation before production rollout
-
Ensure that the feature MRs have been deployed to both production and canary. -
/chatops run auto_deploy status <merge-commit-of-your-feature>
-
-
This feature will need a change management issue as it is C2 severity. I will cross-link here when this happens. -
Ensure that you or a representative in development can be available for at least 2 hours after feature flag updates in production. If a different developer will be covering, or an exception is needed, please inform the oncall SRE by using the @sre-oncall
Slack alias. -
Ensure that documentation has been updated (More info). -
Announce on the feature issue an estimated time this will be enabled on GitLab.com. -
If the feature might impact the user experience, notify #support_gitlab-com
and your team channel (more guidance when this is necessary in the dev docs). -
If the feature flag in code has an actor, enable it on GitLab.com for testing groups/projects. -
/chatops run feature set --<actor-type>=<actor> partition_pruning true
-
-
Verify that the feature works as expected. Posting the QA result in this issue is preferable.
Global rollout on production
-
Incrementally roll out the feature. -
/chatops run feature set partition_pruning true
-
-
Announce on the feature issue that the feature has been globally enabled. -
Wait for at least one day for the verification term.
(Optional) Release the feature with the feature flag
If you're still unsure whether the feature is deemed stable but want to release it in the current milestone, you can change the default state of the feature flag to be enabled. To do so, follow these steps:
-
Create a merge request with the following changes. Ask for review and merge it. -
Set the default_enabled
attribute in the feature flag definition totrue
. -
Create a changelog entry.
-
-
Ensure that the default-enabling MR has been deployed to both production and canary. If the merge request was deployed before the code cutoff, the feature can be officially announced in a release blog post. -
/chatops run auto_deploy status <merge-commit-of-default-enabling-mr>
-
-
Close the feature issue to indicate the feature will be released in the current milestone. -
Set the next milestone to this rollout issue for scheduling the flag removal. -
(Optional) You can create a separate issue for scheduling the steps below to Release the feature. -
Set the title to "[Feature flag] Cleanup partition_pruning
". -
Execute the /copy_metadata <this-rollout-issue-link>
quick action to copy the labels from this rollout issue. -
Link this rollout issue as a related issue. -
Close this rollout issue.
-
WARNING: This approach has the downside that it makes it difficult for us to clean up the flag. For example, on-premise users could disable the feature on their GitLab instance. But when you remove the flag at some point, they suddenly see the feature as enabled and they can't roll it back to the previous behavior. To avoid this potential breaking change, use this approach only for urgent matters.
Release the feature
After the feature has been deemed stable, the clean up should be done as soon as possible to permanently enable the feature and reduce complexity in the codebase.
-
Create a merge request to remove partition_pruning
feature flag. Ask for review and merge it.-
Remove all references to the feature flag from the codebase. -
Remove the YAML definitions for the feature from the repository. -
Create a changelog entry.
-
-
Ensure that the cleanup MR has been deployed to both production and canary. If the merge request was deployed before the code cutoff, the feature can be officially announced in a release blog post. -
/chatops run auto_deploy status <merge-commit-of-cleanup-mr>
-
-
Close the feature issue to indicate the feature will be released in the current milestone. -
Clean up the feature flag from all environments by running these chatops command in #production
channel:-
/chatops run feature delete partition_pruning --dev
-
/chatops run feature delete partition_pruning --staging
-
/chatops run feature delete partition_pruning
-
-
Close this rollout issue.
Rollback Steps
-
This feature can be disabled by running the following Chatops command:
/chatops run feature set partition_pruning false