Class: ActiveRecord::ConnectionAdapters::MysqlFlexmasterAdapter

Inherits:
Mysql2Adapter
  • Object
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

#initialize(logger, config) ⇒ MysqlFlexmasterAdapter

Returns a new instance of MysqlFlexmasterAdapter.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 34

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_transactionObject



48
49
50
51
52
53
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 48

def begin_db_transaction
  if !in_transaction?
    with_lost_cx_guard { hard_verify }
  end
  super
end

#current_hostObject



87
88
89
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 87

def current_host
  @connection.query_options[:host]
end

#current_portObject



91
92
93
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 91

def current_port
  @connection.query_options[:port]
end

#execute(sql, name = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 55

def execute(sql, name = nil)
  if in_transaction?
    super # no way to rescue any lost cx or wrong-host errors at this point.
  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.



73
74
75
76
77
78
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 73

def quote(*args)
  if !@connection
    soft_verify
  end
  super
end

#quote_string(*args) ⇒ Object



80
81
82
83
84
85
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 80

def quote_string(*args)
  if !@connection
    soft_verify
  end
  super
end