gitlab:db:lock_writes should lock writes on tables partitions as well
Lock-writes
We have the rake task gitlab:db:lock_writes
to lock writes on all the legacy tables (gitlab_main
tables on ci
database, and gitlab_ci
on main
databaes).
This rake task was meant to lock the writes on the partitioned tables, but not their partitions.
The problem
As part of the post-staging/production legacy tables truncation analysis: #376305 (closed)
We discovered that some tables had some tables had some partitions locked-for writes and some partitions are not locked for writes. For example security_findings
on the ci
database had the partition security_findings_1
locked for writes, while the partition security_findings_2
was not locked for writes. This is simple due to the fact that some partitioned happened to be tables before when we locked writes on the tables. And these locks persisted on the tables when they were converted into partitions
To understand why this was happening in details, the issue had all the details about this with all the relevent MRs.
The goal
The goal of this issue to modify the rake task gitlab:db:lock_writes
to lock the writes on the tables partitions as well.
Special Case Scenario to pay attention to
The rake task gitlab:db:lock_writes
skips any tables that are already locked for writes. But this should be modified to look into the partitions as well. In another words, it should not assume that table partitions are locked for writes as well
Relevant topics/links
- This relevant MR recently has been implemented to handle truncating tables and and their locked partitions as well, which is the issue that we faced on
staging
andproduction
. - The source code of the
gitlab:db:lock_writes
rake task: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/tasks/gitlab/db/lock_writes.rake
CC: @tkuah @rutgerwessels