Detach and drop database partitions that are past a retention period
What does this MR do?
This is a follow-up to !65093 (merged), which identified the set of partitions that should be detached and then dropped.
In this MR, the role of the partition manager is extended to detach partitions that are past their retain_for
specification, and insert a row in the new detached_partitions
table indicating that the newly detached partition should be dropped a week later.
Separately, a new DropDetachedPartitionsWorker
runs periodically, dropping the tables that have been detached for at least a week and removing their entries from the detached_partitions
table.
As this involves deleting data, both of these operations (detaching and dropping) are behind two separate feature flags:
-
partition_pruning
(rollout issue: #337153 (closed)) controls detaching partitions and inserting the rows in thedetached_partitions
table -
drop_detached_partitions
(rollout issue: #337155 (closed)) controls the worker that pulls rows from the detached_partitions table and actually drops the associated tables.
My plan is to roll out the partition_pruning
flag first, check that the set of rows in the detached_partitions
table is what I expect, then enable the drop_detached_partitions
flag.
Relates to #332199 (closed)
Database Information
Migration: CreateDetachedPartitionsTable
Up
== 20210628154900 CreateDetachedPartitionsTable: migrating ==================== -- create_table(:detached_partitions, {}) -- quote_column_name(:table_name) -> 0.0000s -> 0.0078s -- quote_table_name("check_aecee24ba3") -> 0.0000s -- quote_table_name(:detached_partitions) -> 0.0000s -- execute("ALTER TABLE \"detached_partitions\"\nADD CONSTRAINT \"check_aecee24ba3\" CHECK (char_length(\"table_name\") <= 63)\n") -> 0.0008s == 20210628154900 CreateDetachedPartitionsTable: migrated (0.0121s) ===========
Down
== 20210628154900 CreateDetachedPartitionsTable: reverting ==================== -- drop_table(:detached_partitions, {}) -> 0.0019s == 20210628154900 CreateDetachedPartitionsTable: reverted (0.0105s) ===========
Queries:
select * from detached_partitions where drop_after < ?
- Database Lab
- I did not add an index for this query as the table will only have a few dozen rows in it at most, so postgres will likely use a table scan anyway.
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team