gamma_replication 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3663201d44383fe14f66bd716f1276cdd7920eb14aeaf588621ed874ab433aa
4
- data.tar.gz: 437a7d18d43c2edc61f4a05759db7fa4fa206292e66d68ed6b917f097d296123
3
+ metadata.gz: cb4392908f3daf17928f115476739653bfebee77e940ac586eb17ef27e3104e3
4
+ data.tar.gz: 275c6b6227b7f1f2b700ef452cd10d5d18d079757d2390eb90e7bcfc4fd99b93
5
5
  SHA512:
6
- metadata.gz: d7d2d575ad7cf93c0c625728eaaa4fe9a5002148395d772c3d3d89078b837f72ca0b78205fb371164e0da13b9ce2088e218103da337fd0a98900943f456712a1
7
- data.tar.gz: 77c2eb5eebabbd7436c48f9fada27d0d129bd7056779a5121a82f5456eeee65b79e9b4fb879b7a2baa0423559f55efa71c405836814baccca75e742c137881b5
6
+ metadata.gz: 5e1f56ac2bed52cf873dde8b40d54f2278f2f749a624723805af5bb37cd024da2c8cbd9a53897fb194a69fc52b090607b0cd31d72f9f990c16147cfcc4e8501f
7
+ data.tar.gz: 17ea2d1a0fa8c619871b55270394af7c69f67b3d5a21127cf7c2cabca59306fb062dd849fa4ecce44d3d4fb97c394703c8a5557192f7497c97e94bd6e06fb8d0
@@ -14,6 +14,7 @@ class GammaReplicationCLI < Thor
14
14
  option :maxwell_config, aliases: "-m", desc: "Maxwell configuration file path", required: true
15
15
  option :enable_stats, type: :boolean, desc: "Enable statistics output (default: true)"
16
16
  option :stats_interval, type: :numeric, desc: "Statistics output interval in seconds (default: 10800)"
17
+ option :force, type: :boolean, desc: "Disable foreign key checks during replication", default: false
17
18
  def start
18
19
  GammaReplication::Command::Start.new(options).execute
19
20
  end
@@ -3,9 +3,30 @@
3
3
  module GammaReplication
4
4
  module Command
5
5
  class Start < BaseReplication
6
- def initialize(*)
6
+ FATAL_ERROR_KEYWORDS = [
7
+ /out of memory/i,
8
+ /cannot allocate memory/i,
9
+ /memory allocation failed/i,
10
+ /no space left on device/i,
11
+ /disk full/i,
12
+ /too many open files/i,
13
+ /segmentation fault/i,
14
+ /bus error/i,
15
+ /killed/i,
16
+ /can't connect to mysql server/i,
17
+ /lost connection to mysql server/i,
18
+ /mysql server has gone away/i,
19
+ /permission denied/i,
20
+ /read-only file system/i,
21
+ /network is unreachable/i,
22
+ /connection refused/i,
23
+ /connection timed out/i
24
+ ].freeze
25
+
26
+ def initialize(opts)
7
27
  super
8
- @out_client.client.query("SET FOREIGN_KEY_CHECKS = 0")
28
+ @force_mode = opts[:force]
29
+ @out_client.client.query("SET FOREIGN_KEY_CHECKS = 0") if @force_mode
9
30
  end
10
31
 
11
32
  def apply_mode?
@@ -14,13 +35,34 @@ module GammaReplication
14
35
 
15
36
  def execute_query(query)
16
37
  logger.info("Executing: #{query}") if ENV["DEBUG"]
17
- @out_client.client.query(query)
18
- rescue StandardError => e
19
- logger.error("Query execution failed: #{e.message}")
38
+ retries = 0
39
+ begin
40
+ @out_client.client.query(query)
41
+ rescue StandardError => e
42
+ error_message = e.message.to_s.split("\n").first
43
+ log_msg = "Query execution failed: #{error_message.gsub(/\s+/, " ")}"
44
+ logger.error(log_msg)
45
+
46
+ if fatal_error?(error_message)
47
+ retries += 1
48
+ if retries < 3
49
+ logger.warn("Retrying due to fatal error (attempt #{retries})...")
50
+ sleep 2**retries
51
+ retry
52
+ else
53
+ logger.fatal("Fatal: unrecoverable error after #{retries} attempts. Exiting. Error: #{log_msg}")
54
+ exit(1)
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ def fatal_error?(msg)
61
+ FATAL_ERROR_KEYWORDS.any? { |pattern| msg =~ pattern }
20
62
  end
21
63
 
22
64
  def finalize
23
- @out_client.client.query("SET FOREIGN_KEY_CHECKS = 1")
65
+ @out_client.client.query("SET FOREIGN_KEY_CHECKS = 1") if @force_mode
24
66
  super
25
67
  end
26
68
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GammaReplication
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamma_replication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinsuke Nishio
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-18 00:00:00.000000000 Z
11
+ date: 2025-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport