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.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 37

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



51
52
53
54
55
56
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 51

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

#current_hostObject



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

def current_host
  @connection.query_options[:host]
end

#current_portObject



94
95
96
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 94

def current_port
  @connection.query_options[:port]
end

#execute(sql, name = nil) ⇒ Object



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

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.



76
77
78
79
80
81
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 76

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

#quote_string(*args) ⇒ Object



83
84
85
86
87
88
# File 'lib/active_record/connection_adapters/mysql_flexmaster_adapter.rb', line 83

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