diff options
-rw-r--r-- | lib/gitlab/database/migration_helpers.rb | 9 | ||||
-rw-r--r-- | spec/lib/gitlab/database/migration_helpers_spec.rb | 1 |
2 files changed, 7 insertions, 3 deletions
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index 3f65bc912de..bb4a5660c36 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -219,6 +219,7 @@ module Gitlab # table - The name of the table. # column - The name of the column to update. # value - The value for the column. + # wait_time - The amount of time to wait between batches, in seconds. # # The `value` argument is typically a literal. To perform a computed # update, an Arel literal can be used instead: @@ -235,7 +236,7 @@ module Gitlab # make things _more_ complex). # # rubocop: disable Metrics/AbcSize - def update_column_in_batches(table, column, value) + def update_column_in_batches(table, column, value, wait_time: 2) if transaction_open? raise 'update_column_in_batches can not be run inside a transaction, ' \ 'you can disable transactions by calling disable_ddl_transaction! ' \ @@ -253,9 +254,9 @@ module Gitlab # Update in batches of 5% until we run out of any rows to update. batch_size = ((total / 100.0) * 5.0).ceil - max_size = 1000 + max_size = 10_000 - # The upper limit is 1000 to ensure we don't lock too many rows. For + # The upper limit is 10_000 to ensure we don't lock too many rows. For # example, for "merge_requests" even 1% of the table is around 35 000 # rows for GitLab.com. batch_size = max_size if batch_size > max_size @@ -289,6 +290,8 @@ module Gitlab execute(update_arel.to_sql) + sleep(wait_time) if wait_time + # There are no more rows left to update. break unless stop_row end diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index 664ba0f7234..97aff3e2b60 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -7,6 +7,7 @@ describe Gitlab::Database::MigrationHelpers do before do allow(model).to receive(:puts) + allow(model).to receive(:sleep) end describe '#add_timestamps_with_timezone' do |