switchman 1.15.1 → 2.0.2
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 +10 -5
- data/db/migrate/20130328212039_create_switchman_shards.rb +2 -0
- data/db/migrate/20130328224244_create_default_shard.rb +3 -1
- data/db/migrate/20161206323434_add_back_default_string_limits_switchman.rb +2 -0
- data/db/migrate/20180828183945_add_default_shard_index.rb +2 -0
- data/db/migrate/20180828192111_add_timestamps_to_shards.rb +2 -0
- data/db/migrate/20190114212900_add_unique_name_indexes.rb +2 -0
- data/lib/switchman.rb +3 -1
- data/lib/switchman/action_controller/caching.rb +2 -0
- data/lib/switchman/active_record/abstract_adapter.rb +6 -4
- data/lib/switchman/active_record/association.rb +2 -0
- data/lib/switchman/active_record/attribute_methods.rb +2 -0
- data/lib/switchman/active_record/base.rb +20 -9
- data/lib/switchman/active_record/batches.rb +2 -0
- data/lib/switchman/active_record/calculations.rb +2 -0
- data/lib/switchman/active_record/connection_handler.rb +8 -14
- data/lib/switchman/active_record/connection_pool.rb +2 -12
- data/lib/switchman/active_record/finder_methods.rb +2 -0
- data/lib/switchman/active_record/log_subscriber.rb +2 -0
- data/lib/switchman/active_record/migration.rb +2 -0
- data/lib/switchman/active_record/model_schema.rb +2 -0
- data/lib/switchman/active_record/persistence.rb +3 -1
- data/lib/switchman/active_record/postgresql_adapter.rb +12 -21
- data/lib/switchman/active_record/predicate_builder.rb +2 -0
- data/lib/switchman/active_record/query_cache.rb +2 -0
- data/lib/switchman/active_record/query_methods.rb +2 -0
- data/lib/switchman/active_record/reflection.rb +2 -0
- data/lib/switchman/active_record/relation.rb +7 -5
- data/lib/switchman/active_record/spawn_methods.rb +2 -0
- data/lib/switchman/active_record/statement_cache.rb +5 -16
- data/lib/switchman/active_record/table_definition.rb +4 -2
- data/lib/switchman/active_record/type_caster.rb +2 -0
- data/lib/switchman/active_record/where_clause_factory.rb +2 -0
- data/lib/switchman/active_support/cache.rb +4 -2
- data/lib/switchman/arel.rb +2 -0
- data/lib/switchman/call_super.rb +2 -0
- data/lib/switchman/connection_pool_proxy.rb +13 -11
- data/lib/switchman/database_server.rb +18 -16
- data/lib/switchman/default_shard.rb +2 -0
- data/lib/switchman/engine.rb +10 -8
- data/lib/switchman/environment.rb +2 -0
- data/lib/switchman/errors.rb +2 -0
- data/lib/switchman/{shackles.rb → guard_rail.rb} +6 -4
- data/lib/switchman/{shackles → guard_rail}/relation.rb +7 -5
- data/lib/switchman/open4.rb +2 -0
- data/lib/switchman/r_spec_helper.rb +7 -5
- data/lib/switchman/rails.rb +2 -0
- data/lib/switchman/schema_cache.rb +2 -0
- data/lib/switchman/sharded_instrumenter.rb +3 -1
- data/lib/switchman/standard_error.rb +2 -0
- data/lib/switchman/test_helper.rb +5 -3
- data/lib/switchman/version.rb +3 -1
- data/lib/tasks/switchman.rake +6 -13
- metadata +27 -13
data/lib/switchman/open4.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "switchman/test_helper"
|
2
4
|
|
3
5
|
module Switchman
|
@@ -65,7 +67,7 @@ module Switchman
|
|
65
67
|
(@@shard3.drop_database if @@shard3) rescue nil
|
66
68
|
@@shard1 = @@shard2 = @@shard3 = nil
|
67
69
|
Shard.delete_all
|
68
|
-
Shard.default(true)
|
70
|
+
Shard.default(reload: true)
|
69
71
|
next
|
70
72
|
end
|
71
73
|
end
|
@@ -73,7 +75,7 @@ module Switchman
|
|
73
75
|
# in the db before then
|
74
76
|
Shard.delete_all
|
75
77
|
Switchman.cache.delete("default_shard")
|
76
|
-
Shard.default(true)
|
78
|
+
Shard.default(reload: true)
|
77
79
|
puts "Done!"
|
78
80
|
|
79
81
|
at_exit do
|
@@ -102,7 +104,7 @@ module Switchman
|
|
102
104
|
dup.id = @@default_shard.id
|
103
105
|
dup.save!
|
104
106
|
Switchman.cache.delete("default_shard")
|
105
|
-
Shard.default(true)
|
107
|
+
Shard.default(reload: true)
|
106
108
|
dup = @@shard1.dup
|
107
109
|
dup.id = @@shard1.id
|
108
110
|
dup.save!
|
@@ -122,7 +124,7 @@ module Switchman
|
|
122
124
|
raise "Sharding did not set up correctly" if @@sharding_failed
|
123
125
|
Shard.clear_cache
|
124
126
|
if use_transactional_tests
|
125
|
-
Shard.default(true)
|
127
|
+
Shard.default(reload: true)
|
126
128
|
@shard1 = Shard.find(@shard1.id)
|
127
129
|
@shard2 = Shard.find(@shard2.id)
|
128
130
|
shards = [@shard2]
|
@@ -151,7 +153,7 @@ module Switchman
|
|
151
153
|
klass.after(:all) do
|
152
154
|
Shard.connection.update("TRUNCATE #{Shard.quoted_table_name} CASCADE")
|
153
155
|
Switchman.cache.delete("default_shard")
|
154
|
-
Shard.default(true)
|
156
|
+
Shard.default(reload: true)
|
155
157
|
end
|
156
158
|
end
|
157
159
|
end
|
data/lib/switchman/rails.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Switchman
|
2
4
|
class ShardedInstrumenter < ::SimpleDelegator
|
3
5
|
def initialize(instrumenter, shard_host)
|
@@ -14,7 +16,7 @@ module Switchman
|
|
14
16
|
payload[:shard] = {
|
15
17
|
database_server_id: shard.database_server.id,
|
16
18
|
id: shard.id,
|
17
|
-
env: shard.database_server.
|
19
|
+
env: shard.database_server.guard_rail_environment
|
18
20
|
}
|
19
21
|
end
|
20
22
|
super name, payload
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Switchman
|
2
4
|
module TestHelper
|
3
5
|
class << self
|
4
6
|
def recreate_persistent_test_shards(dont_create: false)
|
5
7
|
# recreate the default shard (it got buhleted)
|
6
|
-
::
|
7
|
-
if Shard.default(true).is_a?(DefaultShard)
|
8
|
+
::GuardRail.activate(:deploy) { Switchman.cache.clear }
|
9
|
+
if Shard.default(reload: true).is_a?(DefaultShard)
|
8
10
|
begin
|
9
11
|
Shard.create!(default: true)
|
10
12
|
rescue
|
@@ -12,7 +14,7 @@ module Switchman
|
|
12
14
|
# database doesn't exist yet, presumably cause we're creating it right now
|
13
15
|
return [nil, nil]
|
14
16
|
end
|
15
|
-
Shard.default(true)
|
17
|
+
Shard.default(reload: true)
|
16
18
|
end
|
17
19
|
|
18
20
|
# 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
|
@@ -218,16 +218,9 @@ module Switchman
|
|
218
218
|
args = ['-s', '-x', '-O', '-f', filename]
|
219
219
|
args.concat(Array(extra_flags)) if extra_flags
|
220
220
|
search_path = configuration['schema_search_path']
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
args << "--schema=#{Shellwords.escape(shard)}"
|
225
|
-
elsif !search_path.blank?
|
226
|
-
args << search_path.split(',').map do |part|
|
227
|
-
"--schema=#{part.strip}"
|
228
|
-
end.join(' ')
|
229
|
-
serialized_search_path = connection.schema_search_path
|
230
|
-
end
|
221
|
+
shard = Shard.current.name
|
222
|
+
serialized_search_path = shard
|
223
|
+
args << "--schema=#{Shellwords.escape(shard)}"
|
231
224
|
|
232
225
|
args << configuration['database']
|
233
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.2
|
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: 2020-06
|
13
|
+
date: 2020-11-06 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
|
@@ -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
|
@@ -214,12 +228,12 @@ files:
|
|
214
228
|
- lib/switchman/engine.rb
|
215
229
|
- lib/switchman/environment.rb
|
216
230
|
- lib/switchman/errors.rb
|
231
|
+
- lib/switchman/guard_rail.rb
|
232
|
+
- lib/switchman/guard_rail/relation.rb
|
217
233
|
- lib/switchman/open4.rb
|
218
234
|
- lib/switchman/r_spec_helper.rb
|
219
235
|
- lib/switchman/rails.rb
|
220
236
|
- lib/switchman/schema_cache.rb
|
221
|
-
- lib/switchman/shackles.rb
|
222
|
-
- lib/switchman/shackles/relation.rb
|
223
237
|
- lib/switchman/sharded_instrumenter.rb
|
224
238
|
- lib/switchman/standard_error.rb
|
225
239
|
- lib/switchman/test_helper.rb
|
@@ -229,7 +243,7 @@ homepage: http://www.instructure.com/
|
|
229
243
|
licenses:
|
230
244
|
- MIT
|
231
245
|
metadata: {}
|
232
|
-
post_install_message:
|
246
|
+
post_install_message:
|
233
247
|
rdoc_options: []
|
234
248
|
require_paths:
|
235
249
|
- lib
|
@@ -237,15 +251,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
237
251
|
requirements:
|
238
252
|
- - ">="
|
239
253
|
- !ruby/object:Gem::Version
|
240
|
-
version: '2.
|
254
|
+
version: '2.5'
|
241
255
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
242
256
|
requirements:
|
243
257
|
- - ">="
|
244
258
|
- !ruby/object:Gem::Version
|
245
259
|
version: '0'
|
246
260
|
requirements: []
|
247
|
-
rubygems_version: 3.
|
248
|
-
signing_key:
|
261
|
+
rubygems_version: 3.1.4
|
262
|
+
signing_key:
|
249
263
|
specification_version: 4
|
250
|
-
summary: Rails
|
264
|
+
summary: Rails sharding magic
|
251
265
|
test_files: []
|