Skip to content

Delete project deployments in batches

Hunter Stewart requested to merge hustewart-query-cancel into master

Why

See ActiveRecord::QueryCanceled: PG::QueryCanceled:... (#409828 - closed). In brief, we're getting

PG::QueryCanceled: ERROR:  canceling statement due to statement timeout
CONTEXT:  SQL statement "DELETE FROM ONLY "public"."deployments" WHERE $1 OPERATOR(pg_catalog.=) "project_id"

Which already has a path to a solution.

What

Update the destroy service to delete the deployments in batches

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

I've been creating the objects and running commands in rails console locally:

In rails console

  1. Create a test projecet

test_project = FactoryBot.create(:project, :repository, namespace: User.first.namespace)

  1. Create how ever many deployments you want to test. I tried 1000 once and it took like 10 minutes, 100 wasn't so bad.

FactoryBot.create_list(:deployment, 100, project: test_project)

  1. Run the destroy service and see the resulting SQL. This is the part we care about.

Projects::DestroyService.new(test_project, User.first, {}).public_send(:execute)

You can do this on master and then compare the SQL against the branch hustewart-query-cancel

A few times I ran into some data clean up issues and needed to run:

Route.where("DATE(created_at) = ?", Date.today).destroy_all

in order to create more test data.

There might be a cleaner way to do this, but this seemed to work OK for me.

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Hunter Stewart

Merge request reports

Loading