class Lhm::AtomicSwitcher
Switches origin with destination table using an atomic rename.
It should only be used if the MySQL server version is not affected by the bin log affecting bug #39675. This can be verified using Lhm::SqlHelper.supports_atomic_switch?
.
Attributes
connection[R]
Public Class Methods
new(migration, connection = nil, options = {})
click to toggle source
# File lib/lhm/atomic_switcher.rb, line 19 def initialize(migration, connection = nil, options = {}) @migration = migration @connection = connection @origin = migration.origin @destination = migration.destination @retry_helper = SqlRetry.new( @connection, { log_prefix: "AtomicSwitcher" }.merge!(options.fetch(:retriable, {})) ) end
Public Instance Methods
atomic_switch()
click to toggle source
# File lib/lhm/atomic_switcher.rb, line 32 def atomic_switch "rename table `#{ @origin.name }` to `#{ @migration.archive_name }`, " \ "`#{ @destination.name }` to `#{ @origin.name }`" end
validate()
click to toggle source
# File lib/lhm/atomic_switcher.rb, line 37 def validate unless @connection.data_source_exists?(@origin.name) && @connection.data_source_exists?(@destination.name) error "`#{ @origin.name }` and `#{ @destination.name }` must exist" end end
Private Instance Methods
execute()
click to toggle source
# File lib/lhm/atomic_switcher.rb, line 46 def execute @retry_helper.with_retries do |retriable_connection| retriable_connection.execute atomic_switch end end