class Sequel::ConnectionPool
The base connection pool class, which all other connection pools are based on. This class is not instantiated directly, but subclasses should at the very least implement the following API:
- initialize(Database,
Hash) -
Initialize using the passed
Sequel::Databaseobject and options hash. - hold(
Symbol, &block) -
Yield a connection object (obtained from calling the block passed to
initialize) to the current block. For sharded connection pools, theSymbolpassed is the shard/server to use. - disconnect(
Symbol) -
Disconnect the connection object. For sharded connection pools, the
Symbolpassed is the shard/server to use. - servers
-
An array of shard/server symbols for all shards/servers that this connection pool recognizes.
- size
-
an integer representing the total number of connections in the pool, or for the given shard/server if sharding is supported.
- max_size
-
an integer representing the maximum size of the connection pool, or the maximum size per shard/server if sharding is supported.
For sharded connection pools, the sharded API adds the following methods:
- add_servers(
Arrayof Symbols) -
start recognizing all shards/servers specified by the array of symbols.
- remove_servers(
Arrayof Symbols) -
no longer recognize all shards/servers specified by the array of symbols.
Constants
- OPTS
- POOL_CLASS_MAP
Attributes
The after_connect proc used for this pool. This is called with each new connection made, and is usually used to set custom per-connection settings. Deprecated.
An array of sql strings to execute on each new connection. Deprecated.
The Sequel::Database object tied to this connection pool.
Public Class Methods
Source
# File lib/sequel/connection_pool.rb 113 def initialize(db, opts=OPTS) # SEQUEL6: Remove second argument, always use db.opts 114 @db = db 115 @use_old_connect_api = false # SEQUEL6: Remove 116 @after_connect = opts[:after_connect] # SEQUEL6: Remove 117 @connect_sqls = opts[:connect_sqls] # SEQUEL6: Remove 118 @error_classes = db.send(:database_error_classes).dup.freeze 119 end
Instantiates a connection pool with the given Database and options.
Public Instance Methods
Source
# File lib/sequel/connection_pool.rb 94 def after_connect=(v) # SEQUEL6: Remove 95 @use_old_connect_api = true 96 @after_connect = v 97 end
Override the after_connect proc for the connection pool. Deprecated. Disables support for shard-specific :after_connect and :connect_sqls if used.
Source
# File lib/sequel/connection_pool.rb 104 def connect_sqls=(v) # SEQUEL6: Remove 105 @use_old_connect_api = true 106 @connect_sqls = v 107 end
Override the connect_sqls for the connection pool. Deprecated. Disables support for shard-specific :after_connect and :connect_sqls if used.
Source
# File lib/sequel/connection_pool.rb 122 def servers 123 [:default] 124 end
An array of symbols for all shards/servers, which is a single :default by default.
Private Instance Methods
Source
# File lib/sequel/connection_pool.rb 136 def disconnect_acquired_connection(conn, *) 137 disconnect_connection(conn) 138 end
Only for use by extension that need to disconnect a connection inside acquire. Takes the connection and any arguments accepted by acquire.
Source
# File lib/sequel/connection_pool.rb 130 def disconnect_connection(conn) 131 db.disconnect_connection(conn) 132 end
Remove the connection from the pool. For threaded connections, this should be called without the mutex, because the disconnection may block.
Source
# File lib/sequel/connection_pool.rb 141 def disconnect_error?(exception) 142 exception.is_a?(Sequel::DatabaseDisconnectError) || db.send(:disconnect_error?, exception, OPTS) 143 end
Whether the given exception is a disconnect exception.
Source
# File lib/sequel/connection_pool.rb 147 def make_new(server) 148 begin 149 if @use_old_connect_api 150 # SEQUEL6: Remove block 151 conn = @db.connect(server) 152 153 if ac = @after_connect 154 if ac.arity == 2 155 ac.call(conn, server) 156 else 157 ac.call(conn) 158 end 159 end 160 161 if cs = @connect_sqls 162 cs.each do |sql| 163 db.send(:log_connection_execute, conn, sql) 164 end 165 end 166 167 conn 168 else 169 @db.new_connection(server) 170 end 171 rescue Exception=>exception 172 raise Sequel.convert_exception_class(exception, Sequel::DatabaseConnectionError) 173 end || raise(Sequel::DatabaseConnectionError, "Connection parameters not valid") 174 end
Return a new connection by calling the connection proc with the given server name, and checking for connection errors.