switchman 1.16.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/switchman/shard.rb +8 -5
- data/db/migrate/20130328224244_create_default_shard.rb +1 -1
- data/lib/switchman.rb +1 -1
- data/lib/switchman/active_record/abstract_adapter.rb +2 -2
- data/lib/switchman/active_record/base.rb +9 -9
- data/lib/switchman/active_record/connection_handler.rb +6 -6
- data/lib/switchman/active_record/postgresql_adapter.rb +1 -1
- data/lib/switchman/active_record/relation.rb +5 -5
- data/lib/switchman/active_record/statement_cache.rb +1 -1
- data/lib/switchman/active_record/table_definition.rb +2 -2
- data/lib/switchman/connection_pool_proxy.rb +11 -11
- data/lib/switchman/database_server.rb +16 -16
- data/lib/switchman/engine.rb +8 -8
- data/lib/switchman/{shackles.rb → guard_rail.rb} +4 -4
- data/lib/switchman/{shackles → guard_rail}/relation.rb +5 -5
- data/lib/switchman/r_spec_helper.rb +5 -5
- data/lib/switchman/sharded_instrumenter.rb +1 -1
- data/lib/switchman/test_helper.rb +3 -3
- data/lib/switchman/version.rb +1 -1
- data/lib/tasks/switchman.rake +3 -3
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cec081d77daa09b754a98ce7bc335198b2dfbdbcd093df492a43803ff7a2742
|
4
|
+
data.tar.gz: d93576725471024b24c4622d33e0eff9c1b61498b6c037e624d9b6ff8c78a442
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d4c7b1e82460fbdfda1659fc09379583c5e63ecc21d412466563a62c42679db864f8f09c2eaa2bed17b53216c64d18c42caabec76291f25e00bfc1e6a2499a1
|
7
|
+
data.tar.gz: e52baf68ce2301dfa26abffd423e9855c875232871539fea59ae88ffd8f3b355299cb4c0bb60e32bf90555e7e935d2f73954ec01919cab16993bee73b39e56b6
|
@@ -38,7 +38,10 @@ module Switchman
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def default(reload_deprecated = false, reload: false, with_fallback: false)
|
41
|
-
|
41
|
+
if reload_deprecated
|
42
|
+
reload = reload_deprecated
|
43
|
+
ActiveSupport::Deprecation.warn("positional reload parameter to Switchman::Shard.default is deprecated; use `reload: true`")
|
44
|
+
end
|
42
45
|
if !@default || reload
|
43
46
|
# Have to create a dummy object so that several key methods still work
|
44
47
|
# (it's easier to do this in one place here, and just assume that sharding
|
@@ -351,8 +354,8 @@ module Switchman
|
|
351
354
|
# prune the prior connection unless it happened to be the same
|
352
355
|
if previous_shard && shard != previous_shard && !previous_shard.database_server.shareable?
|
353
356
|
previous_shard.activate do
|
354
|
-
::
|
355
|
-
::
|
357
|
+
::GuardRail.activated_environments.each do |env|
|
358
|
+
::GuardRail.activate(env) do
|
356
359
|
if ::ActiveRecord::Base.connected? && ::ActiveRecord::Base.connection.open_transactions == 0
|
357
360
|
::ActiveRecord::Base.connection_pool.current_pool.disconnect!
|
358
361
|
end
|
@@ -659,7 +662,7 @@ module Switchman
|
|
659
662
|
case adapter
|
660
663
|
when 'mysql', 'mysql2'
|
661
664
|
self.activate do
|
662
|
-
::
|
665
|
+
::GuardRail.activate(:deploy) do
|
663
666
|
drop_statement ||= "DROP DATABASE #{self.name}"
|
664
667
|
Array(drop_statement).each do |stmt|
|
665
668
|
::ActiveRecord::Base.connection.execute(stmt)
|
@@ -668,7 +671,7 @@ module Switchman
|
|
668
671
|
end
|
669
672
|
when 'postgresql'
|
670
673
|
self.activate do
|
671
|
-
::
|
674
|
+
::GuardRail.activate(:deploy) do
|
672
675
|
# Shut up, Postgres!
|
673
676
|
conn = ::ActiveRecord::Base.connection
|
674
677
|
old_proc = conn.raw_connection.set_notice_processor {}
|
@@ -3,7 +3,7 @@ class CreateDefaultShard < ActiveRecord::Migration[4.2]
|
|
3
3
|
unless Switchman::Shard.default.is_a?(Switchman::Shard)
|
4
4
|
Switchman::Shard.reset_column_information
|
5
5
|
Switchman::Shard.create!(:default => true)
|
6
|
-
Switchman::Shard.default(true)
|
6
|
+
Switchman::Shard.default(reload: true)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
data/lib/switchman.rb
CHANGED
@@ -4,8 +4,8 @@ module Switchman
|
|
4
4
|
module ActiveRecord
|
5
5
|
module AbstractAdapter
|
6
6
|
module ForeignKeyCheck
|
7
|
-
def add_column(table, name, type,
|
8
|
-
Engine.foreign_key_check(name, type,
|
7
|
+
def add_column(table, name, type, limit: nil, **)
|
8
|
+
Engine.foreign_key_check(name, type, limit: limit)
|
9
9
|
super
|
10
10
|
end
|
11
11
|
end
|
@@ -31,20 +31,20 @@ module Switchman
|
|
31
31
|
@integral_id
|
32
32
|
end
|
33
33
|
|
34
|
-
def transaction(
|
34
|
+
def transaction(**)
|
35
35
|
if self != ::ActiveRecord::Base && current_scope
|
36
36
|
current_scope.activate do
|
37
37
|
db = Shard.current(shard_category).database_server
|
38
|
-
if ::
|
39
|
-
db.
|
38
|
+
if ::GuardRail.environment != db.guard_rail_environment
|
39
|
+
db.unguard { super }
|
40
40
|
else
|
41
41
|
super
|
42
42
|
end
|
43
43
|
end
|
44
44
|
else
|
45
45
|
db = Shard.current(shard_category).database_server
|
46
|
-
if ::
|
47
|
-
db.
|
46
|
+
if ::GuardRail.environment != db.guard_rail_environment
|
47
|
+
db.unguard { super }
|
48
48
|
else
|
49
49
|
super
|
50
50
|
end
|
@@ -105,12 +105,12 @@ module Switchman
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
def save(
|
108
|
+
def save(*, **)
|
109
109
|
@shard_set_in_stone = true
|
110
110
|
(self.class.current_scope || self.class.default_scoped).shard(shard, :implicit).scoping { super }
|
111
111
|
end
|
112
112
|
|
113
|
-
def save!(
|
113
|
+
def save!(*, **)
|
114
114
|
@shard_set_in_stone = true
|
115
115
|
(self.class.current_scope || self.class.default_scoped).shard(shard, :implicit).scoping { super }
|
116
116
|
end
|
@@ -157,8 +157,8 @@ module Switchman
|
|
157
157
|
|
158
158
|
def update_columns(*)
|
159
159
|
db = Shard.current(self.class.shard_category).database_server
|
160
|
-
if ::
|
161
|
-
return db.
|
160
|
+
if ::GuardRail.environment != db.guard_rail_environment
|
161
|
+
return db.unguard { super }
|
162
162
|
else
|
163
163
|
super
|
164
164
|
end
|
@@ -55,7 +55,7 @@ module Switchman
|
|
55
55
|
Shard.default.remove_instance_variable(:@name) if Shard.default.instance_variable_defined?(:@name)
|
56
56
|
end
|
57
57
|
|
58
|
-
@shard_connection_pools ||= { [:
|
58
|
+
@shard_connection_pools ||= { [:primary, Shard.default.database_server.shareable? ? ::Rails.env : Shard.default] => pool}
|
59
59
|
|
60
60
|
category = pool.spec.name.to_sym
|
61
61
|
proxy = ConnectionPoolProxy.new(category,
|
@@ -64,13 +64,13 @@ module Switchman
|
|
64
64
|
owner_to_pool[pool.spec.name] = proxy
|
65
65
|
|
66
66
|
if first_time
|
67
|
-
if Shard.default.database_server.config[:
|
68
|
-
Shard.default.database_server.
|
67
|
+
if Shard.default.database_server.config[:prefer_secondary]
|
68
|
+
Shard.default.database_server.guard!
|
69
69
|
end
|
70
70
|
|
71
|
-
if Shard.default.is_a?(DefaultShard) && Shard.default.database_server.config[:
|
72
|
-
Shard.default.database_server.
|
73
|
-
Shard.default(true)
|
71
|
+
if Shard.default.is_a?(DefaultShard) && Shard.default.database_server.config[:secondary]
|
72
|
+
Shard.default.database_server.guard!
|
73
|
+
Shard.default(reload: true)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -192,7 +192,7 @@ module Switchman
|
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
195
|
-
def add_index_options(_table_name, _column_name,
|
195
|
+
def add_index_options(_table_name, _column_name, **)
|
196
196
|
index_name, index_type, index_columns, index_options, algorithm, using = super
|
197
197
|
algorithm = nil if DatabaseServer.creating_new_shard && algorithm == "CONCURRENTLY"
|
198
198
|
[index_name, index_type, index_columns, index_options, algorithm, using]
|
@@ -5,7 +5,7 @@ module Switchman
|
|
5
5
|
klass::SINGLE_VALUE_METHODS.concat [ :shard, :shard_source ]
|
6
6
|
end
|
7
7
|
|
8
|
-
def initialize(
|
8
|
+
def initialize(*, **)
|
9
9
|
super
|
10
10
|
self.shard_value = Shard.current(klass ? klass.shard_category : :primary) unless shard_value
|
11
11
|
self.shard_source_value = :implicit unless shard_source_value
|
@@ -17,7 +17,7 @@ module Switchman
|
|
17
17
|
result
|
18
18
|
end
|
19
19
|
|
20
|
-
def merge(*
|
20
|
+
def merge(*)
|
21
21
|
relation = super
|
22
22
|
if relation.shard_value != self.shard_value && relation.shard_source_value == :implicit
|
23
23
|
relation.shard_value = self.shard_value
|
@@ -26,15 +26,15 @@ module Switchman
|
|
26
26
|
relation
|
27
27
|
end
|
28
28
|
|
29
|
-
def new(
|
29
|
+
def new(*, &block)
|
30
30
|
primary_shard.activate(klass.shard_category) { super }
|
31
31
|
end
|
32
32
|
|
33
|
-
def create(
|
33
|
+
def create(*, &block)
|
34
34
|
primary_shard.activate(klass.shard_category) { super }
|
35
35
|
end
|
36
36
|
|
37
|
-
def create!(
|
37
|
+
def create!(*, &block)
|
38
38
|
primary_shard.activate(klass.shard_category) { super }
|
39
39
|
end
|
40
40
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Switchman
|
2
2
|
module ActiveRecord
|
3
3
|
module TableDefinition
|
4
|
-
def column(name, type,
|
5
|
-
Engine.foreign_key_check(name, type,
|
4
|
+
def column(name, type, limit: nil, **)
|
5
|
+
Engine.foreign_key_check(name, type, limit: limit)
|
6
6
|
super
|
7
7
|
end
|
8
8
|
end
|
@@ -37,13 +37,13 @@ module Switchman
|
|
37
37
|
Shard.current(@category)
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
41
|
-
::Rails.env.test? ? :
|
40
|
+
def active_guard_rail_environment
|
41
|
+
::Rails.env.test? ? :primary : active_shard.database_server.guard_rail_environment
|
42
42
|
end
|
43
43
|
|
44
44
|
def current_pool
|
45
45
|
current_active_shard = active_shard
|
46
|
-
pool = self.default_pool if current_active_shard.database_server == Shard.default.database_server &&
|
46
|
+
pool = self.default_pool if current_active_shard.database_server == Shard.default.database_server && active_guard_rail_environment == :primary && (current_active_shard.default? || current_active_shard.database_server.shareable?)
|
47
47
|
pool = @connection_pools[pool_key] ||= create_pool unless pool
|
48
48
|
pool.shard = current_active_shard
|
49
49
|
pool
|
@@ -60,8 +60,8 @@ module Switchman
|
|
60
60
|
connection.instance_variable_set(:@schema_cache, @schema_cache) unless ::Rails.version >= '6'
|
61
61
|
connection
|
62
62
|
rescue ConnectionError
|
63
|
-
raise if active_shard.database_server == Shard.default.database_server &&
|
64
|
-
configs = active_shard.database_server.config(
|
63
|
+
raise if active_shard.database_server == Shard.default.database_server && active_guard_rail_environment == :primary
|
64
|
+
configs = active_shard.database_server.config(active_guard_rail_environment)
|
65
65
|
raise unless configs.is_a?(Array)
|
66
66
|
configs.each_with_index do |config, idx|
|
67
67
|
pool = create_pool(config.dup)
|
@@ -120,7 +120,7 @@ module Switchman
|
|
120
120
|
end
|
121
121
|
|
122
122
|
def pool_key
|
123
|
-
[
|
123
|
+
[active_guard_rail_environment,
|
124
124
|
active_shard.database_server.shareable? ? active_shard.database_server.pool_key : active_shard]
|
125
125
|
end
|
126
126
|
|
@@ -128,7 +128,7 @@ module Switchman
|
|
128
128
|
shard = active_shard
|
129
129
|
unless config
|
130
130
|
if shard != Shard.default
|
131
|
-
config = shard.database_server.config(
|
131
|
+
config = shard.database_server.config(active_guard_rail_environment)
|
132
132
|
config = config.first if config.is_a?(Array)
|
133
133
|
config = config.dup
|
134
134
|
else
|
@@ -138,10 +138,10 @@ module Switchman
|
|
138
138
|
# different models could be using different configs on the default
|
139
139
|
# shard, and database server wouldn't know about that
|
140
140
|
config = default_pool.spec.instance_variable_get(:@config)
|
141
|
-
if config[
|
142
|
-
config = config.merge(config[
|
143
|
-
elsif config[
|
144
|
-
config = config.merge(config[
|
141
|
+
if config[active_guard_rail_environment].is_a?(Hash)
|
142
|
+
config = config.merge(config[active_guard_rail_environment])
|
143
|
+
elsif config[active_guard_rail_environment].is_a?(Array)
|
144
|
+
config = config.merge(config[active_guard_rail_environment].first)
|
145
145
|
else
|
146
146
|
config = config.dup
|
147
147
|
end
|
@@ -69,12 +69,12 @@ module Switchman
|
|
69
69
|
@fake
|
70
70
|
end
|
71
71
|
|
72
|
-
def config(environment = :
|
72
|
+
def config(environment = :primary)
|
73
73
|
@configs[environment] ||= begin
|
74
74
|
if @config[environment].is_a?(Array)
|
75
75
|
@config[environment].map do |config|
|
76
76
|
config = @config.merge((config || {}).symbolize_keys)
|
77
|
-
# make sure
|
77
|
+
# make sure GuardRail doesn't get any brilliant ideas about choosing the first possible server
|
78
78
|
config.delete(environment)
|
79
79
|
config
|
80
80
|
end
|
@@ -86,33 +86,33 @@ module Switchman
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
def
|
90
|
-
@
|
89
|
+
def guard_rail_environment
|
90
|
+
@guard_rail_environment || ::GuardRail.environment
|
91
91
|
end
|
92
92
|
|
93
93
|
# locks this db to a specific environment, except for
|
94
94
|
# when doing writes (then it falls back to the current
|
95
|
-
# value of
|
96
|
-
def
|
97
|
-
@
|
95
|
+
# value of GuardRail.environment)
|
96
|
+
def guard!(environment = :secondary)
|
97
|
+
@guard_rail_environment = environment
|
98
98
|
end
|
99
99
|
|
100
|
-
def
|
101
|
-
@
|
100
|
+
def unguard!
|
101
|
+
@guard_rail_environment = nil
|
102
102
|
end
|
103
103
|
|
104
|
-
def
|
105
|
-
old_env = @
|
106
|
-
|
104
|
+
def unguard
|
105
|
+
old_env = @guard_rail_environment
|
106
|
+
unguard!
|
107
107
|
yield
|
108
108
|
ensure
|
109
|
-
|
109
|
+
guard!(old_env)
|
110
110
|
end
|
111
111
|
|
112
112
|
def shareable?
|
113
113
|
@shareable_environment_key ||= []
|
114
|
-
environment =
|
115
|
-
explicit_user = ::
|
114
|
+
environment = guard_rail_environment
|
115
|
+
explicit_user = ::GuardRail.global_config[:username]
|
116
116
|
return @shareable if @shareable_environment_key == [environment, explicit_user]
|
117
117
|
@shareable_environment_key = [environment, explicit_user]
|
118
118
|
if explicit_user
|
@@ -190,7 +190,7 @@ module Switchman
|
|
190
190
|
begin
|
191
191
|
self.class.creating_new_shard = true
|
192
192
|
shard.activate(*Shard.categories) do
|
193
|
-
::
|
193
|
+
::GuardRail.activate(:deploy) do
|
194
194
|
begin
|
195
195
|
if create_statement
|
196
196
|
if (::ActiveRecord::Base.connection.select_value("SELECT 1 FROM pg_namespace WHERE nspname=#{::ActiveRecord::Base.connection.quote(name)}"))
|
data/lib/switchman/engine.rb
CHANGED
@@ -87,7 +87,7 @@ module Switchman
|
|
87
87
|
require "switchman/arel"
|
88
88
|
require "switchman/call_super"
|
89
89
|
require "switchman/rails"
|
90
|
-
require "switchman/
|
90
|
+
require "switchman/guard_rail/relation"
|
91
91
|
require_dependency "switchman/shard"
|
92
92
|
require "switchman/standard_error"
|
93
93
|
|
@@ -133,7 +133,7 @@ module Switchman
|
|
133
133
|
::ActiveRecord::Relation.prepend(ActiveRecord::Calculations)
|
134
134
|
::ActiveRecord::Relation.include(ActiveRecord::FinderMethods)
|
135
135
|
::ActiveRecord::Relation.include(ActiveRecord::QueryMethods)
|
136
|
-
::ActiveRecord::Relation.prepend(
|
136
|
+
::ActiveRecord::Relation.prepend(GuardRail::Relation)
|
137
137
|
::ActiveRecord::Relation.prepend(ActiveRecord::Relation)
|
138
138
|
::ActiveRecord::Relation.include(ActiveRecord::SpawnMethods)
|
139
139
|
::ActiveRecord::Relation.include(CallSuper)
|
@@ -150,8 +150,8 @@ module Switchman
|
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
-
def self.foreign_key_check(name, type,
|
154
|
-
if name.to_s =~ /_id\z/ && type.to_s == 'integer' &&
|
153
|
+
def self.foreign_key_check(name, type, limit: nil)
|
154
|
+
if name.to_s =~ /_id\z/ && type.to_s == 'integer' && limit.to_i < 8
|
155
155
|
puts "WARNING: All foreign keys need to be 8-byte integers. #{name} looks like a foreign key. If so, please add the option: `:limit => 8`"
|
156
156
|
end
|
157
157
|
end
|
@@ -185,15 +185,15 @@ module Switchman
|
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
188
|
-
initializer 'switchman.
|
188
|
+
initializer 'switchman.extend_guard_rail', :before => "switchman.extend_ar" do
|
189
189
|
::ActiveSupport.on_load(:active_record) do
|
190
|
-
require "switchman/
|
190
|
+
require "switchman/guard_rail"
|
191
191
|
|
192
|
-
::
|
192
|
+
::GuardRail.singleton_class.prepend(GuardRail::ClassMethods)
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
196
|
-
initializer 'switchman.extend_controller', :after => "
|
196
|
+
initializer 'switchman.extend_controller', :after => "guard_rail.extend_ar" do
|
197
197
|
::ActiveSupport.on_load(:action_controller) do
|
198
198
|
require "switchman/action_controller/caching"
|
199
199
|
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module Switchman
|
2
|
-
module
|
2
|
+
module GuardRail
|
3
3
|
module ClassMethods
|
4
4
|
def self.prepended(klass)
|
5
5
|
klass.send(:remove_method, :ensure_handler)
|
6
6
|
end
|
7
7
|
|
8
8
|
# drops the save_handler and ensure_handler calls from the vanilla
|
9
|
-
#
|
9
|
+
# GuardRail' implementation.
|
10
10
|
def activate!(environment)
|
11
|
-
environment ||= :
|
11
|
+
environment ||= :primary
|
12
12
|
activated_environments << environment
|
13
13
|
old_environment = self.environment
|
14
|
-
Thread.current[:
|
14
|
+
Thread.current[:guard_rail_environment] = environment
|
15
15
|
old_environment
|
16
16
|
end
|
17
17
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Switchman
|
2
|
-
module
|
2
|
+
module GuardRail
|
3
3
|
module Relation
|
4
4
|
def exec_queries(*args)
|
5
5
|
if self.lock_value
|
6
6
|
db = Shard.current(shard_category).database_server
|
7
|
-
if ::
|
8
|
-
return db.
|
7
|
+
if ::GuardRail.environment != db.guard_rail_environment
|
8
|
+
return db.unguard { super }
|
9
9
|
end
|
10
10
|
end
|
11
11
|
super
|
@@ -15,8 +15,8 @@ module Switchman
|
|
15
15
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
16
16
|
def #{method}(*args)
|
17
17
|
db = Shard.current(shard_category).database_server
|
18
|
-
if ::
|
19
|
-
db.
|
18
|
+
if ::GuardRail.environment != db.guard_rail_environment
|
19
|
+
db.unguard { super }
|
20
20
|
else
|
21
21
|
super
|
22
22
|
end
|
@@ -65,7 +65,7 @@ module Switchman
|
|
65
65
|
(@@shard3.drop_database if @@shard3) rescue nil
|
66
66
|
@@shard1 = @@shard2 = @@shard3 = nil
|
67
67
|
Shard.delete_all
|
68
|
-
Shard.default(true)
|
68
|
+
Shard.default(reload: true)
|
69
69
|
next
|
70
70
|
end
|
71
71
|
end
|
@@ -73,7 +73,7 @@ module Switchman
|
|
73
73
|
# in the db before then
|
74
74
|
Shard.delete_all
|
75
75
|
Switchman.cache.delete("default_shard")
|
76
|
-
Shard.default(true)
|
76
|
+
Shard.default(reload: true)
|
77
77
|
puts "Done!"
|
78
78
|
|
79
79
|
at_exit do
|
@@ -102,7 +102,7 @@ module Switchman
|
|
102
102
|
dup.id = @@default_shard.id
|
103
103
|
dup.save!
|
104
104
|
Switchman.cache.delete("default_shard")
|
105
|
-
Shard.default(true)
|
105
|
+
Shard.default(reload: true)
|
106
106
|
dup = @@shard1.dup
|
107
107
|
dup.id = @@shard1.id
|
108
108
|
dup.save!
|
@@ -122,7 +122,7 @@ module Switchman
|
|
122
122
|
raise "Sharding did not set up correctly" if @@sharding_failed
|
123
123
|
Shard.clear_cache
|
124
124
|
if use_transactional_tests
|
125
|
-
Shard.default(true)
|
125
|
+
Shard.default(reload: true)
|
126
126
|
@shard1 = Shard.find(@shard1.id)
|
127
127
|
@shard2 = Shard.find(@shard2.id)
|
128
128
|
shards = [@shard2]
|
@@ -151,7 +151,7 @@ module Switchman
|
|
151
151
|
klass.after(:all) do
|
152
152
|
Shard.connection.update("TRUNCATE #{Shard.quoted_table_name} CASCADE")
|
153
153
|
Switchman.cache.delete("default_shard")
|
154
|
-
Shard.default(true)
|
154
|
+
Shard.default(reload: true)
|
155
155
|
end
|
156
156
|
end
|
157
157
|
end
|
@@ -3,8 +3,8 @@ module Switchman
|
|
3
3
|
class << self
|
4
4
|
def recreate_persistent_test_shards(dont_create: false)
|
5
5
|
# recreate the default shard (it got buhleted)
|
6
|
-
::
|
7
|
-
if Shard.default(true).is_a?(DefaultShard)
|
6
|
+
::GuardRail.activate(:deploy) { Switchman.cache.clear }
|
7
|
+
if Shard.default(reload: true).is_a?(DefaultShard)
|
8
8
|
begin
|
9
9
|
Shard.create!(default: true)
|
10
10
|
rescue
|
@@ -12,7 +12,7 @@ module Switchman
|
|
12
12
|
# database doesn't exist yet, presumably cause we're creating it right now
|
13
13
|
return [nil, nil]
|
14
14
|
end
|
15
|
-
Shard.default(true)
|
15
|
+
Shard.default(reload: true)
|
16
16
|
end
|
17
17
|
|
18
18
|
# can't auto-create a new shard on the default shard's db server if the
|
data/lib/switchman/version.rb
CHANGED
data/lib/tasks/switchman.rake
CHANGED
@@ -64,8 +64,8 @@ module Switchman
|
|
64
64
|
TestHelper.recreate_persistent_test_shards(dont_create: true)
|
65
65
|
end
|
66
66
|
|
67
|
-
::
|
68
|
-
Shard.default.database_server.
|
67
|
+
::GuardRail.activate(:deploy) do
|
68
|
+
Shard.default.database_server.unguard do
|
69
69
|
begin
|
70
70
|
categories = categories.call if categories.respond_to?(:call)
|
71
71
|
Shard.with_each_shard(scope, categories, options) do
|
@@ -83,7 +83,7 @@ module Switchman
|
|
83
83
|
|
84
84
|
::ActiveRecord::Base.configurations = new_configs
|
85
85
|
end
|
86
|
-
shard.database_server.
|
86
|
+
shard.database_server.unguard do
|
87
87
|
old_actions.each { |action| action.call(*task_args) }
|
88
88
|
end
|
89
89
|
nil
|
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:
|
4
|
+
version: 2.0.0
|
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: 2020-
|
13
|
+
date: 2020-10-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|
@@ -53,19 +53,19 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '6.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: guardrail
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 2.0.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.0.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: open4
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -228,12 +228,12 @@ files:
|
|
228
228
|
- lib/switchman/engine.rb
|
229
229
|
- lib/switchman/environment.rb
|
230
230
|
- lib/switchman/errors.rb
|
231
|
+
- lib/switchman/guard_rail.rb
|
232
|
+
- lib/switchman/guard_rail/relation.rb
|
231
233
|
- lib/switchman/open4.rb
|
232
234
|
- lib/switchman/r_spec_helper.rb
|
233
235
|
- lib/switchman/rails.rb
|
234
236
|
- lib/switchman/schema_cache.rb
|
235
|
-
- lib/switchman/shackles.rb
|
236
|
-
- lib/switchman/shackles/relation.rb
|
237
237
|
- lib/switchman/sharded_instrumenter.rb
|
238
238
|
- lib/switchman/standard_error.rb
|
239
239
|
- lib/switchman/test_helper.rb
|
@@ -251,15 +251,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
251
251
|
requirements:
|
252
252
|
- - ">="
|
253
253
|
- !ruby/object:Gem::Version
|
254
|
-
version: '2.
|
254
|
+
version: '2.5'
|
255
255
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
256
256
|
requirements:
|
257
257
|
- - ">="
|
258
258
|
- !ruby/object:Gem::Version
|
259
259
|
version: '0'
|
260
260
|
requirements: []
|
261
|
-
rubygems_version: 3.
|
261
|
+
rubygems_version: 3.1.2
|
262
262
|
signing_key:
|
263
263
|
specification_version: 4
|
264
|
-
summary: Rails
|
264
|
+
summary: Rails sharding magic
|
265
265
|
test_files: []
|