rails_failover 0.5.1 → 0.5.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de312681fb912d8d00ffaaf362f8c2201a95066660759aa92393d3212753e6c9
4
- data.tar.gz: 006af26908149488773d664dea57d761ff24304516ae7b65139b20d288f0ab85
3
+ metadata.gz: c3a3ec0058f66ac60c355117284cc6c3ef9edbde71d74d966e38c2e10d38b828
4
+ data.tar.gz: dbfbe03fe13a70ecbc32729ce47223e41b4d9c53d6baeb42df296391490b6116
5
5
  SHA512:
6
- metadata.gz: 634c701d2d4ba73e4b45efed2de949797521c7d390586eeec412f3d6749d93b446bde1b51b53ddc37a41d0e3e79d18902a154a22e07f1bad8528d365822f0614
7
- data.tar.gz: 7c4126b04c1792cb26c98f3532e3cc815d0aaca6aed9cda20831315f826075b362d23d5863c942415a018157553e156e24c9dff128751ea5138c59f6799efecd
6
+ metadata.gz: 7283bd61a7804eb4b5e501e03b71343c620e84f3b334665783a99d8c19fb135d5f49bb97d2f537938d4e73427086c7815981eb4c684b7ed3a38befd878014753
7
+ data.tar.gz: 3856f52865af591c157d29b0613382dd54a4614cc943313f373077db4ab950beaaba953f696faf7298304c283123e0b40ff48d29ea4d8672025ff7d49e778b1f
@@ -0,0 +1,42 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.5.6] - 2020-09-14
10
+
11
+ - FIX: Iteration and mutation of primaries_down in separate threads (#5)
12
+
13
+ Ruby hashes can't be modified whilst they are being iterated over.
14
+
15
+ Here, the primaries_down hash is iterated over to check each previously
16
+ unavailable primary to see if it is now contactable. However, since this
17
+ hash can be updated in other threads, this iteration isn't safe.
18
+
19
+ To prevent this, a copy of the hash is iterated over instead.
20
+
21
+ The GIL should not be released during a hash dup [1], but let's not tie
22
+ ourselves unnecessarily to current MRI behaviour.
23
+
24
+ [1]: https://github.com/ruby-concurrency/concurrent-ruby/issues/528
25
+
26
+
27
+ ## [0.5.5] - 2020-08-04
28
+
29
+ - FIX: Rescue from `Redis::TimeoutError` instead of `Timeout::Error`.
30
+
31
+ ## [0.5.4] - 2020-07-21
32
+
33
+ - FIX: Undefined method on nil class error in forking servers.
34
+
35
+ ## [0.5.3] - 2020-07-20
36
+
37
+ - FIX: Incorrectly rescuing from `PG::ServerError`.
38
+
39
+ ## [0.5.2] - 2020-06-23
40
+
41
+ ### Changed
42
+ - FIX: Only rescue from connection errors.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_failover (0.5.1)
4
+ rails_failover (0.5.6)
5
5
  activerecord (~> 6.0)
6
6
  railties (~> 6.0)
7
7
 
@@ -41,19 +41,19 @@ GEM
41
41
  erubi (1.9.0)
42
42
  i18n (1.8.2)
43
43
  concurrent-ruby (~> 1.0)
44
- loofah (2.5.0)
44
+ loofah (2.7.0)
45
45
  crass (~> 1.0.2)
46
46
  nokogiri (>= 1.5.9)
47
47
  method_source (1.0.0)
48
48
  mini_portile2 (2.4.0)
49
49
  minitest (5.14.1)
50
- nokogiri (1.10.9)
50
+ nokogiri (1.10.10)
51
51
  mini_portile2 (~> 2.4.0)
52
52
  parallel (1.19.1)
53
53
  parser (2.7.1.2)
54
54
  ast (~> 2.4.0)
55
55
  pg (1.2.3)
56
- rack (2.2.2)
56
+ rack (2.2.3)
57
57
  rack-test (1.1.0)
58
58
  rack (>= 1.0, < 3)
59
59
  rails-dom-testing (2.0.3)
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Automatic failover and recovery for primary/replica setup for:
4
4
 
5
5
  1. Redis
6
- 1. ActiveRecord (PostgreSQL/MySQL)
6
+ 1. ActiveRecord (PostgreSQL/MySQL Adapters)
7
7
 
8
8
  ## Installation
9
9
 
@@ -3,18 +3,20 @@
3
3
  module RailsFailover
4
4
  module ActiveRecord
5
5
  class Interceptor
6
- def self.adapter_error
7
- @adapter_error ||= begin
6
+ def self.adapter_errors
7
+ @adapter_errors ||= begin
8
8
  if defined?(::PG)
9
- ::PG::Error
9
+ [::PG::UnableToSend, ::PG::ConnectionBad]
10
10
  elsif defined?(::Mysql2)
11
- ::Mysql2::Error
11
+ [::Mysql2::Error::ConnectionError]
12
12
  end
13
13
  end
14
14
  end
15
15
 
16
16
  def self.handle(request, exception)
17
- if (resolve_cause(exception).is_a?(adapter_error))
17
+ exception = resolve_cause(exception)
18
+
19
+ if adapter_errors.any? { |error| exception.is_a?(error) }
18
20
  Handler.instance.verify_primary(request.env[Middleware::WRITING_ROLE_HEADER])
19
21
  end
20
22
  end
@@ -11,7 +11,7 @@ module RailsFailover
11
11
  options[:driver] = Class.new(options[:driver]) do
12
12
  def self.connect(options)
13
13
  super(options)
14
- rescue Timeout::Error,
14
+ rescue ::Redis::TimeoutError,
15
15
  SocketError,
16
16
  Errno::EADDRNOTAVAIL,
17
17
  Errno::ECONNREFUSED,
@@ -63,7 +63,7 @@ module RailsFailover
63
63
 
64
64
  active_primaries_keys = {}
65
65
 
66
- primaries_down.each do |key, options|
66
+ mon_synchronize { primaries_down.dup }.each do |key, options|
67
67
  info = nil
68
68
  options = options.dup
69
69
 
@@ -163,7 +163,7 @@ module RailsFailover
163
163
  @primaries_down[process_pid] = @primaries_down[@ancestor_pid] || {}
164
164
 
165
165
  if process_pid != @ancestor_pid
166
- @primaries_down.delete(@ancestor_pid).each do |id, options|
166
+ @primaries_down.delete(@ancestor_pid)&.each do |id, options|
167
167
  verify_primary(options)
168
168
  end
169
169
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsFailover
4
- VERSION = "0.5.1"
4
+ VERSION = "0.5.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_failover
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Tan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-16 00:00:00.000000000 Z
11
+ date: 2020-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -49,6 +49,7 @@ files:
49
49
  - ".rspec"
50
50
  - ".rubocop.yml"
51
51
  - ".travis.yml"
52
+ - CHANGELOG.md
52
53
  - CODE_OF_CONDUCT.md
53
54
  - Gemfile
54
55
  - Gemfile.lock