Commit ef987699 authored by Nikola Milojevic's avatar Nikola Milojevic

Merge branch '346836-avoid-tps-increase' into 'master'

Avoid DB calls in MultiStore empty DB case guard

See merge request gitlab-org/gitlab!77180
parents 6153b8c1 d4662859
# frozen_string_literal: true
return unless Gitlab.com? || Gitlab.dev_or_test_env?
def feature_flags_available?
# When the DBMS is not available, an exception (e.g. PG::ConnectionBad) is raised
active_db_connection = ActiveRecord::Base.connection.active? rescue false
......@@ -9,8 +11,6 @@ rescue ActiveRecord::NoDatabaseError
false
end
return unless Gitlab.com? || Gitlab.dev_or_test_env?
Gitlab::Application.configure do
if feature_flags_available? && ::Feature.enabled?(:active_record_transactions_tracking, type: :ops, default_enabled: :yaml)
Gitlab::Database::Transaction::Observer.register!
......
......@@ -97,19 +97,22 @@ module Gitlab
end
def use_primary_and_secondary_stores?
feature_flags_available? &&
Feature.enabled?("use_primary_and_secondary_stores_for_#{instance_name.underscore}", default_enabled: :yaml) &&
!same_redis_store?
feature_table_exists? && Feature.enabled?("use_primary_and_secondary_stores_for_#{instance_name.underscore}", default_enabled: :yaml) && !same_redis_store?
end
def use_primary_store_as_default?
feature_flags_available? &&
Feature.enabled?("use_primary_store_as_default_for_#{instance_name.underscore}", default_enabled: :yaml) &&
!same_redis_store?
feature_table_exists? && Feature.enabled?("use_primary_store_as_default_for_#{instance_name.underscore}", default_enabled: :yaml) && !same_redis_store?
end
private
# @return [Boolean]
def feature_table_exists?
Feature::FlipperFeature.table_exists?
rescue StandardError
false
end
def default_store
use_primary_store_as_default? ? primary_store : secondary_store
end
......
......@@ -646,6 +646,26 @@ RSpec.describe Gitlab::Redis::MultiStore do
expect(multi_store.use_primary_and_secondary_stores?).to be false
end
end
context 'with empty DB' do
before do
allow(Feature::FlipperFeature).to receive(:table_exists?).and_return(false)
end
it 'multi store is disabled' do
expect(multi_store.use_primary_and_secondary_stores?).to be false
end
end
context 'when FF table guard raises' do
before do
allow(Feature::FlipperFeature).to receive(:table_exists?).and_raise
end
it 'multi store is disabled' do
expect(multi_store.use_primary_and_secondary_stores?).to be false
end
end
end
describe '#use_primary_store_as_default?' do
......@@ -668,6 +688,26 @@ RSpec.describe Gitlab::Redis::MultiStore do
expect(multi_store.use_primary_store_as_default?).to be false
end
end
context 'with empty DB' do
before do
allow(Feature::FlipperFeature).to receive(:table_exists?).and_return(false)
end
it 'multi store is disabled' do
expect(multi_store.use_primary_and_secondary_stores?).to be false
end
end
context 'when FF table guard raises' do
before do
allow(Feature::FlipperFeature).to receive(:table_exists?).and_raise
end
it 'multi store is disabled' do
expect(multi_store.use_primary_and_secondary_stores?).to be false
end
end
end
def create_redis_store(options, extras = {})
......
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