lib/gitlab/database/load_balancing/load_balancer.rb
def read(&block)
          conflict_retried = 0

          while host
            begin
              return yield host.connection
            rescue => error
              if serialization_failure?(error)
                # This error can occur when a query conflicts. See
                # https://www.postgresql.org/docs/current/static/hot-standby.html#HOT-STANDBY-CONFLICT
                # for more information.
                #
                # In this event we'll cycle through the secondaries at most 3
                # times before using the primary instead.
                if conflict_retried < @host_list.length * 3
                  conflict_retried += 1
                  release_host
                else
                  break
                end
              elsif connection_error?(error)
                host.offline!
                release_host
              else
                raise error
              end
            end
          end

          LoadBalancing
            .log(:warn, 'No secondaries were available, using primary instead')

          read_write(&block)
        end
# Yields a connection that can be used for reads.
#
# If no secondaries were available this method will use the primary
# instead.
Yields a connection that can be used for reads.
If no secondaries were available this method will use the primary
instead.
Yields a connection that can be used for reads . If no secondaries were available this method will use the primary instead .
def read(&block)
          conflict_retried = 0
          while host
            begin
              return yield host.connection
            rescue => error
              if serialization_failure?(error)
                 In this event we'll cycle through the secondaries at most 3
                 times before using the primary instead.
                if conflict_retried < @host_list.length * 3
                  conflict_retried += 1
                  release_host
                else
                  break
                end
              elsif connection_error?(error)
                host.offline!
                release_host
              else
                raise error
              end
            end
          end
          LoadBalancing
            .log(:warn, 'No secondaries were available, using primary instead')
          read_write(&block)
        end
def read ( & block ) conflict_retried = 0 while host begin return yield host . connection rescue => error if serialization_failure? ( error ) if conflict_retried < @host_list . length * 3 conflict_retried += 1 release_host else break end elsif connection_error? ( error ) host . offline! release_host else raise error end end end LoadBalancing . log ( :warn , 'No secondaries were available, using primary instead' ) read_write ( & block ) end
Yields a connection that can be used for reads.
Yields a connection that can be used for reads .
# This error can occur when a query conflicts. See # https://www.postgresql.org/docs/current/static/hot-standby.html#HOT-STANDBY-CONFLICT # for more information. # # In this event we'll cycle through the secondaries at most 3 # times before using the primary instead.
block