Class: Mysqlknife::Mysql::Replica

Inherits:
Object
  • Object
show all
Defined in:
lib/mysqlknife/mysql/replica.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReplica

Returns a new instance of Replica.



8
9
10
11
12
# File 'lib/mysqlknife/mysql/replica.rb', line 8

def initialize
  @mysql     = MySQL.new
  @mysql_cmd = Mysql::Command.new
  @mysql_sql = Mysql::SQL.new
end

Instance Attribute Details

#behind=(value) ⇒ Object (writeonly)

Sets the attribute behind

Parameters:

  • value

    the value to set the attribute behind to.



6
7
8
# File 'lib/mysqlknife/mysql/replica.rb', line 6

def behind=(value)
  @behind = value
end

Instance Method Details

#check_status_negative(behind) ⇒ Object



14
15
16
# File 'lib/mysqlknife/mysql/replica.rb', line 14

def check_status_negative(behind)
  @behind < 0 && behind < 0 && behind <= @behind && behind != 0
end

#rds?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/mysqlknife/mysql/replica.rb', line 18

def rds?
  ! @mysql.execute(@mysql_sql.show_procedure('rds_skip_repl_error')).first
end

#skipObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mysqlknife/mysql/replica.rb', line 26

def skip
  status = slave_status

  if check_status_negative(status['Seconds_Behind_Master'])
    Mysqlknife::Log.new.skip_repl_error(status)

    if rds?
      @mysql.execute(@mysql_sql.rds_skip_repl_error)
    else
      @mysql.execute(@mysql_sql.mysql_skip_repl_error)
    end
  end
end

#slave_statusObject



22
23
24
# File 'lib/mysqlknife/mysql/replica.rb', line 22

def slave_status
  @mysql.execute(@mysql_sql.slave_status).first
end