• Yorick Peterse's avatar
    Prepare the DB LB for always being enabled · e5c5dff0
    Yorick Peterse authored
    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.
    
    Changelog: changed
    e5c5dff0
load_balancing_spec.rb 25.3 KB