Commit b12d3393 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '351585-support-multiple-databases-for-batched-background-migrations' into 'master'

Resolve "Support multiple databases for batched background migrations"

See merge request gitlab-org/gitlab!83109
parents 7336ccfa 65e1c4ce
......@@ -4,6 +4,10 @@ module Database
class CiDatabaseWorker # rubocop:disable Scalability/IdempotentWorker
include SingleDatabaseWorker
def self.enabled?
Feature.enabled?(:execute_batched_migrations_on_schedule_ci_database, type: :ops, default_enabled: :yaml)
end
def self.tracking_database
@tracking_database ||= Gitlab::Database::CI_DATABASE_NAME
end
......
......@@ -23,6 +23,10 @@ module Database
def tracking_database
raise NotImplementedError, "#{self.name} does not implement #{__method__}"
end
def enabled?
raise NotImplementedError, "#{self.name} does not implement #{__method__}"
end
# :nocov:
def lease_key
......@@ -41,7 +45,7 @@ module Database
end
Gitlab::Database::SharedModel.using_connection(base_model.connection) do
break unless Feature.enabled?(:execute_batched_migrations_on_schedule, type: :ops, default_enabled: :yaml) && active_migration
break unless self.class.enabled? && active_migration
with_exclusive_lease(active_migration.interval) do
# Now that we have the exclusive lease, reload migration in case another process has changed it.
......
......@@ -4,6 +4,10 @@ module Database
class BatchedBackgroundMigrationWorker # rubocop:disable Scalability/IdempotentWorker
include BatchedBackgroundMigration::SingleDatabaseWorker
def self.enabled?
Feature.enabled?(:execute_batched_migrations_on_schedule, type: :ops, default_enabled: :yaml)
end
def self.tracking_database
@tracking_database ||= Gitlab::Database::MAIN_DATABASE_NAME.to_sym
end
......
---
name: execute_batched_migrations_on_schedule_ci_database
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/83109
rollout_issue_url:
milestone: '14.9'
type: ops
group: group::database
default_enabled: false
# frozen_string_literal: true
RSpec.shared_examples 'it runs batched background migration jobs' do |tracking_database|
RSpec.shared_examples 'it runs batched background migration jobs' do |tracking_database, feature_flag:|
include ExclusiveLeaseHelpers
describe 'defining the job attributes' do
......@@ -39,6 +39,16 @@ RSpec.shared_examples 'it runs batched background migration jobs' do |tracking_d
end
end
describe '.enabled?' do
it 'does not raise an error' do
expect { described_class.enabled? }.not_to raise_error
end
it 'returns true' do
expect(described_class.enabled?).to be_truthy
end
end
describe '#perform' do
subject(:worker) { described_class.new }
......@@ -76,7 +86,7 @@ RSpec.shared_examples 'it runs batched background migration jobs' do |tracking_d
context 'when the feature flag is disabled' do
before do
stub_feature_flags(execute_batched_migrations_on_schedule: false)
stub_feature_flags(feature_flag => false)
end
it 'does nothing' do
......@@ -89,7 +99,7 @@ RSpec.shared_examples 'it runs batched background migration jobs' do |tracking_d
context 'when the feature flag is enabled' do
before do
stub_feature_flags(execute_batched_migrations_on_schedule: true)
stub_feature_flags(feature_flag => true)
allow(Gitlab::Database::BackgroundMigration::BatchedMigration).to receive(:active_migration).and_return(nil)
end
......
......@@ -3,5 +3,5 @@
require 'spec_helper'
RSpec.describe Database::BatchedBackgroundMigration::CiDatabaseWorker, :clean_gitlab_redis_shared_state do
it_behaves_like 'it runs batched background migration jobs', 'ci'
it_behaves_like 'it runs batched background migration jobs', 'ci', feature_flag: :execute_batched_migrations_on_schedule_ci_database
end
......@@ -3,5 +3,5 @@
require 'spec_helper'
RSpec.describe Database::BatchedBackgroundMigrationWorker do
it_behaves_like 'it runs batched background migration jobs', :main
it_behaves_like 'it runs batched background migration jobs', :main, feature_flag: :execute_batched_migrations_on_schedule
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment