diff options
Diffstat (limited to 'lib/tasks/gitlab/db.rake')
-rw-r--r-- | lib/tasks/gitlab/db.rake | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake index e2647021914..e83c4cbdb39 100644 --- a/lib/tasks/gitlab/db.rake +++ b/lib/tasks/gitlab/db.rake @@ -160,35 +160,44 @@ namespace :gitlab do Rake::Task['gitlab:db:create_dynamic_partitions'].invoke end - desc 'reindex a regular index without downtime to eliminate bloat' - task :reindex, [:index_name] => :environment do |_, args| - unless Feature.enabled?(:database_reindexing, type: :ops) + desc 'execute reindexing without downtime to eliminate bloat' + task reindex: :environment do + unless Feature.enabled?(:database_reindexing, type: :ops, default_enabled: :yaml) puts "This feature (database_reindexing) is currently disabled.".color(:yellow) exit end - indexes = Gitlab::Database::PostgresIndex.reindexing_support + Gitlab::Database::EachDatabase.each_database_connection do |connection, connection_name| + Gitlab::Database::SharedModel.logger = Logger.new($stdout) if Gitlab::Utils.to_boolean(ENV['LOG_QUERIES_TO_CONSOLE'], default: false) - if identifier = args[:index_name] - raise ArgumentError, "Index name is not fully qualified with a schema: #{identifier}" unless identifier =~ /^\w+\.\w+$/ + # Hack: Before we do actual reindexing work, create async indexes + Gitlab::Database::AsyncIndexes.create_pending_indexes! if Feature.enabled?(:database_async_index_creation, type: :ops) - indexes = indexes.where(identifier: identifier) - - raise "Index not found or not supported: #{args[:index_name]}" if indexes.empty? + Gitlab::Database::Reindexing.automatic_reindexing end + rescue StandardError => e + Gitlab::AppLogger.error(e) + raise + end - ActiveRecord::Base.logger = Logger.new($stdout) if Gitlab::Utils.to_boolean(ENV['LOG_QUERIES_TO_CONSOLE'], default: false) + desc 'Enqueue an index for reindexing' + task :enqueue_reindexing_action, [:index_name, :database] => :environment do |_, args| + model = Gitlab::Database.database_base_models[args.fetch(:database, Gitlab::Database::PRIMARY_DATABASE_NAME)] - # Cleanup leftover temporary indexes from previous, possibly aborted runs (if any) - Gitlab::Database::Reindexing.cleanup_leftovers! + Gitlab::Database::SharedModel.using_connection(model.connection) do + queued_action = Gitlab::Database::PostgresIndex.find(args[:index_name]).queued_reindexing_actions.create! - # Hack: Before we do actual reindexing work, create async indexes - Gitlab::Database::AsyncIndexes.create_pending_indexes! if Feature.enabled?(:database_async_index_creation, type: :ops) + puts "Queued reindexing action: #{queued_action}" + puts "There are #{Gitlab::Database::Reindexing::QueuedAction.queued.size} queued actions in total." + end - Gitlab::Database::Reindexing.perform(indexes) - rescue StandardError => e - Gitlab::AppLogger.error(e) - raise + unless Feature.enabled?(:database_reindexing, type: :ops, default_enabled: :yaml) + puts <<~NOTE.color(:yellow) + Note: database_reindexing feature is currently disabled. + + Enable with: Feature.enable(:database_reindexing) + NOTE + end end desc 'Check if there have been user additions to the database' |