Skip to content
Snippets Groups Projects
Commit 08bd50c0 authored by Dylan Griffith's avatar Dylan Griffith
Browse files

Merge branch 'id-fix-snippet-creation-on-replication-lag' into 'master'

Make snippet creation resilient to replication lag

See merge request !136422



Merged-by: default avatarDylan Griffith <dyl.griffith@gmail.com>
Approved-by: default avatarDylan Griffith <dyl.griffith@gmail.com>
Co-authored-by: Igor Drozdov's avatarIgor Drozdov <idrozdov@gitlab.com>
parents 236b9068 51c0904a
No related branches found
No related tags found
1 merge request!136422Make snippet creation resilient to replication lag
Pipeline #1067502909 passed
......@@ -31,6 +31,11 @@ def multi_files_action(user, files = [], **options)
options[:actions] = transform_file_entries(files)
# The Gitaly calls perform HTTP requests for permissions check
# Stick to the primary in order to make those requests aware that
# primary database must be used to fetch the data
self.class.sticking.stick(:user, user.id)
capture_git_error { repository.commit_files(user, **options) }
ensure
Gitlab::ExclusiveLease.cancel(lease_key, uuid)
......
......@@ -4,12 +4,18 @@ module API
# Internal access API
module Internal
class Base < ::API::Base
include Gitlab::RackLoadBalancingHelpers
before { authenticate_by_gitlab_shell_token! }
before do
api_endpoint = env['api.endpoint']
feature_category = api_endpoint.options[:for].try(:feature_category_for_app, api_endpoint).to_s
if actor.user
load_balancer_stick_request(::User, :user, actor.user.id)
end
Gitlab::ApplicationContext.push(
user: -> { actor&.user },
project: -> { project },
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe SnippetRepository do
RSpec.describe SnippetRepository, feature_category: :snippets do
let_it_be(:user) { create(:user) }
let(:snippet) { create(:personal_snippet, :repository, author: user) }
......@@ -68,6 +68,8 @@
expect(update_file_blob).not_to be_nil
end
expect(described_class.sticking).to receive(:stick)
expect do
snippet_repository.multi_files_action(user, data, **commit_opts)
end.not_to raise_error
......
......@@ -1527,7 +1527,7 @@ def request
describe 'POST /internal/pre_receive' do
let(:valid_params) do
{ gl_repository: gl_repository }
{ gl_repository: gl_repository, user_id: user.id }
end
it 'decreases the reference counter and returns the result' do
......@@ -1539,6 +1539,12 @@ def request
expect(json_response['reference_counter_increased']).to be(true)
end
it 'sticks to the primary' do
expect(User.sticking).to receive(:find_caught_up_replica).with(:user, user.id)
post api("/internal/pre_receive"), params: valid_params, headers: gitlab_shell_internal_api_request_header
end
end
describe 'POST /internal/two_factor_config' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment