switchman 1.5.18 → 1.5.19

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
  SHA1:
3
- metadata.gz: 72cd0fd10611a4acc7c12f46ca25435689d9f3ea
4
- data.tar.gz: 80a15da1b891e2945bf6c2ceb80c0bd95693d63f
3
+ metadata.gz: 65bb936a3b1c3df9044c0c8429a6e7b01b0bafb3
4
+ data.tar.gz: a1e4e5e2c846e10fd95f1916a175b5327e4429d1
5
5
  SHA512:
6
- metadata.gz: 819f32885454df751e646e995b859b8ceb5549bb74f7f8e8dd4a0445c5423cb25ffccbf8dc84da32304f299e619469e9c1540af66537952751d5b3e31ee09384
7
- data.tar.gz: a727cc6b22e0fb123adaf6514ccba6eb1330d9fa96e0410280bb063132852738f9dfe4d198caf271651ea4f0d6f7a1b0b23d20e7c5ec157e790cc6e59d484dba
6
+ metadata.gz: 3d7888becfe60dd1e14255cfca4c3492268ea4048133819a2aa40de66c696b0dd6c4965c66eb82bb68603346afdc43b3f5b8ee636da2ff36a58db7bd0628a52c
7
+ data.tar.gz: bf563c2246872f3afb630f93e08906b55f8e6e7f63a92cd0c765cd87a1fb21120634b375a011fa5b29793c293400ccc96bca83d4796025d15d6985ccc138825f
@@ -249,14 +249,20 @@ module Switchman
249
249
  end
250
250
  end
251
251
 
252
+ # only one process; don't bother forking
253
+ if scopes.length == 1 && parallel == 1
254
+ return with_each_shard(subscopes.first, categories, options) { yield }
255
+ end
256
+
257
+ # clear connections prior to forking (no more queries will be executed in the parent,
258
+ # and we want them gone so that we don't accidentally use them post-fork doing something
259
+ # silly like dealloc'ing prepared statements)
260
+ ::ActiveRecord::Base.clear_all_connections!
261
+
252
262
  scopes.each do |server, subscopes|
253
263
  if !(::ActiveRecord::Relation === subscopes.first) && subscopes.first.class != Array
254
264
  subscopes = [subscopes]
255
265
  end
256
- # only one process; don't bother forking
257
- if scopes.length == 1 && subscopes.length == 1
258
- return with_each_shard(subscopes.first, categories, options) { yield }
259
- end
260
266
 
261
267
  subscopes.each_with_index do |subscope, idx|
262
268
  if subscopes.length > 1
@@ -269,13 +275,23 @@ module Switchman
269
275
  exception_pipes << exception_pipe
270
276
  pid, io_in, io_out, io_err = Open4.pfork4(lambda do
271
277
  begin
272
- ::ActiveRecord::Base.clear_all_connections!
273
278
  Switchman.config[:on_fork_proc].try(:call)
274
279
  $0 = [$0, ARGV, name].flatten.join(' ')
275
280
  with_each_shard(subscope, categories, options) { yield }
276
281
  exception_pipe.last.close
277
- rescue Exception => e
278
- Marshal.dump(e, exception_pipe.last)
282
+ rescue => e
283
+ begin
284
+ dumped = Marshal.dump(e)
285
+ rescue
286
+ # couldn't dump the exception; create a copy with just
287
+ # the message and the backtrace
288
+ e2 = e.class.new(e.message)
289
+ e2.set_backtrace(e.backtrace)
290
+ e2.instance_variable_set(:@active_shards, e.instance_variable_get(:@active_shards))
291
+ dumped = Marshal.dump(e2)
292
+ end
293
+ exception_pipe.last.set_encoding(dumped.encoding)
294
+ exception_pipe.last.write(dumped)
279
295
  exception_pipe.last.flush
280
296
  exception_pipe.last.close
281
297
  exit! 1
@@ -311,9 +327,6 @@ module Switchman
311
327
  errors << pid_to_name_map[pid] if status.exitstatus != 0
312
328
  end
313
329
 
314
- # I'm not sure why, but we have to do this
315
- ::ActiveRecord::Base.clear_all_connections!
316
-
317
330
  # check for an exception; we only re-raise the first one
318
331
  exception_pipes.each do |exception_pipe|
319
332
  begin
@@ -52,7 +52,7 @@ module Switchman
52
52
  arel, binds = binds_from_relation(arel, binds)
53
53
  sql = to_sql(arel, binds)
54
54
  if ::Rails.version >= '5'
55
- cache_sql(sql, binds) { super(sql, name, binds, preparable: visitor.preparable) }
55
+ cache_sql(sql, binds) { super(sql, name, binds, preparable: preparable) }
56
56
  else
57
57
  cache_sql(sql, binds) { super(sql, name, binds) }
58
58
  end
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.5.18"
2
+ VERSION = "1.5.19"
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.5.18
4
+ version: 1.5.19
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: 2016-08-23 00:00:00.000000000 Z
13
+ date: 2016-08-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties