class MysqlSlaver::MasterChanger
Attributes
executor[RW]
master_host[RW]
mysql_root_password[RW]
port[RW]
replication_password[RW]
replication_user[RW]
socket_file[RW]
Public Class Methods
new(params)
click to toggle source
# File lib/mysql_slaver/master_changer.rb, line 7 def initialize(params) @master_host = params.fetch(:master_host) @port = params.fetch(:port) @socket_file = params.fetch(:socket_file, nil) @mysql_root_password = params.fetch(:mysql_root_password, '') @replication_user = params.fetch(:replication_user) @replication_password = params.fetch(:replication_password) @executor = params.fetch(:executor) { Executor.new } end
Public Instance Methods
change!(status)
click to toggle source
# File lib/mysql_slaver/master_changer.rb, line 17 def change!(status) cmds = [ 'stop slave', change_master(status), 'start slave' ] cmd = mysql_command(cmds.join('; '), mysql_params) executor.execute cmd end
Private Instance Methods
change_master(status)
click to toggle source
# File lib/mysql_slaver/master_changer.rb, line 36 def change_master(status) %[CHANGE MASTER TO #{cmd_values(status)}] end
cmd_values(status)
click to toggle source
# File lib/mysql_slaver/master_changer.rb, line 40 def cmd_values(status) [ "MASTER_LOG_FILE='#{status[:file]}'", "MASTER_LOG_POS=#{status[:position]}", "MASTER_HOST='#{master_host}'", "MASTER_PORT=#{port}", "MASTER_USER='#{replication_user}'", "MASTER_PASSWORD='#{replication_password}'" ].join(', ') end
mysql_params()
click to toggle source
# File lib/mysql_slaver/master_changer.rb, line 29 def mysql_params { root_password: mysql_root_password, socket_file: socket_file } end