Commit b7a6b876 authored by Andreas Brandl's avatar Andreas Brandl

Rename subtrans to savepoints

parent a82dde8a
...@@ -414,7 +414,7 @@ module Gitlab ...@@ -414,7 +414,7 @@ module Gitlab
merged_args = { merged_args = {
klass: self.class, klass: self.class,
logger: Gitlab::BackgroundMigration::Logger, logger: Gitlab::BackgroundMigration::Logger,
allow_subtrans: true allow_savepoints: true
}.merge(kwargs) }.merge(kwargs)
Gitlab::Database::WithLockRetries.new(**merged_args) Gitlab::Database::WithLockRetries.new(**merged_args)
......
...@@ -41,7 +41,7 @@ module Gitlab ...@@ -41,7 +41,7 @@ module Gitlab
# * +logger+ - [Gitlab::JsonLogger] # * +logger+ - [Gitlab::JsonLogger]
# * +env+ - [Hash] custom environment hash, see the example with `DISABLE_LOCK_RETRIES` # * +env+ - [Hash] custom environment hash, see the example with `DISABLE_LOCK_RETRIES`
def with_lock_retries(*args, **kwargs, &block) def with_lock_retries(*args, **kwargs, &block)
super(*args, **kwargs.merge(allow_subtrans: false), &block) super(*args, **kwargs.merge(allow_savepoints: false), &block)
end end
# Renames a column without requiring downtime. # Renames a column without requiring downtime.
......
...@@ -61,10 +61,10 @@ module Gitlab ...@@ -61,10 +61,10 @@ module Gitlab
[10.seconds, 10.minutes] [10.seconds, 10.minutes]
].freeze ].freeze
def initialize(logger: NULL_LOGGER, allow_subtrans: true, timing_configuration: DEFAULT_TIMING_CONFIGURATION, klass: nil, env: ENV) def initialize(logger: NULL_LOGGER, allow_savepoints: true, timing_configuration: DEFAULT_TIMING_CONFIGURATION, klass: nil, env: ENV)
@logger = logger @logger = logger
@klass = klass @klass = klass
@allow_subtrans = allow_subtrans @allow_savepoints = allow_savepoints
@timing_configuration = timing_configuration @timing_configuration = timing_configuration
@env = env @env = env
@current_iteration = 1 @current_iteration = 1
...@@ -123,7 +123,7 @@ module Gitlab ...@@ -123,7 +123,7 @@ module Gitlab
end end
def run_block_with_lock_timeout def run_block_with_lock_timeout
raise "WithLockRetries should not run inside already open transaction" if ActiveRecord::Base.connection.transaction_open? && @allow_subtrans.blank? raise "WithLockRetries should not run inside already open transaction" if ActiveRecord::Base.connection.transaction_open? && @allow_savepoints.blank?
ActiveRecord::Base.transaction(requires_new: true) do # rubocop:disable Performance/ActiveRecordSubtransactions ActiveRecord::Base.transaction(requires_new: true) do # rubocop:disable Performance/ActiveRecordSubtransactions
execute("SET LOCAL lock_timeout TO '#{current_lock_timeout_in_ms}ms'") execute("SET LOCAL lock_timeout TO '#{current_lock_timeout_in_ms}ms'")
......
...@@ -262,7 +262,7 @@ RSpec.describe Gitlab::Database::MigrationHelpers::V2 do ...@@ -262,7 +262,7 @@ RSpec.describe Gitlab::Database::MigrationHelpers::V2 do
it 'defaults to disallowing subtransactions' do it 'defaults to disallowing subtransactions' do
with_lock_retries = double with_lock_retries = double
expect(Gitlab::Database::WithLockRetries).to receive(:new).with(hash_including(allow_subtrans: false)).and_return(with_lock_retries) expect(Gitlab::Database::WithLockRetries).to receive(:new).with(hash_including(allow_savepoints: false)).and_return(with_lock_retries)
expect(with_lock_retries).to receive(:run).with(raise_on_exhaustion: false) expect(with_lock_retries).to receive(:run).with(raise_on_exhaustion: false)
model.with_lock_retries(env: env, logger: in_memory_logger) { } model.with_lock_retries(env: env, logger: in_memory_logger) { }
......
...@@ -2335,7 +2335,7 @@ RSpec.describe Gitlab::Database::MigrationHelpers do ...@@ -2335,7 +2335,7 @@ RSpec.describe Gitlab::Database::MigrationHelpers do
it 'defaults to allowing subtransactions' do it 'defaults to allowing subtransactions' do
with_lock_retries = double with_lock_retries = double
expect(Gitlab::Database::WithLockRetries).to receive(:new).with(hash_including(allow_subtrans: true)).and_return(with_lock_retries) expect(Gitlab::Database::WithLockRetries).to receive(:new).with(hash_including(allow_savepoints: true)).and_return(with_lock_retries)
expect(with_lock_retries).to receive(:run).with(raise_on_exhaustion: false) expect(with_lock_retries).to receive(:run).with(raise_on_exhaustion: false)
model.with_lock_retries(env: env, logger: in_memory_logger) { } model.with_lock_retries(env: env, logger: in_memory_logger) { }
......
...@@ -5,8 +5,8 @@ require 'spec_helper' ...@@ -5,8 +5,8 @@ require 'spec_helper'
RSpec.describe Gitlab::Database::WithLockRetries do RSpec.describe Gitlab::Database::WithLockRetries do
let(:env) { {} } let(:env) { {} }
let(:logger) { Gitlab::Database::WithLockRetries::NULL_LOGGER } let(:logger) { Gitlab::Database::WithLockRetries::NULL_LOGGER }
let(:subject) { described_class.new(env: env, logger: logger, allow_subtrans: allow_subtrans, timing_configuration: timing_configuration) } let(:subject) { described_class.new(env: env, logger: logger, allow_savepoints: allow_savepoints, timing_configuration: timing_configuration) }
let(:allow_subtrans) { true } let(:allow_savepoints) { true }
let(:timing_configuration) do let(:timing_configuration) do
[ [
...@@ -258,8 +258,8 @@ RSpec.describe Gitlab::Database::WithLockRetries do ...@@ -258,8 +258,8 @@ RSpec.describe Gitlab::Database::WithLockRetries do
end end
end end
context 'Stop using subtransactions - allow_subtrans: false' do context 'Stop using subtransactions - allow_savepoints: false' do
let(:allow_subtrans) { false } let(:allow_savepoints) { false }
it 'prevents running inside already open transaction' do it 'prevents running inside already open transaction' do
allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(true) allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(true)
......
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