activerecord 7.1.5.1 → 8.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +369 -2484
- data/README.rdoc +15 -15
- data/examples/performance.rb +2 -2
- data/lib/active_record/association_relation.rb +2 -1
- data/lib/active_record/associations/alias_tracker.rb +31 -23
- data/lib/active_record/associations/association.rb +43 -12
- data/lib/active_record/associations/belongs_to_association.rb +21 -8
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +3 -2
- data/lib/active_record/associations/builder/association.rb +7 -6
- data/lib/active_record/associations/builder/belongs_to.rb +1 -0
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +2 -2
- data/lib/active_record/associations/builder/has_many.rb +3 -4
- data/lib/active_record/associations/builder/has_one.rb +3 -4
- data/lib/active_record/associations/collection_association.rb +17 -9
- data/lib/active_record/associations/collection_proxy.rb +14 -1
- data/lib/active_record/associations/disable_joins_association_scope.rb +1 -1
- data/lib/active_record/associations/errors.rb +265 -0
- data/lib/active_record/associations/has_many_association.rb +1 -1
- data/lib/active_record/associations/has_many_through_association.rb +10 -3
- data/lib/active_record/associations/join_dependency/join_association.rb +1 -1
- data/lib/active_record/associations/nested_error.rb +47 -0
- data/lib/active_record/associations/preloader/association.rb +4 -3
- data/lib/active_record/associations/preloader/branch.rb +7 -1
- data/lib/active_record/associations/preloader/through_association.rb +1 -3
- data/lib/active_record/associations/singular_association.rb +14 -3
- data/lib/active_record/associations/through_association.rb +1 -1
- data/lib/active_record/associations.rb +92 -295
- data/lib/active_record/asynchronous_queries_tracker.rb +28 -24
- data/lib/active_record/attribute_assignment.rb +0 -2
- data/lib/active_record/attribute_methods/composite_primary_key.rb +84 -0
- data/lib/active_record/attribute_methods/primary_key.rb +25 -61
- data/lib/active_record/attribute_methods/read.rb +1 -13
- data/lib/active_record/attribute_methods/serialization.rb +4 -24
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +9 -18
- data/lib/active_record/attribute_methods.rb +71 -75
- data/lib/active_record/attributes.rb +63 -49
- data/lib/active_record/autosave_association.rb +92 -57
- data/lib/active_record/base.rb +2 -3
- data/lib/active_record/callbacks.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +48 -122
- data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +0 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +286 -77
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +119 -55
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +197 -76
- data/lib/active_record/connection_adapters/abstract/quoting.rb +66 -92
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +4 -5
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +12 -3
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +48 -12
- data/lib/active_record/connection_adapters/abstract/transaction.rb +140 -67
- data/lib/active_record/connection_adapters/abstract_adapter.rb +85 -90
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +71 -52
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +9 -1
- data/lib/active_record/connection_adapters/mysql/quoting.rb +50 -57
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +2 -8
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +56 -45
- data/lib/active_record/connection_adapters/mysql2/database_statements.rb +92 -101
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +13 -31
- data/lib/active_record/connection_adapters/pool_config.rb +14 -13
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +86 -41
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +10 -0
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +14 -4
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +58 -58
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +2 -4
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +1 -11
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +36 -20
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +3 -2
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +75 -28
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +73 -113
- data/lib/active_record/connection_adapters/schema_cache.rb +124 -131
- data/lib/active_record/connection_adapters/sqlite3/column.rb +14 -1
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +81 -97
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +57 -46
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +16 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +13 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +29 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +35 -3
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +183 -87
- data/lib/active_record/connection_adapters/statement_pool.rb +4 -2
- data/lib/active_record/connection_adapters/trilogy/database_statements.rb +39 -69
- data/lib/active_record/connection_adapters/trilogy_adapter.rb +19 -65
- data/lib/active_record/connection_adapters.rb +65 -0
- data/lib/active_record/connection_handling.rb +74 -37
- data/lib/active_record/core.rb +132 -51
- data/lib/active_record/counter_cache.rb +19 -10
- data/lib/active_record/database_configurations/connection_url_resolver.rb +9 -2
- data/lib/active_record/database_configurations/database_config.rb +23 -4
- data/lib/active_record/database_configurations/hash_config.rb +46 -34
- data/lib/active_record/database_configurations/url_config.rb +20 -1
- data/lib/active_record/database_configurations.rb +1 -1
- data/lib/active_record/delegated_type.rb +41 -17
- data/lib/active_record/dynamic_matchers.rb +2 -2
- data/lib/active_record/encryption/config.rb +3 -1
- data/lib/active_record/encryption/encryptable_record.rb +7 -7
- data/lib/active_record/encryption/encrypted_attribute_type.rb +33 -4
- data/lib/active_record/encryption/encryptor.rb +28 -6
- data/lib/active_record/encryption/extended_deterministic_queries.rb +4 -2
- data/lib/active_record/encryption/key_provider.rb +1 -1
- data/lib/active_record/encryption/message_pack_message_serializer.rb +76 -0
- data/lib/active_record/encryption/message_serializer.rb +4 -0
- data/lib/active_record/encryption/null_encryptor.rb +4 -0
- data/lib/active_record/encryption/read_only_null_encryptor.rb +4 -0
- data/lib/active_record/encryption/scheme.rb +8 -1
- data/lib/active_record/enum.rb +20 -16
- data/lib/active_record/errors.rb +54 -20
- data/lib/active_record/explain.rb +13 -24
- data/lib/active_record/fixtures.rb +37 -33
- data/lib/active_record/future_result.rb +21 -13
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/inheritance.rb +4 -2
- data/lib/active_record/insert_all.rb +19 -16
- data/lib/active_record/integration.rb +4 -1
- data/lib/active_record/internal_metadata.rb +48 -34
- data/lib/active_record/locking/optimistic.rb +8 -7
- data/lib/active_record/log_subscriber.rb +5 -32
- data/lib/active_record/message_pack.rb +1 -1
- data/lib/active_record/migration/command_recorder.rb +33 -14
- data/lib/active_record/migration/compatibility.rb +8 -3
- data/lib/active_record/migration/default_strategy.rb +4 -5
- data/lib/active_record/migration/pending_migration_connection.rb +2 -2
- data/lib/active_record/migration.rb +104 -98
- data/lib/active_record/model_schema.rb +32 -70
- data/lib/active_record/nested_attributes.rb +15 -9
- data/lib/active_record/normalization.rb +3 -7
- data/lib/active_record/persistence.rb +127 -451
- data/lib/active_record/query_cache.rb +19 -8
- data/lib/active_record/query_logs.rb +104 -37
- data/lib/active_record/query_logs_formatter.rb +17 -28
- data/lib/active_record/querying.rb +24 -12
- data/lib/active_record/railtie.rb +26 -68
- data/lib/active_record/railties/controller_runtime.rb +13 -4
- data/lib/active_record/railties/databases.rake +43 -61
- data/lib/active_record/reflection.rb +112 -53
- data/lib/active_record/relation/batches/batch_enumerator.rb +19 -5
- data/lib/active_record/relation/batches.rb +138 -72
- data/lib/active_record/relation/calculations.rb +122 -82
- data/lib/active_record/relation/delegation.rb +30 -22
- data/lib/active_record/relation/finder_methods.rb +32 -18
- data/lib/active_record/relation/merger.rb +12 -14
- data/lib/active_record/relation/predicate_builder/array_handler.rb +2 -2
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +10 -2
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +1 -1
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +4 -3
- data/lib/active_record/relation/predicate_builder.rb +16 -3
- data/lib/active_record/relation/query_attribute.rb +1 -1
- data/lib/active_record/relation/query_methods.rb +317 -101
- data/lib/active_record/relation/spawn_methods.rb +3 -19
- data/lib/active_record/relation/where_clause.rb +7 -19
- data/lib/active_record/relation.rb +561 -119
- data/lib/active_record/result.rb +95 -46
- data/lib/active_record/runtime_registry.rb +39 -0
- data/lib/active_record/sanitization.rb +31 -25
- data/lib/active_record/schema.rb +8 -6
- data/lib/active_record/schema_dumper.rb +53 -20
- data/lib/active_record/schema_migration.rb +31 -14
- data/lib/active_record/scoping/named.rb +6 -2
- data/lib/active_record/signed_id.rb +24 -4
- data/lib/active_record/statement_cache.rb +19 -19
- data/lib/active_record/store.rb +7 -3
- data/lib/active_record/table_metadata.rb +2 -13
- data/lib/active_record/tasks/database_tasks.rb +87 -58
- data/lib/active_record/tasks/mysql_database_tasks.rb +1 -3
- data/lib/active_record/tasks/postgresql_database_tasks.rb +1 -1
- data/lib/active_record/tasks/sqlite_database_tasks.rb +4 -3
- data/lib/active_record/test_fixtures.rb +98 -89
- data/lib/active_record/testing/query_assertions.rb +121 -0
- data/lib/active_record/timestamp.rb +2 -2
- data/lib/active_record/token_for.rb +22 -12
- data/lib/active_record/touch_later.rb +1 -1
- data/lib/active_record/transaction.rb +132 -0
- data/lib/active_record/transactions.rb +72 -17
- data/lib/active_record/translation.rb +0 -2
- data/lib/active_record/type/serialized.rb +1 -3
- data/lib/active_record/type_caster/connection.rb +4 -4
- data/lib/active_record/validations/associated.rb +9 -3
- data/lib/active_record/validations/uniqueness.rb +23 -18
- data/lib/active_record/validations.rb +4 -1
- data/lib/active_record.rb +138 -57
- data/lib/arel/alias_predication.rb +1 -1
- data/lib/arel/collectors/bind.rb +4 -2
- data/lib/arel/collectors/composite.rb +7 -0
- data/lib/arel/collectors/sql_string.rb +2 -2
- data/lib/arel/collectors/substitute_binds.rb +3 -3
- data/lib/arel/nodes/binary.rb +1 -7
- data/lib/arel/nodes/bound_sql_literal.rb +9 -5
- data/lib/arel/nodes/{and.rb → nary.rb} +5 -2
- data/lib/arel/nodes/node.rb +5 -4
- data/lib/arel/nodes/sql_literal.rb +8 -1
- data/lib/arel/nodes.rb +2 -2
- data/lib/arel/predications.rb +1 -1
- data/lib/arel/select_manager.rb +1 -1
- data/lib/arel/table.rb +3 -7
- data/lib/arel/tree_manager.rb +3 -2
- data/lib/arel/update_manager.rb +2 -1
- data/lib/arel/visitors/dot.rb +1 -0
- data/lib/arel/visitors/mysql.rb +9 -4
- data/lib/arel/visitors/postgresql.rb +1 -12
- data/lib/arel/visitors/sqlite.rb +25 -0
- data/lib/arel/visitors/to_sql.rb +29 -16
- data/lib/arel.rb +7 -3
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +4 -1
- metadata +18 -16
- data/lib/active_record/relation/record_fetch_warning.rb +0 -49
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "thread"
|
4
3
|
require "concurrent/map"
|
5
4
|
|
6
5
|
module ActiveRecord
|
@@ -55,31 +54,28 @@ module ActiveRecord
|
|
55
54
|
# about the model. The model needs to pass a connection specification name to the handler,
|
56
55
|
# in order to look up the correct connection pool.
|
57
56
|
class ConnectionHandler
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
class StringConnectionName # :nodoc:
|
62
|
-
attr_reader :name
|
63
|
-
|
64
|
-
def initialize(name)
|
57
|
+
class ConnectionDescriptor # :nodoc:
|
58
|
+
def initialize(name, primary = false)
|
65
59
|
@name = name
|
60
|
+
@primary = primary
|
61
|
+
end
|
62
|
+
|
63
|
+
def name
|
64
|
+
primary_class? ? "ActiveRecord::Base" : @name
|
66
65
|
end
|
67
66
|
|
68
67
|
def primary_class?
|
69
|
-
|
68
|
+
@primary
|
70
69
|
end
|
71
70
|
|
72
71
|
def current_preventing_writes
|
73
|
-
|
72
|
+
ActiveRecord::Base.preventing_writes?(@name)
|
74
73
|
end
|
75
74
|
end
|
76
75
|
|
77
76
|
def initialize
|
78
77
|
# These caches are keyed by pool_config.connection_name (PoolConfig#connection_name).
|
79
78
|
@connection_name_to_pool_manager = Concurrent::Map.new(initial_capacity: 2)
|
80
|
-
|
81
|
-
# Backup finalizer: if the forked child skipped Kernel#fork the early discard has not occurred
|
82
|
-
ObjectSpace.define_finalizer self, FINALIZER
|
83
79
|
end
|
84
80
|
|
85
81
|
def prevent_writes # :nodoc:
|
@@ -94,22 +90,10 @@ module ActiveRecord
|
|
94
90
|
connection_name_to_pool_manager.keys
|
95
91
|
end
|
96
92
|
|
97
|
-
|
98
|
-
ActiveRecord.deprecator.warn(<<-MSG.squish)
|
99
|
-
The `all_connection_pools` method is deprecated in favor of `connection_pool_list`.
|
100
|
-
Call `connection_pool_list(:all)` to get the same behavior as `all_connection_pools`.
|
101
|
-
MSG
|
102
|
-
connection_name_to_pool_manager.values.flat_map { |m| m.pool_configs.map(&:pool) }
|
103
|
-
end
|
104
|
-
|
105
|
-
# Returns the pools for a connection handler and given role. If +:all+ is passed,
|
93
|
+
# Returns the pools for a connection handler and given role. If +:all+ is passed,
|
106
94
|
# all pools belonging to the connection handler will be returned.
|
107
95
|
def connection_pool_list(role = nil)
|
108
|
-
if role.nil?
|
109
|
-
deprecation_for_pool_handling(__method__)
|
110
|
-
role = ActiveRecord::Base.current_role
|
111
|
-
connection_name_to_pool_manager.values.flat_map { |m| m.pool_configs(role).map(&:pool) }
|
112
|
-
elsif role == :all
|
96
|
+
if role.nil? || role == :all
|
113
97
|
connection_name_to_pool_manager.values.flat_map { |m| m.pool_configs.map(&:pool) }
|
114
98
|
else
|
115
99
|
connection_name_to_pool_manager.values.flat_map { |m| m.pool_configs(role).map(&:pool) }
|
@@ -134,7 +118,7 @@ module ActiveRecord
|
|
134
118
|
pool_config = resolve_pool_config(config, owner_name, role, shard)
|
135
119
|
db_config = pool_config.db_config
|
136
120
|
|
137
|
-
pool_manager = set_pool_manager(pool_config.
|
121
|
+
pool_manager = set_pool_manager(pool_config.connection_descriptor)
|
138
122
|
|
139
123
|
# If there is an existing pool with the same values as the pool_config
|
140
124
|
# don't remove the connection. Connections should only be removed if we are
|
@@ -146,8 +130,8 @@ module ActiveRecord
|
|
146
130
|
# Update the pool_config's connection class if it differs. This is used
|
147
131
|
# for ensuring that ActiveRecord::Base and the primary_abstract_class use
|
148
132
|
# the same pool. Without this granular swapping will not work correctly.
|
149
|
-
if owner_name.primary_class? && (existing_pool_config.
|
150
|
-
existing_pool_config.
|
133
|
+
if owner_name.primary_class? && (existing_pool_config.connection_descriptor != owner_name)
|
134
|
+
existing_pool_config.connection_descriptor = owner_name
|
151
135
|
end
|
152
136
|
|
153
137
|
existing_pool_config.pool
|
@@ -156,7 +140,7 @@ module ActiveRecord
|
|
156
140
|
pool_manager.set_pool_config(role, shard, pool_config)
|
157
141
|
|
158
142
|
payload = {
|
159
|
-
connection_name: pool_config.
|
143
|
+
connection_name: pool_config.connection_descriptor.name,
|
160
144
|
role: role,
|
161
145
|
shard: shard,
|
162
146
|
config: db_config.configuration_hash
|
@@ -171,11 +155,6 @@ module ActiveRecord
|
|
171
155
|
# Returns true if there are any active connections among the connection
|
172
156
|
# pools that the ConnectionHandler is managing.
|
173
157
|
def active_connections?(role = nil)
|
174
|
-
if role.nil?
|
175
|
-
deprecation_for_pool_handling(__method__)
|
176
|
-
role = ActiveRecord::Base.current_role
|
177
|
-
end
|
178
|
-
|
179
158
|
each_connection_pool(role).any?(&:active_connection?)
|
180
159
|
end
|
181
160
|
|
@@ -183,32 +162,20 @@ module ActiveRecord
|
|
183
162
|
# and also returns connections to the pool cached by threads that are no
|
184
163
|
# longer alive.
|
185
164
|
def clear_active_connections!(role = nil)
|
186
|
-
|
187
|
-
|
188
|
-
|
165
|
+
each_connection_pool(role).each do |pool|
|
166
|
+
pool.release_connection
|
167
|
+
pool.disable_query_cache!
|
189
168
|
end
|
190
|
-
|
191
|
-
each_connection_pool(role).each(&:release_connection)
|
192
169
|
end
|
193
170
|
|
194
171
|
# Clears the cache which maps classes.
|
195
172
|
#
|
196
173
|
# See ConnectionPool#clear_reloadable_connections! for details.
|
197
174
|
def clear_reloadable_connections!(role = nil)
|
198
|
-
if role.nil?
|
199
|
-
deprecation_for_pool_handling(__method__)
|
200
|
-
role = ActiveRecord::Base.current_role
|
201
|
-
end
|
202
|
-
|
203
175
|
each_connection_pool(role).each(&:clear_reloadable_connections!)
|
204
176
|
end
|
205
177
|
|
206
178
|
def clear_all_connections!(role = nil)
|
207
|
-
if role.nil?
|
208
|
-
deprecation_for_pool_handling(__method__)
|
209
|
-
role = ActiveRecord::Base.current_role
|
210
|
-
end
|
211
|
-
|
212
179
|
each_connection_pool(role).each(&:disconnect!)
|
213
180
|
end
|
214
181
|
|
@@ -216,11 +183,6 @@ module ActiveRecord
|
|
216
183
|
#
|
217
184
|
# See ConnectionPool#flush! for details.
|
218
185
|
def flush_idle_connections!(role = nil)
|
219
|
-
if role.nil?
|
220
|
-
deprecation_for_pool_handling(__method__)
|
221
|
-
role = ActiveRecord::Base.current_role
|
222
|
-
end
|
223
|
-
|
224
186
|
each_connection_pool(role).each(&:flush!)
|
225
187
|
end
|
226
188
|
|
@@ -229,21 +191,8 @@ module ActiveRecord
|
|
229
191
|
# opened and set as the active connection for the class it was defined
|
230
192
|
# for (not necessarily the current class).
|
231
193
|
def retrieve_connection(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard) # :nodoc:
|
232
|
-
pool = retrieve_connection_pool(connection_name, role: role, shard: shard)
|
233
|
-
|
234
|
-
unless pool
|
235
|
-
if shard != ActiveRecord::Base.default_shard
|
236
|
-
message = "No connection pool for '#{connection_name}' found for the '#{shard}' shard."
|
237
|
-
elsif role != ActiveRecord::Base.default_role
|
238
|
-
message = "No connection pool for '#{connection_name}' found for the '#{role}' role."
|
239
|
-
else
|
240
|
-
message = "No connection pool for '#{connection_name}' found."
|
241
|
-
end
|
242
|
-
|
243
|
-
raise ConnectionNotEstablished, message
|
244
|
-
end
|
245
|
-
|
246
|
-
pool.connection
|
194
|
+
pool = retrieve_connection_pool(connection_name, role: role, shard: shard, strict: true)
|
195
|
+
pool.lease_connection
|
247
196
|
end
|
248
197
|
|
249
198
|
# Returns true if a connection that's accessible to this class has
|
@@ -262,9 +211,29 @@ module ActiveRecord
|
|
262
211
|
# Retrieving the connection pool happens a lot, so we cache it in @connection_name_to_pool_manager.
|
263
212
|
# This makes retrieving the connection pool O(1) once the process is warm.
|
264
213
|
# When a connection is established or removed, we invalidate the cache.
|
265
|
-
def retrieve_connection_pool(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard)
|
266
|
-
|
267
|
-
|
214
|
+
def retrieve_connection_pool(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard, strict: false)
|
215
|
+
pool_manager = get_pool_manager(connection_name)
|
216
|
+
pool = pool_manager&.get_pool_config(role, shard)&.pool
|
217
|
+
|
218
|
+
if strict && !pool
|
219
|
+
selector = [
|
220
|
+
("'#{shard}' shard" unless shard == ActiveRecord::Base.default_shard),
|
221
|
+
("'#{role}' role" unless role == ActiveRecord::Base.default_role),
|
222
|
+
].compact.join(" and ")
|
223
|
+
|
224
|
+
selector = [
|
225
|
+
(connection_name unless connection_name == "ActiveRecord::Base"),
|
226
|
+
selector.presence,
|
227
|
+
].compact.join(" with ")
|
228
|
+
|
229
|
+
selector = " for #{selector}" if selector.present?
|
230
|
+
|
231
|
+
message = "No database connection defined#{selector}."
|
232
|
+
|
233
|
+
raise ConnectionNotDefined.new(message, connection_name: connection_name, shard: shard, role: role)
|
234
|
+
end
|
235
|
+
|
236
|
+
pool
|
268
237
|
end
|
269
238
|
|
270
239
|
private
|
@@ -276,31 +245,14 @@ module ActiveRecord
|
|
276
245
|
end
|
277
246
|
|
278
247
|
# Get the existing pool manager or initialize and assign a new one.
|
279
|
-
def set_pool_manager(
|
280
|
-
connection_name_to_pool_manager[
|
248
|
+
def set_pool_manager(connection_descriptor)
|
249
|
+
connection_name_to_pool_manager[connection_descriptor.name] ||= PoolManager.new
|
281
250
|
end
|
282
251
|
|
283
252
|
def pool_managers
|
284
253
|
connection_name_to_pool_manager.values
|
285
254
|
end
|
286
255
|
|
287
|
-
def deprecation_for_pool_handling(method)
|
288
|
-
roles = []
|
289
|
-
pool_managers.each do |pool_manager|
|
290
|
-
roles << pool_manager.role_names
|
291
|
-
end
|
292
|
-
|
293
|
-
if roles.flatten.uniq.count > 1
|
294
|
-
ActiveRecord.deprecator.warn(<<-MSG.squish)
|
295
|
-
`#{method}` currently only applies to connection pools in the current
|
296
|
-
role (`#{ActiveRecord::Base.current_role}`). In Rails 7.2, this method
|
297
|
-
will apply to all known pools, regardless of role. To affect only those
|
298
|
-
connections belonging to a specific role, pass the role name as an
|
299
|
-
argument. To switch to the new behavior, pass `:all` as the role name.
|
300
|
-
MSG
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
256
|
def disconnect_pool_from_pool_manager(pool_manager, role, shard)
|
305
257
|
pool_config = pool_manager.remove_pool_config(role, shard)
|
306
258
|
|
@@ -322,42 +274,16 @@ module ActiveRecord
|
|
322
274
|
#
|
323
275
|
def resolve_pool_config(config, connection_name, role, shard)
|
324
276
|
db_config = Base.configurations.resolve(config)
|
325
|
-
|
277
|
+
db_config.validate!
|
326
278
|
raise(AdapterNotSpecified, "database configuration does not specify adapter") unless db_config.adapter
|
327
|
-
|
328
|
-
# Require the adapter itself and give useful feedback about
|
329
|
-
# 1. Missing adapter gems and
|
330
|
-
# 2. Adapter gems' missing dependencies.
|
331
|
-
path_to_adapter = "active_record/connection_adapters/#{db_config.adapter}_adapter"
|
332
|
-
begin
|
333
|
-
require path_to_adapter
|
334
|
-
rescue LoadError => e
|
335
|
-
# We couldn't require the adapter itself. Raise an exception that
|
336
|
-
# points out config typos and missing gems.
|
337
|
-
if e.path == path_to_adapter
|
338
|
-
# We can assume that a non-builtin adapter was specified, so it's
|
339
|
-
# either misspelled or missing from Gemfile.
|
340
|
-
raise LoadError, "Could not load the '#{db_config.adapter}' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile.", e.backtrace
|
341
|
-
|
342
|
-
# Bubbled up from the adapter require. Prefix the exception message
|
343
|
-
# with some guidance about how to address it and reraise.
|
344
|
-
else
|
345
|
-
raise LoadError, "Error loading the '#{db_config.adapter}' Active Record adapter. Missing a gem it depends on? #{e.message}", e.backtrace
|
346
|
-
end
|
347
|
-
end
|
348
|
-
|
349
|
-
unless ActiveRecord::Base.respond_to?(db_config.adapter_method)
|
350
|
-
raise AdapterNotFound, "database configuration specifies nonexistent #{db_config.adapter} adapter"
|
351
|
-
end
|
352
|
-
|
353
279
|
ConnectionAdapters::PoolConfig.new(connection_name, db_config, role, shard)
|
354
280
|
end
|
355
281
|
|
356
282
|
def determine_owner_name(owner_name, config)
|
357
283
|
if owner_name.is_a?(String) || owner_name.is_a?(Symbol)
|
358
|
-
|
284
|
+
ConnectionDescriptor.new(owner_name.to_s)
|
359
285
|
elsif config.is_a?(Symbol)
|
360
|
-
|
286
|
+
ConnectionDescriptor.new(config.to_s)
|
361
287
|
else
|
362
288
|
owner_name
|
363
289
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "thread"
|
4
3
|
require "weakref"
|
5
4
|
|
6
5
|
module ActiveRecord
|
@@ -43,6 +42,7 @@ module ActiveRecord
|
|
43
42
|
# Advise multi-threaded app servers to ignore this thread for
|
44
43
|
# the purposes of fork safety warnings
|
45
44
|
Thread.current.thread_variable_set(:fork_safe, true)
|
45
|
+
Thread.current.name = "AR Pool Reaper"
|
46
46
|
running = true
|
47
47
|
while running
|
48
48
|
sleep t
|