Prepare the database load balancer for always being enabled
What does this MR do?
This commits prepares the database load balancing code for always being enabled, even when no replicas are configured.
To achieve this, the load balancer now supports the "primary_only" option. When enabled, the list of replicas is ignored (which is empty anyway), and a fake replica is used instead. This fake replica simply reuses the primary connection of the load balancer it belongs to. We chose this approach as there's simply too much code that assumes at least one replica is present when load balancing is enabled.
In addition, we make various changes to ConnectionProxy to allow us to always enable the use of this class. As an example, some tests use code like this:
ActiveRecord::Schema.define do
create_table :foo do
...
end
end
Internally Rails ends up performing some respond_to?
checks to expose
certain methods (or not). Without defining a custom
respond_to_missing?
, these checks return false
and thus the method
isn't available.
We've also had to change a few more methods in the ConnectionProxy
object to handle forwarding trailing hashes. In the previous setup
certain tests would still trigger deprecation warnings. This can be
avoided by using ...
everywhere, and getting rid of the sticky:
keyword argument.
This MR is extracted from !68042 (merged), and depends on the changed introduced in !68856 (merged).
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.