Commit 2390284a authored by Stan Hu's avatar Stan Hu

Merge branch 'ab/iid-unnecessary-locks' into 'master'

Avoid unnecessary locks on internal_ids (remove feature flag)

Closes #30515

See merge request gitlab-org/gitlab!18328
parents cd151e26 98db5766
......@@ -57,8 +57,7 @@ module AtomicInternalId
end
define_method("track_#{scope}_#{column}!") do
iid_always_track = Feature.enabled?(:iid_always_track, default_enabled: true)
return unless @internal_id_needs_tracking || iid_always_track
return unless @internal_id_needs_tracking
scope_value = internal_id_read_scope(scope)
return unless scope_value
......
......@@ -54,7 +54,7 @@ class InternalId < ApplicationRecord
last_value
end
# Temporary instrumentation to track for-update locks
# Instrumentation to track for-update locks
def update_and_save_counter
strong_memoize(:update_and_save_counter) do
Gitlab::Metrics.counter(:gitlab_internal_id_for_update_lock, 'Number of ROW SHARE (FOR UPDATE) locks on individual records from internal_ids')
......
---
title: Avoid unnecessary locks on internal_ids
merge_request: 18328
author:
type: performance
......@@ -22,41 +22,22 @@ describe AtomicInternalId do
end
context 'when value is set by ensure_project_iid!' do
context 'with iid_always_track false' do
before do
stub_feature_flags(iid_always_track: false)
end
it 'does not track the value' do
expect(InternalId).not_to receive(:track_greatest)
it 'does not track the value' do
expect(InternalId).not_to receive(:track_greatest)
milestone.ensure_project_iid!
subject
end
it 'tracks the iid for the scope that is actually present' do
milestone.iid = external_iid
expect(InternalId).to receive(:track_greatest).once.with(milestone, scope_attrs, usage, external_iid, anything)
expect(InternalId).not_to receive(:generate_next)
# group scope is not present here, the milestone does not have a group
milestone.track_group_iid!
subject
end
milestone.ensure_project_iid!
subject
end
context 'with iid_always_track enabled' do
before do
stub_feature_flags(iid_always_track: true)
end
it 'tracks the iid for the scope that is actually present' do
milestone.iid = external_iid
it 'does not track the value' do
expect(InternalId).to receive(:track_greatest)
expect(InternalId).to receive(:track_greatest).once.with(milestone, scope_attrs, usage, external_iid, anything)
expect(InternalId).not_to receive(:generate_next)
milestone.ensure_project_iid!
subject
end
# group scope is not present here, the milestone does not have a group
milestone.track_group_iid!
subject
end
end
end
......
......@@ -47,10 +47,6 @@ shared_examples_for 'AtomicInternalId' do |validate_presence: true|
end
describe 'internal id generation' do
before do
stub_feature_flags(iid_always_track: false)
end
subject { instance.save! }
it 'calls InternalId.generate_next and sets internal id attribute' 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