Class: GammaReplication::Command::Start
Constant Summary
collapse
- FATAL_ERROR_KEYWORDS =
[
/out of memory/i,
/cannot allocate memory/i,
/memory allocation failed/i,
/no space left on device/i,
/disk full/i,
/too many open files/i,
/segmentation fault/i,
/bus error/i,
/killed/i,
/can't connect to mysql server/i,
/lost connection to mysql server/i,
/mysql server has gone away/i,
/permission denied/i,
/read-only file system/i,
/network is unreachable/i,
/connection refused/i,
/connection timed out/i
].freeze
Instance Method Summary
collapse
#execute
Methods inherited from Base
#gamma_tables, #output_setting_warning
Constructor Details
#initialize(opts) ⇒ Start
Returns a new instance of Start.
26
27
28
29
30
|
# File 'lib/gamma_replication/command/start.rb', line 26
def initialize(opts)
super
@force_mode = opts[:force]
@out_client.client.query("SET FOREIGN_KEY_CHECKS = 0") if @force_mode
end
|
Instance Method Details
#apply_mode? ⇒ Boolean
32
33
34
|
# File 'lib/gamma_replication/command/start.rb', line 32
def apply_mode?
true
end
|
#execute_query(query) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/gamma_replication/command/start.rb', line 36
def execute_query(query)
logger.info("Executing: #{query}") if ENV["DEBUG"]
retries = 0
begin
@out_client.client.query(query)
rescue StandardError => e
error_message = e.message.to_s.split("\n").first
log_msg = "Query execution failed: #{error_message.gsub(/\s+/, " ")}"
logger.error(log_msg)
if fatal_error?(error_message)
retries += 1
if retries < 3
logger.warn("Retrying due to fatal error (attempt #{retries})...")
sleep 2**retries
retry
else
logger.fatal("Fatal: unrecoverable error after #{retries} attempts. Exiting. Error: #{log_msg}")
exit(1)
end
end
end
end
|
#fatal_error?(msg) ⇒ Boolean
60
61
62
|
# File 'lib/gamma_replication/command/start.rb', line 60
def fatal_error?(msg)
FATAL_ERROR_KEYWORDS.any? { |pattern| msg =~ pattern }
end
|
#finalize ⇒ Object
64
65
66
67
|
# File 'lib/gamma_replication/command/start.rb', line 64
def finalize
@out_client.client.query("SET FOREIGN_KEY_CHECKS = 1") if @force_mode
super
end
|