Module: Lhm
- Included in:
- Lhm
- Defined in:
- lib/lhm.rb,
lib/lhm/table.rb,
lib/lhm/chunker.rb,
lib/lhm/command.rb,
lib/lhm/invoker.rb,
lib/lhm/printer.rb,
lib/lhm/railtie.rb,
lib/lhm/version.rb,
lib/lhm/migrator.rb,
lib/lhm/entangler.rb,
lib/lhm/migration.rb,
lib/lhm/sql_retry.rb,
lib/lhm/throttler.rb,
lib/lhm/timestamp.rb,
lib/lhm/connection.rb,
lib/lhm/sql_helper.rb,
lib/lhm/table_name.rb,
lib/lhm/chunk_finder.rb,
lib/lhm/chunk_insert.rb,
lib/lhm/intersection.rb,
lib/lhm/test_support.rb,
lib/lhm/throttler/time.rb,
lib/lhm/atomic_switcher.rb,
lib/lhm/cleanup/current.rb,
lib/lhm/locked_switcher.rb,
lib/lhm/proxysql_helper.rb,
lib/lhm/throttler/slave_lag.rb,
lib/lhm/throttler/replica_lag.rb,
lib/lhm/throttler/threads_running.rb,
lib/lhm/throttler/backoff_reduction.rb
Overview
Copyright © 2011 - 2013, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias Schmidt
Defined Under Namespace
Modules: Cleanup, Command, Printer, ProxySQLHelper, SqlHelper, TestInvoker, TestMigrator, Throttler Classes: AtomicSwitcher, ChunkFinder, ChunkInsert, Chunker, Connection, Entangler, Error, Intersection, Invoker, LockedSwitcher, Migration, Migrator, Railtie, SqlRetry, Table, TableName, Timestamp
Constant Summary collapse
- DEFAULT_LOGGER_OPTIONS =
{ level: Logger::INFO, file: STDOUT }
- VERSION =
'4.4.2'
Constants included from Throttler
Class Method Summary collapse
-
.execute_inline! ⇒ Object
Patch LHM to execute ALTER TABLE directly on original tables, without the online migration dance.
- .logger ⇒ Object
- .logger=(new_logger) ⇒ Object
Instance Method Summary collapse
-
#change_table(table_name, options = {}) {|Migrator| ... } ⇒ Boolean
Alters a table with the changes described in the block.
-
#cleanup(run = false, options = {}) ⇒ Object
Cleanup tables and triggers.
- #cleanup_current_run(run, table_name, options = {}) ⇒ Object
-
#connection ⇒ Object
Returns DB connection (or initializes it if not created yet).
-
#setup(connection) ⇒ Object
Setups DB connection.
Methods included from Throttler
format_hosts, setup_throttler, throttler
Class Method Details
.execute_inline! ⇒ Object
Patch LHM to execute ALTER TABLE directly on original tables, without the online migration dance. This mode is designed for local/CI environments where we can speed things up by not invoking “real” LHM logic.
31 32 33 34 |
# File 'lib/lhm/test_support.rb', line 31 def self.execute_inline! Lhm::Migrator.prepend(TestMigrator) Lhm::Invoker.prepend(TestInvoker) end |
.logger ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/lhm.rb', line 109 def self.logger @@logger ||= begin logger = Logger.new(DEFAULT_LOGGER_OPTIONS[:file]) logger.level = DEFAULT_LOGGER_OPTIONS[:level] logger.formatter = nil logger end end |
.logger=(new_logger) ⇒ Object
105 106 107 |
# File 'lib/lhm.rb', line 105 def self.logger=(new_logger) @@logger = new_logger end |
Instance Method Details
#change_table(table_name, options = {}) {|Migrator| ... } ⇒ Boolean
Alters a table with the changes described in the block
54 55 56 57 58 59 60 61 62 |
# File 'lib/lhm.rb', line 54 def change_table(table_name, = {}, &block) with_flags() do origin = Table.parse(table_name, connection) invoker = Invoker.new(origin, connection) block.call(invoker.migrator) invoker.run() true end end |
#cleanup(run = false, options = {}) ⇒ Object
Cleanup tables and triggers
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/lhm.rb', line 70 def cleanup(run = false, = {}) lhm_tables = connection.select_values('show tables').select { |name| name =~ /^lhm(a|n)_/ } if [:until] lhm_tables.select! do |table| table_date_time = Time.strptime(table, 'lhma_%Y_%m_%d_%H_%M_%S') table_date_time <= [:until] end end lhm_triggers = connection.select_values('show triggers').collect do |trigger| trigger.respond_to?(:trigger) ? trigger.trigger : trigger end.select { |name| name =~ /^lhmt/ } drop_tables_and_triggers(run, lhm_triggers, lhm_tables) end |
#cleanup_current_run(run, table_name, options = {}) ⇒ Object
86 87 88 |
# File 'lib/lhm.rb', line 86 def cleanup_current_run(run, table_name, = {}) Lhm::Cleanup::Current.new(run, table_name, connection, ).execute end |
#connection ⇒ Object
Returns DB connection (or initializes it if not created yet)
98 99 100 101 102 103 |
# File 'lib/lhm.rb', line 98 def connection @@connection ||= begin raise 'Please call Lhm.setup' unless defined?(ActiveRecord) @@connection = Connection.new(connection: ActiveRecord::Base.connection) end end |
#setup(connection) ⇒ Object
Setups DB connection
93 94 95 |
# File 'lib/lhm.rb', line 93 def setup(connection) @@connection = Connection.new(connection: connection) end |