Commit 26a8a7ff authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Remove use_insert_all_in_internal_id feature flag

Creates internal ID records without using a subtransaction

Also changes, insert_all to insert since they're just the same under the
hood

Changelog: other
parent a998bacb
......@@ -223,33 +223,19 @@ class InternalId < ApplicationRecord
# If another process was faster in doing this, we'll end up with that record
# when we do the lookup after the insert.
def create_record
if Feature.enabled?(:use_insert_all_in_internal_id, default_enabled: :yaml)
scope[:project].save! if scope[:project] && !scope[:project].persisted?
scope[:namespace].save! if scope[:namespace] && !scope[:namespace].persisted?
scope[:project].save! if scope[:project] && !scope[:project].persisted?
scope[:namespace].save! if scope[:namespace] && !scope[:namespace].persisted?
attributes = {
project_id: scope[:project]&.id || scope[:project_id],
namespace_id: scope[:namespace]&.id || scope[:namespace_id],
usage: usage_value,
last_value: initial_value(subject, scope)
}
attributes = {
project_id: scope[:project]&.id || scope[:project_id],
namespace_id: scope[:namespace]&.id || scope[:namespace_id],
usage: usage_value,
last_value: initial_value(subject, scope)
}
InternalId.insert_all([attributes])
InternalId.insert(attributes)
lookup
else
begin
subject.transaction(requires_new: true) do # rubocop:disable Performance/ActiveRecordSubtransactions
InternalId.create!(
**scope,
usage: usage_value,
last_value: initial_value(subject, scope)
)
end
rescue ActiveRecord::RecordNotUnique
lookup
end
end
lookup
end
end
......@@ -344,32 +330,21 @@ class InternalId < ApplicationRecord
end
def create_record!(subject, scope, usage, value)
if Feature.enabled?(:use_insert_all_in_internal_id, default_enabled: :yaml)
scope[:project].save! if scope[:project] && !scope[:project].persisted?
scope[:namespace].save! if scope[:namespace] && !scope[:namespace].persisted?
scope[:project].save! if scope[:project] && !scope[:project].persisted?
scope[:namespace].save! if scope[:namespace] && !scope[:namespace].persisted?
attributes = {
project_id: scope[:project]&.id || scope[:project_id],
namespace_id: scope[:namespace]&.id || scope[:namespace_id],
usage: usage_value,
last_value: value
}
attributes = {
project_id: scope[:project]&.id || scope[:project_id],
namespace_id: scope[:namespace]&.id || scope[:namespace_id],
usage: usage_value,
last_value: value
}
result = InternalId.insert_all([attributes])
result = InternalId.insert(attributes)
raise RecordAlreadyExists if result.empty?
raise RecordAlreadyExists if result.empty?
value
else
begin
subject.transaction(requires_new: true) do # rubocop:disable Performance/ActiveRecordSubtransactions
internal_id = InternalId.create!(**scope, usage: usage, last_value: value)
internal_id.last_value
end
rescue ActiveRecord::RecordNotUnique
raise RecordAlreadyExists
end
end
value
end
def arel_table
......
---
name: use_insert_all_in_internal_id
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68617
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/339141
milestone: '14.3'
type: development
group: group::project management
default_enabled: false
......@@ -243,21 +243,7 @@ RSpec.describe InternalId do
stub_feature_flags(generate_iids_without_explicit_locking: false)
end
context 'when the insert all feature flag is enabled' do
before do
stub_feature_flags(use_insert_all_in_internal_id: true)
end
it_behaves_like 'a monotonically increasing id generator'
end
context 'when the insert all feature flag is disabled' do
before do
stub_feature_flags(use_insert_all_in_internal_id: false)
end
it_behaves_like 'a monotonically increasing id generator'
end
it_behaves_like 'a monotonically increasing id generator'
end
context 'when the explicit locking feature flag is enabled' do
......@@ -265,21 +251,7 @@ RSpec.describe InternalId do
stub_feature_flags(generate_iids_without_explicit_locking: true)
end
context 'when the insert all feature flag is enabled' do
before do
stub_feature_flags(use_insert_all_in_internal_id: true)
end
it_behaves_like 'a monotonically increasing id generator'
end
context 'when the insert all feature flag is disabled' do
before do
stub_feature_flags(use_insert_all_in_internal_id: false)
end
it_behaves_like 'a monotonically increasing id generator'
end
it_behaves_like 'a monotonically increasing id generator'
end
describe '#increment_and_save!' do
......
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