Class: Gitlab::Database::Reindexing::ReindexConcurrently
- Inherits:
-
Object
- Object
- Gitlab::Database::Reindexing::ReindexConcurrently
- Defined in:
- lib/gitlab/database/reindexing/reindex_concurrently.rb
Overview
This is a >= PG12 reindexing strategy based on ‘REINDEX CONCURRENTLY`
Constant Summary collapse
- ReindexError =
Class.new(StandardError)
- TEMPORARY_INDEX_PATTERN =
'\_ccnew[0-9]*'
- STATEMENT_TIMEOUT =
24.hours
- PG_MAX_INDEX_NAME_LENGTH =
63
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(index, logger: Gitlab::AppLogger) ⇒ ReindexConcurrently
constructor
A new instance of ReindexConcurrently.
- #perform ⇒ Object
Constructor Details
#initialize(index, logger: Gitlab::AppLogger) ⇒ ReindexConcurrently
Returns a new instance of ReindexConcurrently.
16 17 18 19 |
# File 'lib/gitlab/database/reindexing/reindex_concurrently.rb', line 16 def initialize(index, logger: Gitlab::AppLogger) @index = index @logger = logger end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
14 15 16 |
# File 'lib/gitlab/database/reindexing/reindex_concurrently.rb', line 14 def index @index end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
14 15 16 |
# File 'lib/gitlab/database/reindexing/reindex_concurrently.rb', line 14 def logger @logger end |
Instance Method Details
#perform ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gitlab/database/reindexing/reindex_concurrently.rb', line 21 def perform raise ReindexError, 'indexes serving an exclusion constraint are currently not supported' if index.exclusion? raise ReindexError, 'index is a left-over temporary index from a previous reindexing run' if /#{TEMPORARY_INDEX_PATTERN}/o.match?(index.name) # Expression indexes require additional statistics in `pg_statistic`: # select * from pg_statistic where starelid = (select oid from pg_class where relname = 'some_index'); # # In PG12, this has been fixed in https://gitlab.com/postgres/postgres/-/commit/b17ff07aa3eb142d2cde2ea00e4a4e8f63686f96. # Discussion happened in https://www.postgresql.org/message-id/flat/CAFcNs%2BqpFPmiHd1oTXvcPdvAHicJDA9qBUSujgAhUMJyUMb%2BSA%40mail.gmail.com # following a GitLab.com incident that surfaced this (https://gitlab.com/gitlab-com/gl-infra/production/-/issues/2885). # # While this has been backpatched, we continue to disable expression indexes until further review. raise ReindexError, 'expression indexes are currently not supported' if index.expression? begin with_logging do set_statement_timeout do execute("REINDEX INDEX CONCURRENTLY #{quote_table_name(index.schema)}.#{quote_table_name(index.name)}") end end ensure cleanup_dangling_indexes end end |