Class: ActiveRecord::ConnectionAdapters::MysqlFlexmasterAdapter
- Inherits:
-
Mysql2Adapter
- Object
- Mysql2Adapter
- ActiveRecord::ConnectionAdapters::MysqlFlexmasterAdapter
show all
- Defined in:
- lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb
Defined Under Namespace
Classes: NoActiveMasterException, NoServerAvailableException, TooManyMastersException
Constant Summary
collapse
- CHECK_EVERY_N_SELECTS =
10
- DEFAULT_CONNECT_TIMEOUT =
1
- DEFAULT_CONNECT_ATTEMPTS =
3
- DEFAULT_TX_HOLD_TIMEOUT =
5
Instance Method Summary
collapse
Constructor Details
Returns a new instance of MysqlFlexmasterAdapter.
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 36
def initialize(logger, config)
@select_counter = 0
@config = config
@rw = config[:slave] ? :read : :write
@tx_hold_timeout = @config[:tx_hold_timeout] || DEFAULT_TX_HOLD_TIMEOUT
@connection_timeout = @config[:connection_timeout] || DEFAULT_CONNECT_TIMEOUT
@connection_attempts = @config[:connection_attempts] || DEFAULT_CONNECT_ATTEMPTS
connection = find_correct_host(@rw)
raise_no_server_available! unless connection
super(connection, logger, [], config)
end
|
Instance Method Details
#begin_db_transaction ⇒ Object
50
51
52
53
54
55
|
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 50
def begin_db_transaction
if !in_transaction?
with_lost_cx_guard { hard_verify }
end
super
end
|
#current_host ⇒ Object
89
90
91
|
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 89
def current_host
@connection.query_options[:host]
end
|
#current_port ⇒ Object
93
94
95
|
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 93
def current_port
@connection.query_options[:port]
end
|
#execute(sql, name = nil) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 57
def execute(sql, name = nil)
if in_transaction?
super else
with_lost_cx_guard do
if has_side_effects?(sql)
hard_verify
else
soft_verify
end
super
end
end
end
|
#quote(*args) ⇒ Object
after a cluster recovers from a bad state, an insert or SELECT will bring us back into sanity, but sometimes would we never get there and would get stuck crashing in this function instead.
75
76
77
78
79
80
|
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 75
def quote(*args)
if !@connection
soft_verify
end
super
end
|
#quote_string(*args) ⇒ Object
82
83
84
85
86
87
|
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 82
def quote_string(*args)
if !@connection
soft_verify
end
super
end
|