slave_pools 1.0.0.rc4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/lib/slave_pools/config.rb +6 -0
- data/lib/slave_pools/connection_proxy.rb +7 -4
- data/lib/slave_pools/engine.rb +3 -0
- data/lib/slave_pools/version.rb +1 -1
- data/spec/connection_proxy_spec.rb +7 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0fd6bf772d8b4651a9c582e9e04c079d7fdc788
|
4
|
+
data.tar.gz: 61e8af6660ecb8de50e5160dfba7a90ee3162935
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1063bfd67d77804819728d33e1c13d11daa65c295e1647ee7a2af4acdf115810ec777545964c085feb4b6c86cae78312699c2ff7a11621d37f766eac3407389
|
7
|
+
data.tar.gz: bf754bf16417db1effd756db76bd536a745eb82e6275bb842926888a5f8b2f2e945e55d7db37d12f94a5f1576fe849d0856d09fac1a8836ed59901bfade12626
|
data/README.md
CHANGED
@@ -88,6 +88,17 @@ 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
|
+
|
91
102
|
## Usage
|
92
103
|
|
93
104
|
Toggle to next replica:
|
data/lib/slave_pools/config.rb
CHANGED
@@ -13,10 +13,16 @@ 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
|
+
|
16
21
|
def initialize
|
17
22
|
@environment = 'development'
|
18
23
|
@defaults_to_master = false
|
19
24
|
@safe_methods = []
|
25
|
+
@no_replay_on_master = {}
|
20
26
|
end
|
21
27
|
end
|
22
28
|
end
|
@@ -121,11 +121,14 @@ module SlavePools
|
|
121
121
|
end
|
122
122
|
|
123
123
|
# decides whether to replay query against master based on the
|
124
|
-
# exception
|
124
|
+
# exception and message.
|
125
|
+
# These can be adjusted by setting SlavePools.configs.no_replay_on_master.
|
125
126
|
def safe_to_replay(e)
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
129
132
|
end
|
130
133
|
|
131
134
|
private
|
data/lib/slave_pools/engine.rb
CHANGED
@@ -21,6 +21,9 @@ module SlavePools
|
|
21
21
|
else
|
22
22
|
warn "Unsupported ActiveRecord version #{ActiveRecord.version}. Please whitelist the safe methods."
|
23
23
|
end
|
24
|
+
SlavePools.config.no_replay_on_master = {
|
25
|
+
'Mysql2::Error' => ['Timeout waiting for a response from the last query']
|
26
|
+
}
|
24
27
|
end
|
25
28
|
|
26
29
|
config.after_initialize do
|
data/lib/slave_pools/version.rb
CHANGED
@@ -143,25 +143,20 @@ describe SlavePools do
|
|
143
143
|
@proxy.should respond_to(:unsafe)
|
144
144
|
end
|
145
145
|
|
146
|
-
it 'should
|
147
|
-
|
148
|
-
@
|
149
|
-
@master.should_not_receive(:select_all)
|
150
|
-
lambda { @proxy.select_all(@sql) }.should raise_error
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'should rescue a Mysql::Error fall back to the master' do
|
154
|
-
@default_slave1.should_receive(:select_all).once.and_raise(Mysql2::Error.new('connection error'))
|
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'))
|
155
149
|
@default_slave2.should_not_receive(:select_all)
|
156
150
|
@master.should_receive(:select_all).and_return(true)
|
157
151
|
lambda { @proxy.select_all(@sql) }.should_not raise_error
|
158
152
|
end
|
159
153
|
|
160
|
-
it 'should re-raise a
|
161
|
-
|
154
|
+
it 'should re-raise a Error that is flagged as no replay' do
|
155
|
+
SlavePools.config.no_replay_on_master = {'ArgumentError' => ['random message']}
|
156
|
+
@default_slave1.should_receive(:select_all).once.and_raise(ArgumentError.new('random message'))
|
162
157
|
@default_slave2.should_not_receive(:select_all)
|
163
158
|
@master.should_not_receive(:select_all)
|
164
|
-
lambda { @proxy.select_all(@sql) }.should raise_error
|
159
|
+
lambda { @proxy.select_all(@sql) }.should raise_error(ArgumentError)
|
165
160
|
end
|
166
161
|
|
167
162
|
it 'should reload models from the master' do
|
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.
|
4
|
+
version: 1.1.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-
|
12
|
+
date: 2014-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
version: '1.2'
|
140
140
|
requirements: []
|
141
141
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.0.
|
142
|
+
rubygems_version: 2.0.14
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: Connection proxy for ActiveRecord for master / replica setups.
|