Commit 5dbc1c26 authored by Stan Hu's avatar Stan Hu

Merge branch 'georgekoltsov/update-export-workers-data-consistency' into 'master'

Update Export workers to read from replica

See merge request gitlab-org/gitlab!68153
parents 52a4fad1 d63e1672
---
name: load_balancing_for_export_workers
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68153
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/338615
milestone: '14.2'
type: development
group: group::import
default_enabled: false
...@@ -31,10 +31,12 @@ module Gitlab ...@@ -31,10 +31,12 @@ module Gitlab
end end
def execute def execute
serialize_root read_from_replica_if_available do
serialize_root
includes.each do |relation_definition| includes.each do |relation_definition|
serialize_relation(relation_definition) serialize_relation(relation_definition)
end
end end
end end
...@@ -166,6 +168,13 @@ module Gitlab ...@@ -166,6 +168,13 @@ module Gitlab
) )
]) ])
end end
def read_from_replica_if_available(&block)
return yield unless ::Feature.enabled?(:load_balancing_for_export_workers, type: :development, default_enabled: :yaml)
return yield unless ::Gitlab::Database::LoadBalancing.enable?
::Gitlab::Database::LoadBalancing::Session.current.use_replicas_for_read_queries(&block)
end
end end
end end
end end
......
...@@ -156,6 +156,41 @@ RSpec.describe Gitlab::ImportExport::Json::StreamingSerializer do ...@@ -156,6 +156,41 @@ RSpec.describe Gitlab::ImportExport::Json::StreamingSerializer do
subject.execute subject.execute
end end
end end
describe 'load balancing' do
context 'when feature flag load_balancing_for_export_workers is enabled' do
before do
stub_feature_flags(load_balancing_for_export_workers: true)
end
context 'when enabled', :db_load_balancing do
it 'reads from replica' do
expect(Gitlab::Database::LoadBalancing::Session.current).to receive(:use_replicas_for_read_queries).and_call_original
subject.execute
end
end
context 'when disabled' do
it 'reads from primary' do
allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(false)
expect(Gitlab::Database::LoadBalancing::Session.current).not_to receive(:use_replicas_for_read_queries)
subject.execute
end
end
end
context 'when feature flag load_balancing_for_export_workers is disabled' do
it 'reads from primary' do
stub_feature_flags(load_balancing_for_export_workers: false)
expect(Gitlab::Database::LoadBalancing::Session.current).not_to receive(:use_replicas_for_read_queries)
subject.execute
end
end
end
end end
describe '.batch_size' do describe '.batch_size' 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