Class: Lhm::Invoker

Inherits:
Object
  • Object
show all
Includes:
SqlHelper
Defined in:
lib/lhm/invoker.rb

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 =
-2

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SqlHelper

#annotation, #idx_name, #idx_spec, #tagged, #version_string

Constructor Details

#initialize(origin, connection) ⇒ Invoker

Returns a new instance of Invoker


22
23
24
25
# File 'lib/lhm/invoker.rb', line 22

def initialize(origin, connection)
  @connection = connection
  @migrator = Migrator.new(origin, connection)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection


20
21
22
# File 'lib/lhm/invoker.rb', line 20

def connection
  @connection
end

#migratorObject (readonly)

Returns the value of attribute migrator


20
21
22
# File 'lib/lhm/invoker.rb', line 20

def migrator
  @migrator
end

Instance Method Details

#run(options = {}) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/lhm/invoker.rb', line 40

def run(options = {})
  normalize_options(options)
  set_session_lock_wait_timeouts
  migration = @migrator.run

  Entangler.new(migration, @connection).run do
    Chunker.new(migration, @connection, options).run
    if options[:atomic_switch]
      AtomicSwitcher.new(migration, @connection).run
    else
      LockedSwitcher.new(migration, @connection).run
    end
  end
end

#set_session_lock_wait_timeoutsObject


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lhm/invoker.rb', line 27

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
    @connection.execute("SET SESSION innodb_lock_wait_timeout=#{global_innodb_lock_wait_timeout['Value'].to_i + LOCK_WAIT_TIMEOUT_DELTA}")
  end

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