Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/database/async_indexes/index_creator.rb')
-rw-r--r--lib/gitlab/database/async_indexes/index_creator.rb48
1 files changed, 10 insertions, 38 deletions
diff --git a/lib/gitlab/database/async_indexes/index_creator.rb b/lib/gitlab/database/async_indexes/index_creator.rb
index 3ae2bb7b3e5..c5f4c5f30ad 100644
--- a/lib/gitlab/database/async_indexes/index_creator.rb
+++ b/lib/gitlab/database/async_indexes/index_creator.rb
@@ -3,48 +3,24 @@
module Gitlab
module Database
module AsyncIndexes
- class IndexCreator
- include IndexingExclusiveLeaseGuard
-
- TIMEOUT_PER_ACTION = 1.day
+ class IndexCreator < AsyncIndexes::IndexBase
STATEMENT_TIMEOUT = 20.hours
- def initialize(async_index)
- @async_index = async_index
- end
-
- def perform
- try_obtain_lease do
- if index_exists?
- log_index_info('Skipping index creation as the index exists')
- else
- log_index_info('Creating async index')
-
- set_statement_timeout do
- connection.execute(async_index.definition)
- end
-
- log_index_info('Finished creating async index')
- end
-
- async_index.destroy
- end
- end
-
private
- attr_reader :async_index
-
- def index_exists?
- connection.indexes(async_index.table_name).any? { |index| index.name == async_index.name }
+ override :preconditions_met?
+ def preconditions_met?
+ !index_exists?
end
- def connection
- @connection ||= async_index.connection
+ override :action_type
+ def action_type
+ 'creation'
end
- def lease_timeout
- TIMEOUT_PER_ACTION
+ override :around_execution
+ def around_execution(&block)
+ set_statement_timeout(&block)
end
def set_statement_timeout
@@ -53,10 +29,6 @@ module Gitlab
ensure
connection.execute('RESET statement_timeout')
end
-
- def log_index_info(message)
- Gitlab::AppLogger.info(message: message, table_name: async_index.table_name, index_name: async_index.name)
- end
end
end
end