Skip to content

Detach and drop database partitions that are past a retention period

Simon Tomlinson requested to merge stomlinson/drop-range-partitions into master

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 the detached_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

Availability and Testing

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
Edited by Simon Tomlinson

Merge request reports

Loading