[GPRD] Complete ci_builds partitioning
Production Change
Change Summary
gitlab-org/gitlab!115485 (merged) was supposed to create a new partitioned table for ci_builds and attach it as its first partition, but it failed execute in production and had to be revered(gitlab-org/gitlab!120157 (merged)). Now the DB is in an inconsistent state, the migration was successfully executed in gstg and main database, but failed halfway through on ci. We need to complete it, but doing it as a regular migration is likely to fail again because we can't choose when it will be executed and it can overlap again with a wraparound vacuum process, blocking the release process for 10-12 hours.
Change Details
- Services Impacted - ServicePostgres
- Change Technician - @alexander-sosna
-
Change Reviewer -
@alexander-sosna - Time tracking - 10 minutes
- Downtime Component - No downtime
Detailed steps for the change
Change Steps - steps to take to execute the change
Estimated Time to Complete (mins) - 10 minutes
-
Set label changein-progress /label ~change::in-progress -
Connect to the CI primary database -
Configure the session to report execution timing with \timing on -
Confirm that the routing table exists and it has no partitions attached with \d+ p_ci_builds -
Check that there is no wraparound prevention vacuum process running for any of the tables involved in this operation( ci_pipelines,ci_stages,ci_builds,ci_resource_groups) with: -
select query, age(clock_timestamp(), query_start) as duration from postgres_pg_stat_activity_autovacuum() where query ilike '%wraparound%'; -
As a single command, execute the following snippet to attach ci_buildstop_ci_builds:
BEGIN;
SET LOCAL idle_in_transaction_session_timeout TO '1s';
SET LOCAL statement_timeout TO '10s';
SET LOCAL lock_timeout TO '7s';
LOCK ci_pipelines, ci_stages, ci_builds, ci_resource_groups IN ACCESS EXCLUSIVE MODE;
DROP TRIGGER IF EXISTS ci_builds_loose_fk_trigger ON ci_builds;
ALTER TABLE p_ci_builds ATTACH PARTITION ci_builds FOR VALUES IN (100);
ALTER SEQUENCE "ci_builds_id_seq" OWNED BY "p_ci_builds"."id";
ALTER TABLE p_ci_builds DROP CONSTRAINT "partitioning_constraint";
CREATE TRIGGER ci_builds_loose_fk_trigger AFTER DELETE ON ci_builds REFERENCING OLD TABLE AS old_table FOR EACH STATEMENT EXECUTE FUNCTION insert_into_loose_foreign_keys_deleted_records();
CREATE TRIGGER p_ci_builds_loose_fk_trigger AFTER DELETE ON p_ci_builds REFERENCING OLD TABLE AS old_table FOR EACH STATEMENT EXECUTE FUNCTION insert_into_loose_foreign_keys_deleted_records();
COMMIT;
-
In case of lock timeout errors, the lock_timeoutvalue must be increased to10sand the snippet retried -
Confirm that the table was attached to p_ci_buildsand the triggers created with\d+ p_ci_builds -
Set label changecomplete /label ~change::complete
Rollback
Rollback steps - steps to be taken in the event of a need to rollback this change
Estimated Time to Complete (mins) - 0 minutes
Detaching the partition on .com is not simple/possible: gitlab-org/gitlab!115485 (comment 1363958856)
-
Set label changeaborted /label ~change::aborted
Monitoring
Key metrics to observe
- Metric:
patroni-ciService Apdex- Location: https://dashboards.gitlab.net/d/patroni-ci-main/patroni-ci-overview?orgId=1
- What changes to this metric should prompt a rollback: drops below 98%
- Metric: patroni-ci Service RPS - Requests per Second
- Location: https://dashboards.gitlab.net/d/patroni-ci-main/patroni-ci-overview?orgId=1
- What changes to this metric should prompt a rollback: drops significantly for 5 minutes
Change Reviewer checklist
-
Check if the following applies: - The scheduled day and time of execution of the change is appropriate.
- The change plan is technically accurate.
- The change plan includes estimated timing values based on previous testing.
- The change plan includes a viable rollback plan.
- The specified metrics/monitoring dashboards provide sufficient visibility for the change.
-
Check if the following applies: - The complexity of the plan is appropriate for the corresponding risk of the change. (i.e. the plan contains clear details).
- The change plan includes success measures for all steps/milestones during the execution.
- The change adequately minimizes risk within the environment/service.
- The performance implications of executing the change are well-understood and documented.
- The specified metrics/monitoring dashboards provide sufficient visibility for the change.
- If not, is it possible (or necessary) to make changes to observability platforms for added visibility?
- The change has a primary and secondary SRE with knowledge of the details available during the change window.
- The labels blocks deployments and/or blocks feature-flags are applied as necessary
Change Technician checklist
-
Check if all items below are complete: - The change plan is technically accurate.
- This Change Issue is linked to the appropriate Issue and/or Epic
- Change has been tested in staging and results noted in a comment on this issue.
- A dry-run has been conducted and results noted in a comment on this issue.
- The change execution window respects the Production Change Lock periods.
- For C1 and C2 change issues, the change event is added to the GitLab Production calendar.
- For C1 and C2 change issues, the SRE on-call has been informed prior to change being rolled out. (In #production channel, mention
@sre-oncalland this issue and await their acknowledgement.) - For C1 and C2 change issues, the SRE on-call provided approval with the eoc_approved label on the issue.
- For C1 and C2 change issues, the Infrastructure Manager provided approval with the manager_approved label on the issue.
- Release managers have been informed (If needed! Cases include DB change) prior to change being rolled out. (In #production channel, mention
@release-managersand this issue and await their acknowledgment.) - There are currently no active incidents that are severity1 or severity2
- If the change involves doing maintenance on a database host, an appropriate silence targeting the host(s) should be added for the duration of the change.