Remove `database_async_index_creation` feature flag check from migration helpers
What does this MR do and why?
This removes database_async_index_creation
check from migration helpers related to async index creation, so that they can work with decomposed database.
This change means that for instances where the feature flag is not enabled (i.e. anything but GitLab.com) there will be records created in postgres_async_indexes
, those records will be cleaned up when the index is created the usual way with add_concurrent_index
.
We still keep the check in https://gitlab.com/gitlab-org/gitlab/-/blob/a3a63d3fa47109d2a6256c6c9359d8fb622961d5/lib/gitlab/database/reindexing.rb#L29.
See #354776 (closed).
How to set up and validate locally
- Make sure the feature flag is disabled:
Feature.disable(:database_async_index_creation)
Check postgres_async_indexes
table:
gitlabhq_development=# table postgres_async_indexes;
id | created_at | updated_at | name | definition | table_name
----+------------+------------+------+------------+------------
(0 rows)
- Create migration
db/migrate/20220310024425_test_prepare_async_index.rb
to prepare async index creation like
# frozen_string_literal: true
# db/migrate/20220310024425_test_prepare_async_index.rb
class TestPrepareAsyncIndex < Gitlab::Database::Migration[1.0]
INDEX_NAME = 'index_ci_builds_on_scheduling_type'
def up
prepare_async_index :ci_builds, :scheduling_type, name: INDEX_NAME
end
def down
unprepare_async_index :ci_builds, :scheduling_type, name: INDEX_NAME
end
end
-
Migrate up
bundle exec rails db:migrate:up VERSION=20220310024425
-
Check
postgres_async_indexes
table, there should be a record for this async index creation:
gitlabhq_development=# table postgres_async_indexes;
id | created_at | updated_at | name | definition | table_name
----+-------------------------------+-------------------------------+------------------------------------+---------------------------------------------------------------------------------------------------+------------
43 | 2022-03-10 02:47:23.587199+00 | 2022-03-10 02:47:23.587199+00 | index_ci_builds_on_scheduling_type | CREATE INDEX CONCURRENTLY "index_ci_builds_on_scheduling_type" ON "ci_builds" ("scheduling_type") | ci_builds
(1 row)
- Create migration
db/migrate/20220310024935_test_create_index.rb
to create the index in the usual way:
# frozen_string_literal: true
# db/migrate/20220310024935_test_create_index.rb
class TestCreateIndex < Gitlab::Database::Migration[1.0]
INDEX_NAME = 'index_ci_builds_on_scheduling_type'
disable_ddl_transaction!
def up
add_concurrent_index :ci_builds, :scheduling_type, name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :ci_builds, INDEX_NAME
end
end
- Migrate up
bundle exec rails db:migrate:up VERSION=20220310024935
Check postgres_async_indexes
, the record for async index creation should be gone, and the new index will exists
gitlabhq_development=# table postgres_async_indexes;
id | created_at | updated_at | name | definition | table_name
----+------------+------------+------+------------+------------
(0 rows)
gitlabhq_development=# \di index_ci_builds_on_scheduling_type
List of relations
Schema | Name | Type | Owner | Table
--------+------------------------------------+-------+--------+-----------
public | index_ci_builds_on_scheduling_type | index | krasio | ci_builds
(1 row)
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #354776 (closed)