switchman 3.3.1 → 3.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/switchman/active_record/associations.rb +5 -4
- data/lib/switchman/shard.rb +19 -9
- data/lib/switchman/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 786c667d13377d8e04408f506d0bdb01cf64143a89ba029c0fc373d840851c01
|
4
|
+
data.tar.gz: 01a1e23d2622783d9cc93d36cbec0dbbfd1e4e71d264e7a5e92db9f5446475f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 536073d8679b9b4bc5aa1facfea63ac6289caacca60177264321a75bae80c3795bb7941636cb27b1478ac64a6f0f4df9508a5f4ad6f401f200762050ba2e3a9e
|
7
|
+
data.tar.gz: 64a835f1bf27b2a783f9e834004c43d2c8588b3df22468d5c795e9f6b273d70d1ae8b2645ffab7ff2b23cc8567a0af7d60c37b9136463f0e93378ff965ed0139
|
@@ -273,10 +273,11 @@ module Switchman
|
|
273
273
|
end
|
274
274
|
|
275
275
|
module AutosaveAssociation
|
276
|
-
def
|
277
|
-
|
278
|
-
|
279
|
-
|
276
|
+
def association_foreign_key_changed?(reflection, record, key)
|
277
|
+
return false if reflection.through_reflection?
|
278
|
+
|
279
|
+
# have to use send instead of _read_attribute because sharding
|
280
|
+
record.has_attribute?(reflection.foreign_key) && record.send(reflection.foreign_key) != key
|
280
281
|
end
|
281
282
|
|
282
283
|
def save_belongs_to_association(reflection)
|
data/lib/switchman/shard.rb
CHANGED
@@ -120,7 +120,8 @@ module Switchman
|
|
120
120
|
# forking.
|
121
121
|
# exception: - :ignore, :raise, :defer (wait until the end and raise the first
|
122
122
|
# error), or a proc
|
123
|
-
|
123
|
+
# output: - :simple, :decorated (with database_server_id:shard_name)
|
124
|
+
def with_each_shard(*args, parallel: false, exception: :raise, output: :simple)
|
124
125
|
raise ArgumentError, "wrong number of arguments (#{args.length} for 0...2)" if args.length > 2
|
125
126
|
|
126
127
|
return Array.wrap(yield) unless default.is_a?(Shard)
|
@@ -164,20 +165,21 @@ module Switchman
|
|
164
165
|
parent_process_name = `ps -ocommand= -p#{Process.pid}`.slice(/#{$0}.*/)
|
165
166
|
ret = ::Parallel.map(scopes, in_processes: scopes.length > 1 ? parallel : 0) do |server, subscope|
|
166
167
|
name = server.id
|
167
|
-
|
168
|
-
|
169
|
-
$stderr = Parallel::PrefixingIO.new(name, STDERR)
|
170
|
-
# rubocop:enable Style/GlobalStdStream
|
168
|
+
last_description = name
|
169
|
+
|
171
170
|
begin
|
172
171
|
max_length = 128 - name.length - 3
|
173
172
|
short_parent_name = parent_process_name[0..max_length] if max_length >= 0
|
174
173
|
new_title = [short_parent_name, name].join(' ')
|
175
174
|
Process.setproctitle(new_title)
|
176
175
|
Switchman.config[:on_fork_proc]&.call
|
177
|
-
with_each_shard(subscope, classes, exception: exception,
|
176
|
+
with_each_shard(subscope, classes, exception: exception, output: :decorated) do
|
177
|
+
last_description = Shard.current.description
|
178
|
+
Parallel::ResultWrapper.new(yield)
|
179
|
+
end
|
178
180
|
rescue => e
|
179
181
|
logger.error e.full_message
|
180
|
-
Parallel::QuietExceptionWrapper.new(
|
182
|
+
Parallel::QuietExceptionWrapper.new(last_description, ::Parallel::ExceptionWrapper.new(e))
|
181
183
|
end
|
182
184
|
end.flatten
|
183
185
|
|
@@ -195,14 +197,20 @@ module Switchman
|
|
195
197
|
|
196
198
|
classes ||= []
|
197
199
|
|
198
|
-
previous_shard = nil
|
199
200
|
result = []
|
200
201
|
ex = nil
|
202
|
+
old_stdout = $stdout
|
203
|
+
old_stderr = $stderr
|
201
204
|
scope.each do |shard|
|
202
205
|
# shard references a database server that isn't configured in this environment
|
203
206
|
next unless shard.database_server
|
204
207
|
|
205
208
|
shard.activate(*classes) do
|
209
|
+
if output == :decorated
|
210
|
+
$stdout = Parallel::PrefixingIO.new(shard.description, $stdout)
|
211
|
+
$stderr = Parallel::PrefixingIO.new(shard.description, $stderr)
|
212
|
+
end
|
213
|
+
|
206
214
|
result.concat Array.wrap(yield)
|
207
215
|
rescue
|
208
216
|
case exception
|
@@ -216,8 +224,10 @@ module Switchman
|
|
216
224
|
else
|
217
225
|
raise
|
218
226
|
end
|
227
|
+
ensure
|
228
|
+
$stdout = old_stdout
|
229
|
+
$stderr = old_stderr
|
219
230
|
end
|
220
|
-
previous_shard = shard
|
221
231
|
end
|
222
232
|
raise ex if ex
|
223
233
|
|
data/lib/switchman/version.rb
CHANGED
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: 3.3.
|
4
|
+
version: 3.3.3
|
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: 2023-03-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -300,7 +300,7 @@ licenses:
|
|
300
300
|
- MIT
|
301
301
|
metadata:
|
302
302
|
rubygems_mfa_required: 'true'
|
303
|
-
post_install_message:
|
303
|
+
post_install_message:
|
304
304
|
rdoc_options: []
|
305
305
|
require_paths:
|
306
306
|
- lib
|
@@ -315,8 +315,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
315
315
|
- !ruby/object:Gem::Version
|
316
316
|
version: '0'
|
317
317
|
requirements: []
|
318
|
-
rubygems_version: 3.
|
319
|
-
signing_key:
|
318
|
+
rubygems_version: 3.1.6
|
319
|
+
signing_key:
|
320
320
|
specification_version: 4
|
321
321
|
summary: Rails sharding magic
|
322
322
|
test_files: []
|