Add partition_manager_sync_partitions ops flags per database

What does this MR do and why?

Partition management (sync_partitions, drop_detached_partitions and finalize_pending_detach_partitions in Gitlab::Database::Partitioning) is gated by a single ops flag, partition_manager_sync_partitions, for every database. During INC-15918 and INC-16023 that flag had to be disabled to stop repeated ATTACH PARTITION lock retries on the CI database, which also stopped partition retention on main and left detached web_hook_logs_daily partitions undropped there.

This MR adds one ops flag per database, partition_manager_sync_partitions_main, _ci and _sec, all enabled by default:

  • Callers now name the database they operate on. blocking_feature_flag(database_name) returns the global flag when it blocks, otherwise that database's flag when it is disabled.
  • drop_detached_partitions and finalize_pending_detach_partitions take a database_name and run only on that database. Database::DropDetachedPartitionsWorker and Database::FinalizePendingDetachPartitionsWorker iterate the databases and call them per database.
  • sync_partitions checks the per-database flag once per database in sync_database, and passes only_on to the top-level check so gitlab:db:create_dynamic_partitions:<db> returns and prints the flag that blocked it.
  • The global partition_manager_sync_partitions flag keeps its behaviour as the kill switch for all databases.

With this, /chatops run feature set partition_manager_sync_partitions_ci false stops CI partition creation, detach and drop while main and sec keep running.

References

Screenshots or screen recordings

No UI change.

How to set up and validate locally

Requires a GDK with separate main and ci databases.

  1. In a Rails console, disable the CI flag and run a sync:

    Feature.disable(:partition_manager_sync_partitions_ci)
    Gitlab::Database::Partitioning.sync_partitions

    log/application.log shows Skipping sync of dynamic postgres partitions with "feature_flag":"partition_manager_sync_partitions_ci" and "database_name":"ci", while the main sync runs.

  2. Run the per-database task for each database:

    bin/rake gitlab:db:create_dynamic_partitions:ci
    bin/rake gitlab:db:create_dynamic_partitions:main

    The first prints Note: partition_manager_sync_partitions_ci feature is currently disabled; the second prints nothing.

  3. Check the per-database retention methods:

    Gitlab::Database::Partitioning.drop_detached_partitions('ci')   # => :partition_manager_sync_partitions_ci
    Gitlab::Database::Partitioning.drop_detached_partitions('main') # runs the dropper on main
  4. Re-enable the flag with Feature.enable(:partition_manager_sync_partitions_ci) and repeat step 1; both databases sync.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Prabakaran Murugesan

Merge request reports

Loading
Loading