Do not run service discovery for DB load balancing for rake tasks
What does this MR do and why?
Do not run service discovery for DB load balancing for rake tasks
It turns out we don't want to setup DB load balancing for rake task. This is implemented correctly for the host based load balancing code, but not implemented correctly for the service discovery based load balancing code.
Make this two paths consistent with each other.
Related issue: #346765 (closed)
Screenshots or screen recordings
These are strongly recommended to assist reviewers and reduce the time to merge your change.
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
-
Setup
config/database.yml
to add the following lines (reference https://docs.gitlab.com/ee/administration/postgresql/database_load_balancing.html#service-discovery). You can use the value s below as isload_balancing: discover: nameserver: 'localhost' record: something.localhost
-
Apply the following patch. It is necessary to mimic that we in a Rake task, and that we have a response from the service discovery DNS query. (Or you can setup a real DNS server, and run a rake task)
diff --git a/lib/gitlab/database/load_balancing/configuration.rb b/lib/gitlab/database/load_balancing/configuration.rb
index da313361073..3c475a4a891 100644
--- a/lib/gitlab/database/load_balancing/configuration.rb
+++ b/lib/gitlab/database/load_balancing/configuration.rb
@@ -102,9 +102,10 @@ def pool_size
# This is disabled for Rake tasks to ensure e.g. database migrations
# always produce consistent results.
def load_balancing_enabled?
- return false if Gitlab::Runtime.rake?
+ return false
+ #return false if Gitlab::Runtime.rake?
- hosts.any? || service_discovery_enabled?
+ #hosts.any? || service_discovery_enabled?
end
def service_discovery_enabled?
diff --git a/lib/gitlab/database/load_balancing/service_discovery.rb b/lib/gitlab/database/load_balancing/service_discovery.rb
index dfd4892371c..23442b74fe3 100644
--- a/lib/gitlab/database/load_balancing/service_discovery.rb
+++ b/lib/gitlab/database/load_balancing/service_discovery.rb
@@ -109,7 +109,8 @@ def perform_service_discovery
# The return value is the amount of time (in seconds) to wait before
# checking the DNS record for any changes.
def refresh_if_necessary
- interval, from_dns = addresses_from_dns
+ #interval, from_dns = addresses_from_dns
+ interval, from_dns = 10, [Address.new('127.0.0.1', 8022)]
current = addresses_from_load_balancer
- Run a rails console. For
master
, you will see the following errors inlog/exceptions_json.log
. For this branch, there will be no errors
{"severity":"ERROR","time":"2021-12-01T08:04:03.711Z","correlation_id":null,"exception.class":"NoMethodError","exception.message":"undefined method `host' for #\u003cGitlab::Database::LoadBalancing::PrimaryHost:0x00007f9d89e5b978\u003e","exception.backtrace":[],"user.username":null,"tags.program":"console","tags.locale":"en","tags.feature_category":null,"tags.correlation_id":null}
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.