Sha256: 1aff1740230efe8d5941c40b2175e6ab09b6b3f6e6d7792e2af22d7075e06207

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

module ActiveRecord::Turntable
  module ActiveRecordExt
    module ConnectionHandlerExtension
      # @note Override not to establish_connection destroy existing connection pool proxy object
      def retrieve_connection_pool(spec_name)
        owner_to_pool.fetch(spec_name) do
          # Check if a connection was previously established in an ancestor process,
          # which may have been forked.
          if ancestor_pool = pool_from_any_process_for(spec_name)
            if ancestor_pool.is_a?(ActiveRecord::ConnectionAdapters::ConnectionPool)
              # A connection was established in an ancestor process that must have
              # subsequently forked. We can't reuse the connection, but we can copy
              # the specification and establish a new connection with it.
              spec = ancestor_pool.spec
              spec = spec.to_hash if spec.respond_to?(:to_hash)
              establish_connection(spec).tap do |pool|
                pool.schema_cache = ancestor_pool.schema_cache if ancestor_pool.schema_cache
              end
            else
              # Use same PoolProxy object
              owner_to_pool[spec_name] = ancestor_pool
            end
          else
            owner_to_pool[spec_name] = nil
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
activerecord-turntable-4.4.0 lib/active_record/turntable/active_record_ext/connection_handler_extension.rb
activerecord-turntable-4.3.0 lib/active_record/turntable/active_record_ext/connection_handler_extension.rb
activerecord-turntable-4.2.0 lib/active_record/turntable/active_record_ext/connection_handler_extension.rb
activerecord-turntable-4.1.0 lib/active_record/turntable/active_record_ext/connection_handler_extension.rb
activerecord-turntable-4.0.0 lib/active_record/turntable/active_record_ext/connection_handler_extension.rb
activerecord-turntable-3.1.0 lib/active_record/turntable/active_record_ext/connection_handler_extension.rb