Skip to content

Prepare the database load balancer for always being enabled

Yorick Peterse requested to merge prepare-lb-for-always-enabled into master

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

Edited by Yorick Peterse

Merge request reports

Loading