Skip to content

Commit

Permalink
Merge pull request #2 from StayNTouch/CICO-55340
Browse files Browse the repository at this point in the history
CICO-55914 Store slave connections in instance variable to avoid repe…
  • Loading branch information
Arun Murugan authored Jul 25, 2018
2 parents c8b70c1 + 686823b commit 1ab95a7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/lhm/throttler/slave_lag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def initialize(options = {})
@timeout_seconds = INITIAL_TIMEOUT
@stride = options[:stride] || DEFAULT_STRIDE
@allowed_lag = options[:allowed_lag] || DEFAULT_MAX_ALLOWED_LAG
@slave_connections = {}
end

def execute
Expand Down Expand Up @@ -43,6 +42,10 @@ def throttle_seconds
end
end

def slave_connections
@slave_connections ||= slave_hosts.map { |slave_host| slave_connection(slave_host) }
end

def slave_hosts
slaves = get_slaves.map { |slave_host| slave_host.partition(':')[0] }
.delete_if { |slave| slave == 'localhost' || slave == '127.0.0.1' }
Expand All @@ -55,13 +58,12 @@ def get_slaves
end

def max_current_slave_lag
max = slave_hosts.map { |slave| slave_lag(slave) }.flatten.push(0).max
max = slave_connections.map { |slave_connection| slave_lag(slave_connection) }.flatten.push(0).max
Lhm.logger.info "Max current slave lag: #{max}"
max
end

def slave_lag(slave)
conn = slave_connection(slave)
def slave_lag(conn)
if conn.respond_to?(:exec_query)
result = conn.exec_query(SQL_SELECT_MAX_SLAVE_LAG)
result.map { |row| row['Seconds_Behind_Master'].to_i }
Expand Down

0 comments on commit 1ab95a7

Please sign in to comment.