slave_pools 1.1.1 → 1.2.0

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: 1af19658e56521d10ebddd67a970dd7432b92e0e
4
- data.tar.gz: f6c72622c728ad4857350beeaf39ce66c6e69fb4
3
+ metadata.gz: 50f5e7c113601d6c4102dd8660462ae9a1f62330
4
+ data.tar.gz: f0af5c9ca9d4c7bf04e93688d6090374389ff091
5
5
  SHA512:
6
- metadata.gz: 991f5fccf93d7534694dab0f70ce6f13c4bc884f63031941940c110f46448f1d520908d0f4bbb5a9df65d340061403d77f2a00e8b2c82d29acfe01e935580ce2
7
- data.tar.gz: bc84b2d325527d50589cf92eddfc31ee4e5009cfefffe4a8efa75b607e7a590bbb511808bdac7fcb9ad4c6e8163e7cb4bdefef97a14e1aa61d9d799eac5a5300
6
+ metadata.gz: d51b2c0210454fbf3188f7c95ae46556846676bb3d5453ba46a29eef8f374ec75a3c1e16fdbff13f117e22fa953001e9a2db9a1587456008ab9e9fbe376c37a6
7
+ data.tar.gz: db186e0357c7221d768a285e39d666bc3139e15170d9b6b14f78399ab35e8baa657268f751a7faaceb5808347d70019a10c56d85c9faa739743332ed79007a63
data/README.md CHANGED
@@ -88,17 +88,6 @@ Add a `config/initializers/slave_pools.rb` if you want to change config settings
88
88
 
89
89
  SlavePools.config.defaults_to_master = true
90
90
 
91
- #### Configure Errors to not replay on master
92
-
93
- Some errors you may not want to replay on master, e.g. queries that timeout.
94
-
95
- This can be configured by updating the no_replay_on_master with a hash of errors and the corresponding messages that should not be replayed, e.g.:
96
-
97
- SlavePools.config.no_replay_on_master = {
98
- 'Mysql2::Error' => ['Timeout waiting for a response from the last query', 'other error message that you don't want to replay'],
99
- 'TimeoutError' => ['some message']
100
- }
101
-
102
91
  ## Usage
103
92
 
104
93
  Toggle to next replica:
@@ -13,16 +13,10 @@ module SlavePools
13
13
  # Defaults are based on Rails version.
14
14
  attr_accessor :safe_methods
15
15
 
16
- # enter a list of errors/messages that shouldn't fall back to master
17
- # of the form {'ErrorClass' => ['message regex1', 'message regex 2'], }
18
- # Defaults are {'Mysql2::Error' => ['Timeout waiting for a response from the last query']}.
19
- attr_accessor :no_replay_on_master
20
-
21
16
  def initialize
22
17
  @environment = 'development'
23
18
  @defaults_to_master = false
24
19
  @safe_methods = []
25
- @no_replay_on_master = {}
26
20
  end
27
21
  end
28
22
  end
@@ -108,27 +108,9 @@ module SlavePools
108
108
  rescue => e
109
109
  SlavePools.log :error, "Error during ##{method}: #{e}"
110
110
  log_proxy_state
111
- raise if conn == master
112
111
 
113
- if safe_to_replay(e)
114
- SlavePools.log :error, %(#{e.message}\n#{e.backtrace.join("\n")})
115
- SlavePools.log :error, "Replaying on master."
116
- route_to(master, method, *args, &block)
117
- else
118
- current.retrieve_connection.verify! # may reconnect
119
- raise e
120
- end
121
- end
122
-
123
- # decides whether to replay query against master based on the
124
- # exception and message.
125
- # These can be adjusted by setting SlavePools.configs.no_replay_on_master.
126
- def safe_to_replay(e)
127
- return true unless flagged_messages_for_error = SlavePools.config.no_replay_on_master[e.class.to_s]
128
-
129
- return false if flagged_messages_for_error.any? {|m| e.message.match(m)}
130
-
131
- true
112
+ current.retrieve_connection.verify! # may reconnect
113
+ raise e
132
114
  end
133
115
 
134
116
  private
@@ -21,11 +21,6 @@ module SlavePools
21
21
  else
22
22
  warn "Unsupported ActiveRecord version #{ActiveRecord.version}. Please whitelist the safe methods."
23
23
  end
24
- if SlavePools.config.no_replay_on_master.blank?
25
- SlavePools.config.no_replay_on_master = {
26
- 'Mysql2::Error' => ['Timeout waiting for a response from the last query']
27
- }
28
- end
29
24
  end
30
25
 
31
26
  config.after_initialize do
@@ -1,3 +1,3 @@
1
1
  module SlavePools
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -143,16 +143,7 @@ describe SlavePools do
143
143
  @proxy.should respond_to(:unsafe)
144
144
  end
145
145
 
146
- it 'should rescue an error not flagged as no replay' do
147
- SlavePools.config.no_replay_on_master = {'Mysql2::Error' => ['random message']}
148
- @default_slave1.should_receive(:select_all).once.and_raise(Mysql2::Error.new('Timeout waiting for a response'))
149
- @default_slave2.should_not_receive(:select_all)
150
- @master.should_receive(:select_all).and_return(true)
151
- lambda { @proxy.select_all(@sql) }.should_not raise_error
152
- end
153
-
154
- it 'should re-raise a Error that is flagged as no replay' do
155
- SlavePools.config.no_replay_on_master = {'ArgumentError' => ['random message']}
146
+ it 'should not replay errors on master' do
156
147
  @default_slave1.should_receive(:select_all).once.and_raise(ArgumentError.new('random message'))
157
148
  @default_slave2.should_not_receive(:select_all)
158
149
  @master.should_not_receive(:select_all)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slave_pools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Drabik
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-30 00:00:00.000000000 Z
12
+ date: 2014-06-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord