debian-mirror-gitlab/config/initializers/load_balancing.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.6 KiB
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
2021-11-18 22:05:49 +05:30
Gitlab::Application.configure do |config|
config.middleware.use(Gitlab::Database::LoadBalancing::RackMiddleware)
2022-11-25 23:54:43 +05:30
# We need re-rerun the setup when code reloads in development
config.reloader.to_prepare do
if Gitlab.dev_or_test_env?
Gitlab::Database::LoadBalancing.base_models.each do |model|
Gitlab::Database::LoadBalancing::Setup.new(model).setup
end
end
end
2021-11-18 22:05:49 +05:30
end
2021-10-27 15:23:28 +05:30
2021-11-18 22:05:49 +05:30
Gitlab::Database::LoadBalancing.base_models.each do |model|
# The load balancer needs to be configured immediately, and re-configured
# after forking. This ensures queries that run before forking use the load
# balancer, and queries running after a fork don't run into any errors when
# using dead database connections.
#
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/63485 for more
# information.
Gitlab::Database::LoadBalancing::Setup.new(model).setup
2019-09-30 21:07:59 +05:30
2021-11-18 22:05:49 +05:30
# Database queries may be run before we fork, so we must set up the load
# balancer as early as possible. When we do fork, we need to make sure all the
# hosts are disconnected.
Gitlab::Cluster::LifecycleEvents.on_before_fork do
# When forking, we don't want to wait until the connections aren't in use
# any more, as this could delay the boot cycle.
2021-12-11 22:18:48 +05:30
model.load_balancer.disconnect!(timeout: 0)
2021-09-04 01:27:46 +05:30
end
2019-09-30 21:07:59 +05:30
2021-11-18 22:05:49 +05:30
# Service discovery only needs to run in the worker processes, as the main one
# won't be running many (if any) database queries.
2021-09-04 01:27:46 +05:30
Gitlab::Cluster::LifecycleEvents.on_worker_start do
2021-11-18 22:05:49 +05:30
Gitlab::Database::LoadBalancing::Setup
.new(model, start_service_discovery: true)
.setup
2019-09-30 21:07:59 +05:30
end
end