From 6b5d8b17e28741bccf31029633cc5af7ceab1486 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 18 May 2022 18:08:05 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../single_database_worker.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'app/workers/database/batched_background_migration/single_database_worker.rb') diff --git a/app/workers/database/batched_background_migration/single_database_worker.rb b/app/workers/database/batched_background_migration/single_database_worker.rb index aeadda4b8e1..8a0de268048 100644 --- a/app/workers/database/batched_background_migration/single_database_worker.rb +++ b/app/workers/database/batched_background_migration/single_database_worker.rb @@ -7,6 +7,7 @@ module Database include ApplicationWorker include CronjobQueue # rubocop:disable Scalability/CronWorkerContext + include Gitlab::Utils::StrongMemoize LEASE_TIMEOUT_MULTIPLIER = 3 MINIMUM_LEASE_TIMEOUT = 10.minutes.freeze @@ -44,6 +45,15 @@ module Database return end + if shares_db_config? + Sidekiq.logger.info( + class: self.class.name, + database: self.class.tracking_database, + message: 'skipping migration execution for database that shares database configuration with another database') + + return + end + Gitlab::Database::SharedModel.using_connection(base_model.connection) do break unless self.class.enabled? && active_migration @@ -63,7 +73,7 @@ module Database private def active_migration - @active_migration ||= Gitlab::Database::BackgroundMigration::BatchedMigration.active_migration + @active_migration ||= Gitlab::Database::BackgroundMigration::BatchedMigration.active_migration(connection: base_model.connection) end def run_active_migration @@ -71,7 +81,13 @@ module Database end def base_model - @base_model ||= Gitlab::Database.database_base_models[self.class.tracking_database] + strong_memoize(:base_model) do + Gitlab::Database.database_base_models[self.class.tracking_database] + end + end + + def shares_db_config? + base_model && Gitlab::Database.db_config_share_with(base_model.connection_db_config).present? end def with_exclusive_lease(interval) -- cgit v1.2.3