summaryrefslogtreecommitdiff
path: root/lib/tasks/gitlab/db.rake
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 13:16:36 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 13:16:36 +0000
commit311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch)
tree07e7870bca8aed6d61fdcc810731c50d2c40af47 /lib/tasks/gitlab/db.rake
parent27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff)
downloadgitlab-ce-311b0269b4eb9839fa63f80c8d7a58f32b8138a0.tar.gz
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'lib/tasks/gitlab/db.rake')
-rw-r--r--lib/tasks/gitlab/db.rake45
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'