switchman 1.13.3 → 2.0.0
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/app/models/switchman/shard.rb +743 -11
- data/db/migrate/20130328224244_create_default_shard.rb +1 -1
- data/lib/switchman/active_record/abstract_adapter.rb +2 -6
- data/lib/switchman/active_record/association.rb +35 -12
- data/lib/switchman/active_record/attribute_methods.rb +3 -0
- data/lib/switchman/active_record/base.rb +47 -9
- data/lib/switchman/active_record/calculations.rb +2 -1
- data/lib/switchman/active_record/connection_handler.rb +23 -20
- data/lib/switchman/active_record/connection_pool.rb +17 -15
- data/lib/switchman/active_record/log_subscriber.rb +8 -12
- data/lib/switchman/active_record/migration.rb +9 -0
- data/lib/switchman/active_record/model_schema.rb +1 -1
- data/lib/switchman/active_record/postgresql_adapter.rb +22 -47
- data/lib/switchman/active_record/query_cache.rb +17 -107
- data/lib/switchman/active_record/query_methods.rb +4 -0
- data/lib/switchman/active_record/relation.rb +5 -5
- data/lib/switchman/active_record/statement_cache.rb +4 -25
- data/lib/switchman/active_record/table_definition.rb +2 -2
- data/lib/switchman/active_support/cache.rb +16 -0
- data/lib/switchman/connection_pool_proxy.rb +38 -22
- data/lib/switchman/database_server.rb +32 -19
- data/lib/switchman/default_shard.rb +1 -0
- data/lib/switchman/engine.rb +16 -14
- data/lib/switchman/{shackles → guard_rail}/relation.rb +5 -5
- data/lib/switchman/{shackles.rb → guard_rail.rb} +4 -4
- data/lib/switchman/r_spec_helper.rb +7 -7
- 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/switchman.rb +1 -1
- data/lib/tasks/switchman.rake +23 -17
- metadata +35 -22
- data/app/models/switchman/shard_internal.rb +0 -714
|
@@ -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!
|
|
@@ -121,8 +121,8 @@ module Switchman
|
|
|
121
121
|
klass.before do
|
|
122
122
|
raise "Sharding did not set up correctly" if @@sharding_failed
|
|
123
123
|
Shard.clear_cache
|
|
124
|
-
if
|
|
125
|
-
Shard.default(true)
|
|
124
|
+
if use_transactional_tests
|
|
125
|
+
Shard.default(reload: true)
|
|
126
126
|
@shard1 = Shard.find(@shard1.id)
|
|
127
127
|
@shard2 = Shard.find(@shard2.id)
|
|
128
128
|
shards = [@shard2]
|
|
@@ -137,7 +137,7 @@ module Switchman
|
|
|
137
137
|
|
|
138
138
|
klass.after do
|
|
139
139
|
next if @@sharding_failed
|
|
140
|
-
if
|
|
140
|
+
if use_transactional_tests
|
|
141
141
|
shards = [@shard2]
|
|
142
142
|
shards << @shard1 unless @shard1.database_server == Shard.default.database_server
|
|
143
143
|
shards.each do |shard|
|
|
@@ -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/switchman.rb
CHANGED
data/lib/tasks/switchman.rake
CHANGED
|
@@ -20,7 +20,12 @@ module Switchman
|
|
|
20
20
|
open = servers.delete('open')
|
|
21
21
|
|
|
22
22
|
servers = servers.map { |server| DatabaseServer.find(server) }.compact
|
|
23
|
-
|
|
23
|
+
if open
|
|
24
|
+
open_servers = DatabaseServer.all.select { |server| server.config[:open] }
|
|
25
|
+
servers.concat(open_servers)
|
|
26
|
+
servers << DatabaseServer.find(nil) if open_servers.empty?
|
|
27
|
+
servers.uniq!
|
|
28
|
+
end
|
|
24
29
|
servers = DatabaseServer.all - servers if negative
|
|
25
30
|
end
|
|
26
31
|
|
|
@@ -59,16 +64,26 @@ module Switchman
|
|
|
59
64
|
TestHelper.recreate_persistent_test_shards(dont_create: true)
|
|
60
65
|
end
|
|
61
66
|
|
|
62
|
-
::
|
|
63
|
-
Shard.default.database_server.
|
|
67
|
+
::GuardRail.activate(:deploy) do
|
|
68
|
+
Shard.default.database_server.unguard do
|
|
64
69
|
begin
|
|
65
70
|
categories = categories.call if categories.respond_to?(:call)
|
|
66
71
|
Shard.with_each_shard(scope, categories, options) do
|
|
67
72
|
shard = Shard.current
|
|
68
73
|
puts "#{shard.id}: #{shard.description}"
|
|
69
74
|
::ActiveRecord::Base.connection_pool.spec.config[:shard_name] = Shard.current.name
|
|
70
|
-
::
|
|
71
|
-
|
|
75
|
+
if ::Rails.version < '6.0'
|
|
76
|
+
::ActiveRecord::Base.configurations[::Rails.env] = ::ActiveRecord::Base.connection_pool.spec.config.stringify_keys
|
|
77
|
+
else
|
|
78
|
+
# Adopted from the deprecated code that currently lives in rails proper
|
|
79
|
+
remaining_configs = ::ActiveRecord::Base.configurations.configurations.reject { |db_config| db_config.env_name == ::Rails.env }
|
|
80
|
+
new_config = ::ActiveRecord::DatabaseConfigurations.new(::Rails.env =>
|
|
81
|
+
::ActiveRecord::Base.connection_pool.spec.config.stringify_keys).configurations
|
|
82
|
+
new_configs = remaining_configs + new_config
|
|
83
|
+
|
|
84
|
+
::ActiveRecord::Base.configurations = new_configs
|
|
85
|
+
end
|
|
86
|
+
shard.database_server.unguard do
|
|
72
87
|
old_actions.each { |action| action.call(*task_args) }
|
|
73
88
|
end
|
|
74
89
|
nil
|
|
@@ -195,9 +210,7 @@ module Switchman
|
|
|
195
210
|
@filter_database_servers_chain ||= ->(servers) { servers }
|
|
196
211
|
end
|
|
197
212
|
end
|
|
198
|
-
end
|
|
199
213
|
|
|
200
|
-
module Switchman
|
|
201
214
|
module ActiveRecord
|
|
202
215
|
module PostgreSQLDatabaseTasks
|
|
203
216
|
def structure_dump(filename, extra_flags=nil)
|
|
@@ -205,16 +218,9 @@ module Switchman
|
|
|
205
218
|
args = ['-s', '-x', '-O', '-f', filename]
|
|
206
219
|
args.concat(Array(extra_flags)) if extra_flags
|
|
207
220
|
search_path = configuration['schema_search_path']
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
args << "--schema=#{Shellwords.escape(shard)}"
|
|
212
|
-
elsif !search_path.blank?
|
|
213
|
-
args << search_path.split(',').map do |part|
|
|
214
|
-
"--schema=#{part.strip}"
|
|
215
|
-
end.join(' ')
|
|
216
|
-
serialized_search_path = connection.schema_search_path
|
|
217
|
-
end
|
|
221
|
+
shard = Shard.current.name
|
|
222
|
+
serialized_search_path = shard
|
|
223
|
+
args << "--schema=#{Shellwords.escape(shard)}"
|
|
218
224
|
|
|
219
225
|
args << configuration['database']
|
|
220
226
|
run_cmd('pg_dump', args, 'dumping')
|
metadata
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
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
|
|
8
8
|
- James Williams
|
|
9
9
|
- Jacob Fugal
|
|
10
|
-
autorequire:
|
|
10
|
+
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2020-10-05 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: railties
|
|
@@ -18,54 +18,54 @@ dependencies:
|
|
|
18
18
|
requirements:
|
|
19
19
|
- - ">="
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: '5.
|
|
21
|
+
version: '5.1'
|
|
22
22
|
- - "<"
|
|
23
23
|
- !ruby/object:Gem::Version
|
|
24
|
-
version: '
|
|
24
|
+
version: '6.1'
|
|
25
25
|
type: :runtime
|
|
26
26
|
prerelease: false
|
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
|
28
28
|
requirements:
|
|
29
29
|
- - ">="
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
|
-
version: '5.
|
|
31
|
+
version: '5.1'
|
|
32
32
|
- - "<"
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: '
|
|
34
|
+
version: '6.1'
|
|
35
35
|
- !ruby/object:Gem::Dependency
|
|
36
36
|
name: activerecord
|
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
|
38
38
|
requirements:
|
|
39
39
|
- - ">="
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: '5.
|
|
41
|
+
version: '5.1'
|
|
42
42
|
- - "<"
|
|
43
43
|
- !ruby/object:Gem::Version
|
|
44
|
-
version: '
|
|
44
|
+
version: '6.1'
|
|
45
45
|
type: :runtime
|
|
46
46
|
prerelease: false
|
|
47
47
|
version_requirements: !ruby/object:Gem::Requirement
|
|
48
48
|
requirements:
|
|
49
49
|
- - ">="
|
|
50
50
|
- !ruby/object:Gem::Version
|
|
51
|
-
version: '5.
|
|
51
|
+
version: '5.1'
|
|
52
52
|
- - "<"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
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
|
|
@@ -108,6 +108,20 @@ dependencies:
|
|
|
108
108
|
- - ">="
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
110
|
version: '0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: pry
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
111
125
|
- !ruby/object:Gem::Dependency
|
|
112
126
|
name: pg
|
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -173,7 +187,6 @@ extra_rdoc_files: []
|
|
|
173
187
|
files:
|
|
174
188
|
- Rakefile
|
|
175
189
|
- app/models/switchman/shard.rb
|
|
176
|
-
- app/models/switchman/shard_internal.rb
|
|
177
190
|
- db/migrate/20130328212039_create_switchman_shards.rb
|
|
178
191
|
- db/migrate/20130328224244_create_default_shard.rb
|
|
179
192
|
- db/migrate/20161206323434_add_back_default_string_limits_switchman.rb
|
|
@@ -215,12 +228,12 @@ files:
|
|
|
215
228
|
- lib/switchman/engine.rb
|
|
216
229
|
- lib/switchman/environment.rb
|
|
217
230
|
- lib/switchman/errors.rb
|
|
231
|
+
- lib/switchman/guard_rail.rb
|
|
232
|
+
- lib/switchman/guard_rail/relation.rb
|
|
218
233
|
- lib/switchman/open4.rb
|
|
219
234
|
- lib/switchman/r_spec_helper.rb
|
|
220
235
|
- lib/switchman/rails.rb
|
|
221
236
|
- lib/switchman/schema_cache.rb
|
|
222
|
-
- lib/switchman/shackles.rb
|
|
223
|
-
- lib/switchman/shackles/relation.rb
|
|
224
237
|
- lib/switchman/sharded_instrumenter.rb
|
|
225
238
|
- lib/switchman/standard_error.rb
|
|
226
239
|
- lib/switchman/test_helper.rb
|
|
@@ -230,7 +243,7 @@ homepage: http://www.instructure.com/
|
|
|
230
243
|
licenses:
|
|
231
244
|
- MIT
|
|
232
245
|
metadata: {}
|
|
233
|
-
post_install_message:
|
|
246
|
+
post_install_message:
|
|
234
247
|
rdoc_options: []
|
|
235
248
|
require_paths:
|
|
236
249
|
- lib
|
|
@@ -238,15 +251,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
238
251
|
requirements:
|
|
239
252
|
- - ">="
|
|
240
253
|
- !ruby/object:Gem::Version
|
|
241
|
-
version: '2.
|
|
254
|
+
version: '2.5'
|
|
242
255
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
243
256
|
requirements:
|
|
244
257
|
- - ">="
|
|
245
258
|
- !ruby/object:Gem::Version
|
|
246
259
|
version: '0'
|
|
247
260
|
requirements: []
|
|
248
|
-
rubygems_version: 3.
|
|
249
|
-
signing_key:
|
|
261
|
+
rubygems_version: 3.1.2
|
|
262
|
+
signing_key:
|
|
250
263
|
specification_version: 4
|
|
251
|
-
summary: Rails
|
|
264
|
+
summary: Rails sharding magic
|
|
252
265
|
test_files: []
|