Skip to content
Snippets Groups Projects

Adjust sub-batch size for failed Batched Background Migration Jobs

1 file
+ 18
2
Compare changes
  • Side-by-side
  • Inline
@@ -7,6 +7,7 @@ module BackgroundMigration
#
# Job arguments needed must be defined explicitly,
# see https://docs.gitlab.com/ee/development/database/batched_background_migrations.html#job-arguments.
# rubocop:disable Metrics/ClassLength
class BatchedMigrationJob
include Gitlab::Database::DynamicModelHelpers
include Gitlab::ClassAttributes
@@ -96,8 +97,14 @@ def each_sub_batch(batching_arguments: {}, batching_scope: nil)
sub_batch_relation = filter_sub_batch(relation, batching_scope)
sub_batch_relation.each_batch(**all_batching_arguments) do |relation|
batch_metrics.instrument_operation(operation_name) do
yield relation
instrumenter = Gitlab::Database::BackgroundMigration::SqlErrorTrackerInstrumenter.new
ActiveSupport::Notifications.subscribed(instrumenter, 'sql.active_record') do
batch_metrics.instrument_operation(operation_name) do
yield relation
rescue *timeout_exceptions => exception
raise sub_batch_exception_class.new(exception, instrumenter.result)
end
end
sleep([pause_ms, 0].max * 0.001)
@@ -134,6 +141,15 @@ def filter_sub_batch(relation, batching_scope = nil)
def operation_name
raise('Operation name is required, please define it with `operation_name`')
end
def sub_batch_exception_class
::Gitlab::Database::BackgroundMigration::Error::SubBatchTimeoutException
end
def timeout_exceptions
sub_batch_exception_class::TIMEOUT_EXCEPTIONS
end
end
end
end
# rubocop:enable Metrics/ClassLength
Loading