Class: Flydata::SourceMysql::MysqlCompatibilityCheck
Instance Method Summary
collapse
#check_writing_permissions
#check
#before_logging, #log_error_stderr, #log_info_stdout, #log_warn_stderr
Constructor Details
Returns a new instance of MysqlCompatibilityCheck.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/flydata/source_mysql/mysql_compatibility_check.rb', line 14
def initialize(dp_hash, de_hash, options={})
super
@db_opts = FlydataCore::Mysql::Config.build_mysql_db_opts(de_hash)
@dump_dir = options[:dump_dir] || nil
@backup_dir = options[:backup_dir] || nil
@tables = de_hash['tables']
begin
@rds = FlydataCore::Mysql::MysqlCompatibilityChecker.new(@db_opts).rds?
rescue FlydataCore::MissingExecutePermissionMysqlCompatibilityError => e
@rds = false
log_warn_stderr("[WARNING] #{e.message}")
end
end
|
Instance Method Details
#check_compatibility56_variable ⇒ Object
38
39
40
|
# File 'lib/flydata/source_mysql/mysql_compatibility_check.rb', line 38
def check_compatibility56_variable
FlydataCore::Mysql::MySqlVersion57CompabilityChecker.new(@db_opts).do_check
end
|
#check_mysql_binlog_retention ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/flydata/source_mysql/mysql_compatibility_check.rb', line 80
def check_mysql_binlog_retention
if is_rds?
run_rds_retention_check
else
run_mysql_retention_check
end
end
|
#check_mysql_parameters_compat ⇒ Object
71
72
73
74
75
76
77
78
|
# File 'lib/flydata/source_mysql/mysql_compatibility_check.rb', line 71
def check_mysql_parameters_compat
begin
FlydataCore::Mysql::OptionalBinlogParameterChecker.new(@db_opts).do_check
rescue FlydataCore::MysqlCompatibilityError => e
log_warn_stderr(e.to_s)
end
FlydataCore::Mysql::RequiredBinlogParameterChecker.new(@db_opts).do_check
end
|
#check_mysql_protocol_tcp_compat ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/flydata/source_mysql/mysql_compatibility_check.rb', line 46
def check_mysql_protocol_tcp_compat
query = FlydataCore::Mysql::CommandGenerator.generate_mysql_show_grants_cmd(@db_opts)
Open3.popen3(query) do |stdin, stdout, stderr|
stdin.close
while !stderr.eof?
lines = []
while line = stderr.gets do
lines << line.strip unless line =~ /Warning: Using a password on the command line interface can be insecure/
end
unless lines.empty?
err_reason = lines.join(" ")
log_error("Error occured during access to mysql server.", err: err_reason)
raise FlydataCore::MysqlCompatibilityError, "Cannot connect to MySQL database. Please make sure you can connect with this command:\n $ mysql -u #{@db_opts[:username]} -h #{@db_opts[:host]} -P #{@db_opts[:port]} #{@db_opts[:database]} --protocol=tcp -p"
end
end
end
end
|
#check_mysql_user_compat ⇒ Object
42
43
44
|
# File 'lib/flydata/source_mysql/mysql_compatibility_check.rb', line 42
def check_mysql_user_compat
FlydataCore::Mysql::SyncPermissionChecker.new(@db_opts).do_check
end
|
#check_rds_master_status ⇒ Object
65
66
67
68
69
|
# File 'lib/flydata/source_mysql/mysql_compatibility_check.rb', line 65
def check_rds_master_status
if is_rds?
FlydataCore::Mysql::RdsMasterStatusChecker.new(@db_opts).do_check
end
end
|
#is_rds? ⇒ Boolean
111
112
113
|
# File 'lib/flydata/source_mysql/mysql_compatibility_check.rb', line 111
def is_rds?
@rds
end
|
#print_errors ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/flydata/source_mysql/mysql_compatibility_check.rb', line 29
def print_errors
return if @errors.empty?
log_error_stderr "There may be some compatibility issues with your MySQL credentials: "
@errors.each do |error|
log_error_stderr " * #{error.message}"
end
raise "Please correct these errors if you wish to run FlyData Sync"
end
|
#run_mysql_retention_check ⇒ Object
88
89
90
|
# File 'lib/flydata/source_mysql/mysql_compatibility_check.rb', line 88
def run_mysql_retention_check
FlydataCore::Mysql::NonRdsRetentionChecker.new(@db_opts).do_check
end
|
#run_rds_retention_check ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/flydata/source_mysql/mysql_compatibility_check.rb', line 92
def run_rds_retention_check
FlydataCore::Mysql::RdsRetentionChecker.new(@db_opts).do_check
rescue Mysql2::Error => e
if e.message =~ /command denied to user/
retention_hours = FlydataCore::Mysql::RdsRetentionChecker::BINLOG_RETENTION_HOURS
log_warn_stderr("[WARNING]Cannot verify RDS retention period on current MySQL user account.\n" +
"To see retention period, please run this on your RDS:\n" +
" $> call mysql.rds_show_configuration;\n" +
"Please verify that the hours is not nil and is at least #{retention_hours} hours\n" +
"To set binlog retention hours, you can run this on your RDS:\n" +
" $> call mysql.rds_set_configuration('binlog retention hours', #{retention_hours});\n"
)
else
raise e
end
rescue FlydataCore::MissingExecutePermissionMysqlCompatibilityError => e
log_warn_stderr("[WARNING] #{e.message}")
end
|