Class: Arrival::CliGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/arrival/cli_generator.rb

Overview

Generates the equivalent Percona’s pt-online-schema-change command to the given SQL statement

–no-check-alter is used to allow running CHANGE COLUMN statements. For more details, check: www.percona.com/doc/percona-toolkit/2.2/pt-online-schema-change.html#cmdoption-pt-online-schema-change–[no]check-alter # rubocop:disable Metrics/LineLength

Constant Summary collapse

COMMAND_NAME =
'gh-ost'.freeze
DEFAULT_OPTIONS =
Set.new(
  [
    Option.new('execute'),
    Option.new('max-load', 'Threads_running=150'),
    Option.new('critical-load', 'Threads_running=4000'),
    Option.new('chunk-size', '1000'),
    Option.new('throttle-control-replicas', 'mysql-replica'),
    Option.new('max-lag-millis', '3000'),
    Option.new('user', 'replica_user'),
    Option.new('password', 'replica_pass'),
    Option.new('host', 'mysql-replica'),
    Option.new('database', 'arrival_test'),
    Option.new('dml-batch-size', '1000'),
    Option.new('alter', '"CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci"'),
    Option.new('assume-rbr'),
    Option.new('cut-over', 'default'),
    Option.new('exact-rowcount'),
    Option.new('concurrent-rowcount'),
    Option.new('default-retries', '1200'),
    Option.new('cut-over-lock-timeout-seconds', '10'),
    Option.new('panic-flag-file', '/tmp/ghost.panic.downloads.flag'),
    Option.new('assume-master-host', 'mysql-main'),
    # Option.new('postpone-cut-over-flag-file', '/tmp/ghost.postpone.downloads.flag'),
    Option.new('verbose'),
  ]
).freeze

Instance Method Summary collapse

Instance Method Details

#generate(_table_name = nil, statement) ⇒ String

Generates the percona command. Fills all the connection credentials from the current AR connection, but that can be amended via ENV-vars: PERCONA_DB_HOST, PERCONA_DB_USER, PERCONA_DB_PASSWORD, PERCONA_DB_NAME Table name can’t not be amended, it populates automatically from the migration data

deprecated: @param table_name [String]

Parameters:

  • statement (String)

    MySQL statement

Returns:

  • (String)


51
52
53
54
55
# File 'lib/arrival/cli_generator.rb', line 51

def generate(_table_name=nil, statement)
  alter_argument = AlterArgument.new(statement)

  "#{command} #{all_options} #{alter_argument} #{Option.new("table", alter_argument.table_name)}"
end

#parse_statement(statement) ⇒ String

Generates the percona command for a raw MySQL statement. Fills all the connection credentials from the current AR connection, but that can amended via ENV-vars: PERCONA_DB_HOST, PERCONA_DB_USER, PERCONA_DB_PASSWORD, PERCONA_DB_NAME Table name can’t not be amended, it populates automatically from the migration data

Parameters:

  • statement (String)

    MySQL statement

Returns:

  • (String)


65
66
67
68
69
70
# File 'lib/arrival/cli_generator.rb', line 65

def parse_statement(statement)
  alter_argument = AlterArgument.new(statement)
  # dsn = DSN.new(connection_details.database, alter_argument.table_name)

  "#{command} #{all_options} #{alter_argument} #{Option.new("table", alter_argument.table_name)}"
end