Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/lhm/invoker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ module Lhm
# and replaced by destination.
class Invoker
include SqlHelper
LOCK_WAIT_TIMEOUT_DELTA = -2
LOCK_WAIT_TIMEOUT_DELTA = 10
INNODB_LOCK_WAIT_TIMEOUT_MAX=1073741824.freeze # https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_lock_wait_timeout
LOCK_WAIT_TIMEOUT_MAX=31536000.freeze # https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html

attr_reader :migrator, :connection

Expand All @@ -29,11 +31,17 @@ def set_session_lock_wait_timeouts
global_lock_wait_timeout = @connection.select_one("SHOW GLOBAL VARIABLES LIKE 'lock_wait_timeout'")

if global_innodb_lock_wait_timeout
@connection.execute("SET SESSION innodb_lock_wait_timeout=#{global_innodb_lock_wait_timeout['Value'].to_i + LOCK_WAIT_TIMEOUT_DELTA}")
desired_innodb_lock_wait_timeout = global_innodb_lock_wait_timeout['Value'].to_i + LOCK_WAIT_TIMEOUT_DELTA
if desired_innodb_lock_wait_timeout <= INNODB_LOCK_WAIT_TIMEOUT_MAX
@connection.execute("SET SESSION innodb_lock_wait_timeout=#{desired_innodb_lock_wait_timeout}")
end
end

if global_lock_wait_timeout
@connection.execute("SET SESSION lock_wait_timeout=#{global_lock_wait_timeout['Value'].to_i + LOCK_WAIT_TIMEOUT_DELTA}")
desired_lock_wait_timeout = global_lock_wait_timeout['Value'].to_i + LOCK_WAIT_TIMEOUT_DELTA
if desired_lock_wait_timeout <= LOCK_WAIT_TIMEOUT_MAX
@connection.execute("SET SESSION lock_wait_timeout=#{desired_lock_wait_timeout}")
end
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/integration/lock_wait_timeout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

it 'set_session_lock_wait_timeouts should set the sessions lock wait timeouts to less than the global values by a delta' do
connection = Lhm.send(:connection)
connection.execute('SET GLOBAL innodb_lock_wait_timeout=11')
connection.execute('SET GLOBAL lock_wait_timeout=11')
connection.execute('SET SESSION innodb_lock_wait_timeout=1')
connection.execute('SET SESSION lock_wait_timeout=1')

Expand Down