ros-apartment 4.0.0.alpha9 → 4.0.0.alpha10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b4b1a4532066ffd3ebfdfa8c43b0f0cdd4e304f31f9905af8a91550e71c44a6
4
- data.tar.gz: 75868c2063131bc20022d35142d87aff2c15f7c8b65b7fa3d8cbee43be4f11d1
3
+ metadata.gz: d24210e257a6f61365a496b60f54762e4b0e9d5ef6f652d77891455fba01d6a4
4
+ data.tar.gz: dd1eb795e6ca4c9bc2b22377b2feb7fd8bd9fc66efdd3d1eaaeab891bd4fa7d3
5
5
  SHA512:
6
- metadata.gz: 1f3c98442bf8ea826918440071a3a702615494d8761ef20f990135a10697650e05b72926f28a6cf1053b2aa969b67aee1b8c43249efe73ff58e8802c916f92a3
7
- data.tar.gz: f23fd1d357e9b5b598516960a0d480f22512b0c8b4481827bb137cc074589a73d4684e4879dc1b2355a12a108fe1b25eaf54eff283aa6c89557c823d91a3e13a
6
+ metadata.gz: 2397d625268ff6c241eb7886834f99383e650a9613048d0c8d99594083d7cb450e3b328279f56d7c14b3babf70e9ca03069b5c5c507f3a3f06591a429c8283e8
7
+ data.tar.gz: 57ef4cf17beff1ee06a8abdaff9303b114be190c962f829de2465e766b1235664718e1bb534c8bee715657dbea45512c116f1467d20a287f7ea7c55e164822aa
@@ -146,10 +146,19 @@ module Apartment
146
146
  def migrate_tenant(tenant) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
147
147
  start = monotonic_now
148
148
  Apartment::Current.migrating = true
149
+ tenant_pool = nil
149
150
 
150
151
  with_migration_role do
151
152
  Apartment::Tenant.switch(tenant) do
152
- context = ActiveRecord::Base.connection_pool.migration_context
153
+ tenant_pool = ActiveRecord::Base.connection_pool
154
+ # Lease eagerly so the pool stays in_use? for the whole migration. This
155
+ # closes a capture->lease window: a parallel admission pass could
156
+ # otherwise evict the not-yet-leased pool, and the later lease_connection
157
+ # (in with_advisory_locks_disabled) would resolve a DIFFERENT replacement
158
+ # pool that this method's ensure would not release. It also guarantees the
159
+ # release below targets the pool that actually holds the lease.
160
+ tenant_pool.lease_connection
161
+ context = tenant_pool.migration_context
153
162
 
154
163
  unless @version || context.needs_migration?
155
164
  return Result.new(
@@ -186,6 +195,7 @@ module Apartment
186
195
  )
187
196
  ensure
188
197
  Apartment::Current.migrating = false
198
+ release_tenant_pool_connection(tenant, tenant_pool)
189
199
  end
190
200
 
191
201
  def run_sequential(tenants)
@@ -276,6 +286,25 @@ module Apartment
276
286
  # cannot re-escape the handler. Success-path instrumentation is left
277
287
  # un-isolated by design — only the failure path carries the hard no-raise
278
288
  # guarantee, and swallowing there would mask real subscriber bugs.
289
+ # Best-effort release of THIS worker's lease on the tenant pool, so the
290
+ # finished pool is no longer in_use? and becomes admission-evictable.
291
+ # Targeted (not handler-wide clear_active_connections!) so the shared
292
+ # sequential / migrate_one paths, which run on a caller-owned execution
293
+ # context, do not release a caller's other leases. A release failure must
294
+ # never mask the migration error or the returned Result, so it is swallowed
295
+ # and warned; the warn is nested-rescued because a broken $stderr raises
296
+ # IOError (a StandardError) — the same guard instrument_failure applies to
297
+ # its own warn. See docs/designs/v4-migrator-per-tenant-connection-release.md.
298
+ def release_tenant_pool_connection(tenant, pool)
299
+ pool&.release_connection
300
+ rescue StandardError => e
301
+ begin
302
+ warn "[Apartment::Migrator] connection release failed for #{tenant}: #{e.class}: #{e.message}"
303
+ rescue StandardError
304
+ nil
305
+ end
306
+ end
307
+
279
308
  def instrument_failure(tenant, error, duration)
280
309
  Instrumentation.instrument(:migrate_tenant_failed, tenant: tenant, error: error, duration: duration)
281
310
  rescue StandardError => e
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Apartment
4
- VERSION = '4.0.0.alpha9'
4
+ VERSION = '4.0.0.alpha10'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ros-apartment
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.alpha9
4
+ version: 4.0.0.alpha10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brunner