Class: Lhm::Invoker
Overview
Copies an origin table to an altered destination table. Live activity is synchronized into the destination table using triggers.
Once the origin and destination tables have converged, origin is archived and replaced by destination.
Constant Summary collapse
- LOCK_WAIT_TIMEOUT_DELTA =
10
- INNODB_LOCK_WAIT_TIMEOUT_MAX =
1073741824.freeze
- LOCK_WAIT_TIMEOUT_MAX =
31536000.freeze
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#migrator ⇒ Object
readonly
Returns the value of attribute migrator.
Instance Method Summary collapse
-
#initialize(origin, connection) ⇒ Invoker
constructor
A new instance of Invoker.
- #run(options = {}) ⇒ Object
- #set_session_lock_wait_timeouts ⇒ Object
- #triggers_still_exist?(conn, entangler) ⇒ Boolean
Methods included from SqlHelper
#annotation, #idx_name, #idx_spec, #tagged, #version_string
Constructor Details
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
22 23 24 |
# File 'lib/lhm/invoker.rb', line 22 def connection @connection end |
#migrator ⇒ Object (readonly)
Returns the value of attribute migrator.
22 23 24 |
# File 'lib/lhm/invoker.rb', line 22 def migrator @migrator end |
Instance Method Details
#run(options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/lhm/invoker.rb', line 48 def run( = {}) () set_session_lock_wait_timeouts migration = @migrator.run entangler = Entangler.new(migration, @connection) entangler.run do [:verifier] ||= Proc.new { |conn| triggers_still_exist?(conn, entangler) } Chunker.new(migration, @connection, ).run raise "Required triggers do not exist" unless triggers_still_exist?(@connection, entangler) if [:atomic_switch] AtomicSwitcher.new(migration, @connection).run else LockedSwitcher.new(migration, @connection).run end end end |
#set_session_lock_wait_timeouts ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lhm/invoker.rb', line 29 def set_session_lock_wait_timeouts global_innodb_lock_wait_timeout = @connection.select_one("SHOW GLOBAL VARIABLES LIKE 'innodb_lock_wait_timeout'") global_lock_wait_timeout = @connection.select_one("SHOW GLOBAL VARIABLES LIKE 'lock_wait_timeout'") if global_innodb_lock_wait_timeout 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 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 |
#triggers_still_exist?(conn, entangler) ⇒ Boolean
66 67 68 69 |
# File 'lib/lhm/invoker.rb', line 66 def triggers_still_exist?(conn, entangler) triggers = conn.select_values("SHOW TRIGGERS LIKE '%#{migrator.origin.name}'").select { |name| name =~ /^lhmt/ } triggers.sort == entangler.expected_triggers.sort end |