ar_mysql_flexmaster 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
data/ar_mysql_flexmaster.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
13
|
gem.name = "ar_mysql_flexmaster"
|
14
14
|
gem.require_paths = ["lib"]
|
15
|
-
gem.version = "0.4.
|
15
|
+
gem.version = "0.4.3"
|
16
16
|
|
17
17
|
gem.add_runtime_dependency("mysql2")
|
18
18
|
gem.add_runtime_dependency("activerecord")
|
@@ -68,6 +68,15 @@ module ActiveRecord
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
+
# after a cluster recovers from a bad state, an insert or SELECT will bring us back
|
72
|
+
# into sanity, but sometimes would we never get there and would get stuck crashing in this function instead.
|
73
|
+
def quote(*args)
|
74
|
+
if !@connection
|
75
|
+
soft_verify
|
76
|
+
end
|
77
|
+
super
|
78
|
+
end
|
79
|
+
|
71
80
|
def current_host
|
72
81
|
@connection.query_options[:host]
|
73
82
|
end
|
data/test/ar_flexmaster_test.rb
CHANGED
@@ -191,25 +191,52 @@ class TestArFlexmaster < Test::Unit::TestCase
|
|
191
191
|
ActiveRecord::Base.configurations["test"]["hosts"].pop
|
192
192
|
end
|
193
193
|
|
194
|
-
def
|
194
|
+
def test_limping_along_with_a_slave_acting_as_a_master
|
195
195
|
User.create!
|
196
|
-
UserSlave.first
|
197
|
-
|
198
196
|
$mysql_master.down!
|
199
197
|
|
200
|
-
#
|
201
|
-
|
198
|
+
# the test here is that even though we've asserted we want the master,
|
199
|
+
# since we're doing a SELECT we'll stay limping along by running the SELECT on a slave instead.
|
200
|
+
User.first
|
201
|
+
|
202
|
+
assert [$mysql_slave, $mysql_slave_2].include?(master_connection)
|
203
|
+
ensure
|
204
|
+
$mysql_master.up!
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_recovering_after_losing_connection_to_the_master
|
208
|
+
User.create!
|
209
|
+
assert User.connection.instance_variable_get("@connection")
|
202
210
|
|
203
|
-
|
204
|
-
#
|
211
|
+
$mysql_master.down!
|
212
|
+
# trying to do an INSERT with the master down puts is into a precious state --
|
213
|
+
# we've got a nil @connection object. There's two possible solutions here;
|
214
|
+
#
|
215
|
+
# 1 - substitute a slave connection in for the master object but raise an exception anyway
|
216
|
+
# 2 - deal with a nil connection object later
|
217
|
+
#
|
218
|
+
# opting for (2) now
|
219
|
+
#
|
205
220
|
assert_raises(ActiveRecord::ConnectionAdapters::MysqlFlexmasterAdapter::NoServerAvailableException) do
|
206
221
|
User.create!
|
207
222
|
end
|
208
223
|
|
209
|
-
|
210
|
-
User.first
|
224
|
+
assert_equal nil, User.connection.instance_variable_get("@connection")
|
211
225
|
|
212
|
-
|
226
|
+
# this proxies to @connection and has been the cause of some crashes
|
227
|
+
assert User.connection.quote("foo")
|
228
|
+
ensure
|
229
|
+
$mysql_master.up!
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_recovering_after_the_master_is_back_up
|
233
|
+
User.create!
|
234
|
+
$mysql_master.down!
|
235
|
+
|
236
|
+
assert_raises(ActiveRecord::ConnectionAdapters::MysqlFlexmasterAdapter::NoServerAvailableException) do
|
237
|
+
User.create!
|
238
|
+
end
|
239
|
+
# bad state again.
|
213
240
|
|
214
241
|
# now a dba or someone comes along and flips the read-only bit on the slave
|
215
242
|
$mysql_slave.set_rw(true)
|