Commit 838422d7 authored by Kamil Trzciński's avatar Kamil Trzciński

Remove GITLAB_LB_CONFIGURE_CONNECTION feature flag

The connection pool size reconfigure was moved
to load balancer setup. This is safe and we can
remove the legacy code.
parent de0aa461
......@@ -10,10 +10,6 @@ Gitlab.ee do
end
end
unless Gitlab::Utils.to_boolean(ENV["GITLAB_LB_CONFIGURE_CONNECTION"], default: true)
ActiveRecord::Base.establish_connection(Gitlab::Database.main.db_config_with_default_pool_size)
end
Gitlab.ee do
if Gitlab::Runtime.sidekiq? && Gitlab::Geo.geo_database_configured?
Rails.configuration.geo_database['pool'] = Gitlab::Database.default_pool_size
......
......@@ -59,20 +59,6 @@ module Gitlab
adapter_name.casecmp('postgresql') == 0
end
# TODO: To be removed with GITLAB_LB_CONFIGURE_CONNECTION
def db_config_with_default_pool_size
db_config_object = scope.connection_db_config
config = db_config_object
.configuration_hash
.merge(pool: Database.default_pool_size)
ActiveRecord::DatabaseConfigurations::HashConfig.new(
db_config_object.env_name,
db_config_object.name,
config
)
end
# Check whether the underlying database is in read-only mode
def db_read_only?
pg_is_in_recovery =
......
......@@ -22,17 +22,10 @@ module Gitlab
def configure_connection
db_config_object = @model.connection_db_config
hash =
if Gitlab::Utils.to_boolean(ENV["GITLAB_LB_CONFIGURE_CONNECTION"], default: true)
db_config_object.configuration_hash.merge(
prepared_statements: false,
pool: Gitlab::Database.default_pool_size
)
else
db_config_object.configuration_hash.merge(
prepared_statements: false
)
end
hash = db_config_object.configuration_hash.merge(
prepared_statements: false,
pool: Gitlab::Database.default_pool_size
)
hash_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(
db_config_object.env_name,
......
......@@ -7,13 +7,6 @@ RSpec.describe 'Database config initializer', :reestablished_active_record_base
load Rails.root.join('config/initializers/database_config.rb')
end
before do
allow(Gitlab::Runtime).to receive(:max_threads).and_return(max_threads)
stub_env('GITLAB_LB_CONFIGURE_CONNECTION', 'false')
end
let(:max_threads) { 8 }
it 'retains the correct database name for the connection' do
previous_db_name = Gitlab::Database.main.scope.connection.pool.db_config.name
......@@ -22,52 +15,7 @@ RSpec.describe 'Database config initializer', :reestablished_active_record_base
expect(Gitlab::Database.main.scope.connection.pool.db_config.name).to eq(previous_db_name)
end
context 'when no custom headroom is specified' do
it 'sets the pool size based on the number of worker threads' do
old = ActiveRecord::Base.connection_db_config.pool
expect(old).not_to eq(18)
expect { subject }
.to change { ActiveRecord::Base.connection_db_config.pool }
.from(old)
.to(18)
end
it 'overwrites custom pool settings' do
config = Gitlab::Database.main.config.merge(pool: 42)
allow(Gitlab::Database.main).to receive(:config).and_return(config)
subject
expect(ActiveRecord::Base.connection_db_config.pool).to eq(18)
end
context 'when GITLAB_LB_CONFIGURE_CONNECTION=true' do
before do
stub_env('GITLAB_LB_CONFIGURE_CONNECTION', 'true')
end
it 'does not overwrite custom pool settings' do
expect { subject }.not_to change { ActiveRecord::Base.connection_db_config.pool }
end
end
end
context "when specifying headroom through an ENV variable" do
let(:headroom) { 15 }
before do
stub_env("DB_POOL_HEADROOM", headroom)
end
it "adds headroom on top of the calculated size" do
old = ActiveRecord::Base.connection_db_config.pool
expect { subject }
.to change { ActiveRecord::Base.connection_db_config.pool }
.from(old)
.to(23)
end
it 'does not overwrite custom pool settings' do
expect { subject }.not_to change { ActiveRecord::Base.connection_db_config.pool }
end
end
......@@ -112,20 +112,6 @@ RSpec.describe Gitlab::Database::Connection do
end
end
describe '#db_config_with_default_pool_size' do
it 'returns db_config with our default pool size' do
allow(Gitlab::Database).to receive(:default_pool_size).and_return(9)
expect(connection.db_config_with_default_pool_size.pool).to eq(9)
end
it 'returns db_config with the correct database name' do
db_name = connection.scope.connection.pool.db_config.name
expect(connection.db_config_with_default_pool_size.name).to eq(db_name)
end
end
describe '#db_read_only?' do
it 'detects a read-only database' do
allow(connection.scope.connection)
......
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