Class: Lhm::Throttler::Replica
- Inherits:
-
Object
- Object
- Lhm::Throttler::Replica
- Defined in:
- lib/lhm/throttler/replica_lag.rb
Constant Summary collapse
- SQL_SELECT_REPLICA_HOSTS =
"SELECT host FROM information_schema.processlist WHERE command LIKE 'Binlog Dump%'"
- SQL_SELECT_MAX_REPLICA_LAG =
'SHOW SLAVE STATUS'
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(host, connection_config = nil) ⇒ Replica
constructor
A new instance of Replica.
- #lag ⇒ Object
- #replica_hosts ⇒ Object
Constructor Details
#initialize(host, connection_config = nil) ⇒ Replica
Returns a new instance of Replica.
105 106 107 108 109 |
# File 'lib/lhm/throttler/replica_lag.rb', line 105 def initialize(host, connection_config = nil) @host = host @connection_config = prepare_connection_config(connection_config) @connection = client(@connection_config) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
95 96 97 |
# File 'lib/lhm/throttler/replica_lag.rb', line 95 def connection @connection end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
95 96 97 |
# File 'lib/lhm/throttler/replica_lag.rb', line 95 def host @host end |
Class Method Details
.client ⇒ Object
97 98 99 |
# File 'lib/lhm/throttler/replica_lag.rb', line 97 def self.client defined?(Mysql2::Client) ? Mysql2::Client : Trilogy end |
.client_error ⇒ Object
101 102 103 |
# File 'lib/lhm/throttler/replica_lag.rb', line 101 def self.client_error defined?(Mysql2::Error) ? Mysql2::Error : Trilogy::Error end |
Instance Method Details
#lag ⇒ Object
115 116 117 |
# File 'lib/lhm/throttler/replica_lag.rb', line 115 def lag query_connection(SQL_SELECT_MAX_REPLICA_LAG, 'Seconds_Behind_Master').first.to_i end |
#replica_hosts ⇒ Object
111 112 113 |
# File 'lib/lhm/throttler/replica_lag.rb', line 111 def replica_hosts Throttler.format_hosts(query_connection(SQL_SELECT_REPLICA_HOSTS, 'host')) end |