switchman 1.12.11 → 1.12.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4812ac6ce707debd4e3f051bb5a252423f3151f8bd01132be6bf8d70b88d5d2f
4
- data.tar.gz: 193b31d26be336ba9441e6f4cd3702a57652ff6fc78454050aeee8c46795837c
3
+ metadata.gz: 809ad5808c045d1b4f9b2e7ac5084b0d10ced204c76d85b6649ec8a55384dd04
4
+ data.tar.gz: bba8310639966bc33a47ada04d46628a15ddf7a531e92c9ff9cecd9e1050a338
5
5
  SHA512:
6
- metadata.gz: 0ab5d97b97144a52ead634b53a17e60514eb653f82634b9a86b48676a13591b2511fc55f132d30634bf3abf42e3ccff17fe5ec96a27b61f5046a3fa22adc39a9
7
- data.tar.gz: 18e0c13e3b678c0007df134d6ed18404ba11f669b077ff1fdf912a9799a75db578c4605088f0e0c399840c65e56bf7b1e17aaae807c8b6a9403b96f68f537ca1
6
+ metadata.gz: 6ccf69f1a56258e1bd8b1c1dd915f50bb2b7fbff026168a08aadb5a71d7ede117bdebfaff48ea0ecd870295d0be810e1f425dd864dbd0ca2532c882b241d8973
7
+ data.tar.gz: 8b12e4e22e15e7cfbbc9e635f4b9d6c035ccc20d21afdbc347b9f1ddc6c906dc507362c936cb2de65a52f00de8d6bc96ae7d6e64f1ed5e9f5600a49ac42fc0a6
@@ -28,6 +28,8 @@ module Switchman
28
28
  after_save :clear_cache
29
29
  after_destroy :clear_cache
30
30
 
31
+ after_rollback :on_rollback
32
+
31
33
  scope :primary, -> { where(name: nil).order(:database_server_id, :id).distinct_on(:database_server_id) }
32
34
 
33
35
  class << self
@@ -676,6 +678,18 @@ module Switchman
676
678
  database_server.shard_name(self)
677
679
  end
678
680
 
681
+ def on_rollback
682
+ # make sure all connection pool proxies are referencing valid pools
683
+ ::ActiveRecord::Base.connection_handler.connection_pools.each do |pool|
684
+ next unless pool.is_a?(ConnectionPoolProxy)
685
+ ::Shackles.activated_environments.each do |env|
686
+ ::Shackles.activate(env) do
687
+ pool.current_pool
688
+ end
689
+ end
690
+ end
691
+ end
692
+
679
693
  def hashify_categories(categories)
680
694
  if categories.empty?
681
695
  { :primary => self }
@@ -4,11 +4,11 @@ module Switchman
4
4
  module ActiveRecord
5
5
  module ConnectionPool
6
6
  def shard
7
- Thread.current["#{object_id}_shard".to_sym] || Shard.default
7
+ Thread.current[tls_key] || Shard.default
8
8
  end
9
9
 
10
10
  def shard=(value)
11
- Thread.current["#{object_id}_shard".to_sym] = value
11
+ Thread.current[tls_key] = value
12
12
  end
13
13
 
14
14
  def default_schema
@@ -84,6 +84,12 @@ module Switchman
84
84
  end
85
85
  conn.shard = shard
86
86
  end
87
+
88
+ private
89
+
90
+ def tls_key
91
+ "#{object_id}_shard".to_sym
92
+ end
87
93
  end
88
94
  end
89
95
  end
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.12.11"
2
+ VERSION = "1.12.12"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.11
4
+ version: 1.12.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-09-17 00:00:00.000000000 Z
13
+ date: 2018-10-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -259,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
259
  version: '0'
260
260
  requirements: []
261
261
  rubyforge_project:
262
- rubygems_version: 2.7.6
262
+ rubygems_version: 2.7.2
263
263
  signing_key:
264
264
  specification_version: 4
265
265
  summary: Rails 4 sharding magic