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 +4 -4
- data/lib/apartment/migrator.rb +30 -1
- data/lib/apartment/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d24210e257a6f61365a496b60f54762e4b0e9d5ef6f652d77891455fba01d6a4
|
|
4
|
+
data.tar.gz: dd1eb795e6ca4c9bc2b22377b2feb7fd8bd9fc66efdd3d1eaaeab891bd4fa7d3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2397d625268ff6c241eb7886834f99383e650a9613048d0c8d99594083d7cb450e3b328279f56d7c14b3babf70e9ca03069b5c5c507f3a3f06591a429c8283e8
|
|
7
|
+
data.tar.gz: 57ef4cf17beff1ee06a8abdaff9303b114be190c962f829de2465e766b1235664718e1bb534c8bee715657dbea45512c116f1467d20a287f7ea7c55e164822aa
|
data/lib/apartment/migrator.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
data/lib/apartment/version.rb
CHANGED