Skip to content
代码片段 群组 项目
未验证 提交 6a092329 编辑于 作者: James Fargher's avatar James Fargher 提交者: GitLab
浏览文件

Merge branch '462379-disable-sticky-writes-PAT-last-used-service' into 'master'

Disable sticky writes in the PAT last used service

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/153707



Merged-by: default avatarJames Fargher <jfargher@gitlab.com>
Approved-by: default avatarImre Farkas <ifarkas@gitlab.com>
Approved-by: default avatarJames Fargher <jfargher@gitlab.com>
Co-authored-by: default avatarDavid Fernandez <dfernandez@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -12,7 +12,7 @@ def execute
# We _only_ want to update last_used_at and not also updated_at (which
# would be updated when using #touch).
@personal_access_token.update_column(:last_used_at, Time.zone.now) if update?
without_sticky_writes { @personal_access_token.update_column(:last_used_at, Time.zone.now) } if update?
end
private
......@@ -26,5 +26,15 @@ def update?
last_used <= 10.minutes.ago
end
def without_sticky_writes
if Feature.enabled?(:disable_sticky_writes_for_pat_last_used, @personal_access_token.user)
::Gitlab::Database::LoadBalancing::Session.without_sticky_writes do
yield
end
else
yield
end
end
end
end
---
name: disable_sticky_writes_for_pat_last_used
feature_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/462379
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/153707
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/462823
milestone: '17.1'
group: group::package registry
type: gitlab_com_derisk
default_enabled: false
......@@ -18,6 +18,34 @@
expect { subject }.not_to change { personal_access_token.last_used_at }
end
context 'when database load balancing is configured' do
let!(:service) { described_class.new(personal_access_token) }
it 'does not stick to primary' do
::Gitlab::Database::LoadBalancing::Session.clear_session
expect(::Gitlab::Database::LoadBalancing::Session.current).not_to be_performed_write
expect { service.execute }.to change { personal_access_token.last_used_at }
expect(::Gitlab::Database::LoadBalancing::Session.current).to be_performed_write
expect(::Gitlab::Database::LoadBalancing::Session.current).not_to be_using_primary
end
context 'with disable_sticky_writes_for_pat_last_used disabled' do
before do
stub_feature_flags(disable_sticky_writes_for_pat_last_used: false)
end
it 'does stick to primary' do
::Gitlab::Database::LoadBalancing::Session.clear_session
expect(::Gitlab::Database::LoadBalancing::Session.current).not_to be_performed_write
expect { service.execute }.to change { personal_access_token.last_used_at }
expect(::Gitlab::Database::LoadBalancing::Session.current).to be_performed_write
expect(::Gitlab::Database::LoadBalancing::Session.current).to be_using_primary
end
end
end
end
context 'when the personal access token was used less than 10 minutes ago', :freeze_time do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册