mysql_replicator 0.2.0 → 0.3.0

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: b8caf562beab557ef33cf471becf5af562c46d13b0613c1dff120b8f6b22f9a3
4
- data.tar.gz: 511544da5cda5f94331f08fdead13f100eb233e8810320903ed0343a5be50554
3
+ metadata.gz: 89139696403c8871f454557357e7aa588ae352e0ba2b1108897614bd3109e103
4
+ data.tar.gz: d2a3b05f3c6181b4b40c1dcdfcf7be4accfd5d8f785cb6ae1ade5d489de669d4
5
5
  SHA512:
6
- metadata.gz: 9ca4f3dcba764981ce012d11699eaf740f303e8ecfc649b498eadd59a72cf5c9aaccc470c7db436adb0ec7df39b79ff8312aca6f511f8580722e48066b92b8cf
7
- data.tar.gz: ccee5ba75a950ff020314e488b2368460ed16d90aabdba21c0e3023f400c40e4ba8990e9fb7d8077aa0cd1dd42029b79a49c9b03e0a72a8320b7a20971ab7295
6
+ metadata.gz: e55787771552dfcacf4d697f0190ea07e86d1191fc0dee3b5ddbd04afba80fc81d2df1a321a7fb7ae318682f9c8a1f52613f8fa6dab5fbab968cc569b0def222
7
+ data.tar.gz: 657517edf37d8c83ede73abf1c5e4619eaccc05861d21e707a341f3bcab42da6d39b231a0cf946fef2f087baeb6dfdf6acdb8fe5e0eee1772b75c460929531f7
@@ -7,7 +7,7 @@ module MysqlReplicator
7
7
  # @rbs @connection: MysqlReplicator::Connection
8
8
  # @rbs @server_id: Integer
9
9
  # @rbs @checksum_type: String?
10
- # @rbs @event_listener: ^(MysqlReplicator::Binlogs::EventParser::binlogEvent) -> untyped | nil
10
+ # @rbs @event_listener: ^(MysqlReplicator::Binlogs::EventParser::binlogEvent?, Exception?) -> untyped | nil
11
11
 
12
12
  # @rbs! attr_reader connection: MysqlReplicator::Connection
13
13
  attr_reader :connection
@@ -21,7 +21,7 @@ module MysqlReplicator
21
21
  @checksum_type = nil
22
22
  end
23
23
 
24
- # @rbs &block: { (MysqlReplicator::Binlogs::EventParser::binlogEvent) -> untyped | nil }
24
+ # @rbs &block: { (MysqlReplicator::Binlogs::EventParser::binlogEvent?, Exception?) -> untyped | nil }
25
25
  # @rbs return: void
26
26
  def on(&block)
27
27
  @event_listener = block
@@ -35,19 +35,23 @@ module MysqlReplicator
35
35
  binlog_file = binlog_info[:file]
36
36
  binlog_position = binlog_info[:position]
37
37
 
38
- configure_binlog_checksum if @checksum_type.nil?
38
+ configure_binlog_checksum
39
39
  register_as_slave
40
40
  start_binlog_dump(binlog_file, binlog_position)
41
41
 
42
42
  begin
43
43
  handle_binlog_events
44
44
  rescue Interrupt
45
- stop_replication
45
+ # Ctrl+Cによる正常終了
46
46
  rescue => e
47
+ raise e if defined?(::IRB::Abort) && e.is_a?(::IRB::Abort) # steep:ignore UnknownConstant
48
+
47
49
  MysqlReplicator::Logger.error \
48
50
  "Unexpected error: #{e.message},\n" \
49
51
  "Backtrace: #{e.backtrace.first(5).join("\n")}"
50
52
 
53
+ @event_listener&.call(nil, e)
54
+ ensure
51
55
  stop_replication
52
56
  end
53
57
  end
@@ -56,6 +60,9 @@ module MysqlReplicator
56
60
  def stop_replication
57
61
  @connection.flush_socket_buffer
58
62
  unregister_as_slave
63
+ rescue => e
64
+ MysqlReplicator::Logger.error "Failed to unregister as slave: #{e.message}"
65
+ ensure
59
66
  @connection.close
60
67
  end
61
68
 
@@ -180,8 +187,8 @@ module MysqlReplicator
180
187
  binlog_event = event_parser.execute(payload[1..], @connection, @checksum_type == 'CRC32')
181
188
 
182
189
  case binlog_event[:event_type]
183
- when :QUERY, :WRITE_ROWS, :UPDATE_ROWS, :DELETE_ROWS
184
- @event_listener&.call(binlog_event)
190
+ when :QUERY, :TABLE_MAP, :WRITE_ROWS, :UPDATE_ROWS, :DELETE_ROWS
191
+ @event_listener&.call(binlog_event, nil)
185
192
  end
186
193
  MysqlReplicator::Logger.debug "Binlog event: #{binlog_event}"
187
194
  when 0xFF
@@ -186,7 +186,7 @@ module MysqlReplicator
186
186
 
187
187
  begin
188
188
  # Read all unread data in non-blocking mode
189
- while @socket.ready?
189
+ while @socket.wait_readable(0)
190
190
  data = @socket.read_nonblock(1024)
191
191
  flushed_data += data
192
192
  MysqlReplicator::Logger.debug \
@@ -2,5 +2,5 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module MysqlReplicator
5
- VERSION = '0.2.0' #: String
5
+ VERSION = '0.3.0' #: String
6
6
  end
@@ -28,7 +28,7 @@ module MysqlReplicator
28
28
  # @rbs user: String
29
29
  # @rbs password: String
30
30
  # @rbs database: String
31
- # @rbs &block: { (MysqlReplicator::Binlogs::EventParser::binlogEvent) -> untyped | nil }?
31
+ # @rbs &block: { (MysqlReplicator::Binlogs::EventParser::binlogEvent?, Exception?) -> untyped | nil }?
32
32
  # @rbs return: void
33
33
  def self.run(host: '127.0.0.1', port: 3306, user: 'root', password: 'root', database: '', &block)
34
34
  conn = MysqlReplicator::Connection.new(
@@ -9,7 +9,7 @@ module MysqlReplicator
9
9
 
10
10
  @checksum_type: String?
11
11
 
12
- @event_listener: ^(MysqlReplicator::Binlogs::EventParser::binlogEvent) -> untyped | nil
12
+ @event_listener: ^(MysqlReplicator::Binlogs::EventParser::binlogEvent?, Exception?) -> untyped | nil
13
13
 
14
14
  # @rbs! attr_reader connection: MysqlReplicator::Connection
15
15
  attr_reader connection: untyped
@@ -19,9 +19,9 @@ module MysqlReplicator
19
19
  # @rbs return void
20
20
  def initialize: (MysqlReplicator::Connection connection, ?Integer server_id) -> void
21
21
 
22
- # @rbs &block: { (MysqlReplicator::Binlogs::EventParser::binlogEvent) -> untyped | nil }
22
+ # @rbs &block: { (MysqlReplicator::Binlogs::EventParser::binlogEvent?, Exception?) -> untyped | nil }
23
23
  # @rbs return: void
24
- def on: () ?{ (?) -> untyped } -> void
24
+ def on: () ?{ (MysqlReplicator::Binlogs::EventParser::binlogEvent?, Exception?) -> untyped } -> void
25
25
 
26
26
  # @rbs return: void
27
27
  def start_replication: () -> void
@@ -5,14 +5,14 @@ module MysqlReplicator
5
5
  class RowsEventParser
6
6
  type rowData = { ordinal_position: Integer, data_type: String, column_name: String, value: String | Integer | bool | nil, primary_key: bool }
7
7
 
8
- type execution = { table_id: Integer, flags: Integer, extra_data_length: Integer, column_count: Integer, rows: Array[rowData] }
8
+ type execution = { database: String?, table: String?, table_id: Integer, flags: Integer, extra_data_length: Integer, column_count: Integer, rows: Array[rowData] }
9
9
 
10
10
  # @rbs event_type: :WRITE_ROWS | :UPDATE_ROWS | :DELETE_ROWS
11
11
  # @rbs payload: String
12
12
  # @rbs checksum_enabled bool
13
13
  # @rbs table_map: Hash[Integer, MysqlReplicator::Binlogs::TableMapEventParser::execution]
14
14
  # @rbs return: execution
15
- def self.parse: (:WRITE_ROWS | :UPDATE_ROWS | :DELETE_ROWS event_type, String payload, bool checksum_enabled, Hash[Integer, MysqlReplicator::Binlogs::TableMapEventParser::execution] table_map) -> execution
15
+ def self.parse: (:WRITE_ROWS | :UPDATE_ROWS | :DELETE_ROWS event_type, String payload, bool checksum_enabled, Hash[Integer, MysqlReplicator::Binlogs::TableMapEventParser::execution] table_map) -> { database: String?, table: String?, table_id: Integer, flags: Integer, extra_data_length: Integer, column_count: Integer, rows: Array[untyped] }
16
16
 
17
17
  # @rbs io: StringIO
18
18
  # @rbs column_count: Integer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql_replicator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yo_waka
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  - !ruby/object:Gem::Version
119
119
  version: '0'
120
120
  requirements: []
121
- rubygems_version: 4.0.3
121
+ rubygems_version: 4.0.6
122
122
  specification_version: 4
123
123
  summary: The MySQL Binlog event handler using MySQL Replication Protocol
124
124
  test_files: []