mysql_binlog 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a369e0a06cfbe3cd3d5f0fff501e0956e7138abc
4
- data.tar.gz: 45dd1afcf6a14152aa63c03cc4d79175babab607
3
+ metadata.gz: 7b81a85e5ebc8ed76b5152df02001e8a2dd6df87
4
+ data.tar.gz: d74e28a964473c50e1120c3f52fd61333aad8c99
5
5
  SHA512:
6
- metadata.gz: 3dd3c45cfa72070a7ac471d7c9ccf33c408f8103b697cf2cbf852be01f4fbc48f7f04095193603327b7ce2b1bfd50916eb6658c8b391659be5bc7ad650738545
7
- data.tar.gz: bb698d2f9fd0865f137158b132381ad95eb8434f0d79efbe048399a52b528f38c4e94e508f198c1a99547f776b16b1468b729a1fd50e972c3dbae357cfaa1030
6
+ metadata.gz: ba05cac9a92cf9e2ad05c37625a25e4d6c506b7ba473b321b8d7536c81e4c299e1060192304fdf8c639abc554b6ed0927fa5ac850d33c8a0a9f4d6ec371e9151
7
+ data.tar.gz: 1fe544bbc944267de7479316ab0a3a497737e57fe51754cf9e6c1e52e670940097c48780f635d473948b928645705630a19920000f2015fe676bb10758ee7b80
@@ -31,17 +31,17 @@ module MysqlBinlog
31
31
  :delete_rows_event_v1 => 25, #
32
32
  :incident_event => 26, #
33
33
  :heartbeat_log_event => 27, #
34
- :ignorable_log_event => 28,
35
- :rows_query_log_event => 29,
36
- :write_rows_event_v2 => 30,
37
- :update_rows_event_v2 => 31,
38
- :delete_rows_event_v2 => 32,
39
- :gtid_log_event => 33,
40
- :anonymous_gtid_log_event => 34,
41
- :previous_gtids_log_event => 35,
42
- :transaction_context_event => 36,
43
- :view_change_event => 37,
44
- :xa_prepare_log_event => 38,
34
+ :ignorable_log_event => 28, #
35
+ :rows_query_log_event => 29, #
36
+ :write_rows_event_v2 => 30, #
37
+ :update_rows_event_v2 => 31, #
38
+ :delete_rows_event_v2 => 32, #
39
+ :gtid_log_event => 33, #
40
+ :anonymous_gtid_log_event => 34, #
41
+ :previous_gtids_log_event => 35, #
42
+ :transaction_context_event => 36, #
43
+ :view_change_event => 37, #
44
+ :xa_prepare_log_event => 38, #
45
45
 
46
46
  :table_metadata_event => 50, # Only in Twitter MySQL
47
47
  }
@@ -59,6 +59,9 @@ module MysqlBinlog
59
59
  :write_rows_event_v1,
60
60
  :update_rows_event_v1,
61
61
  :delete_rows_event_v1,
62
+ :write_rows_event_v2,
63
+ :update_rows_event_v2,
64
+ :delete_rows_event_v2,
62
65
  ]
63
66
 
64
67
  # Values for the +flags+ field that may appear in binary logs. There are
@@ -174,6 +177,10 @@ module MysqlBinlog
174
177
  :complete_rows => 1 << 3, # COMPLETE_ROWS_F
175
178
  }
176
179
 
180
+ GENERIC_ROWS_EVENT_VH_FIELD_TYPES = [
181
+ :extra_rows_info, # ROWS_V_EXTRAINFO_TAG
182
+ ]
183
+
177
184
  # Parse binary log events from a provided binary log. Must be driven
178
185
  # externally, but handles all the details of parsing an event header
179
186
  # and the content of the various event types.
@@ -488,7 +495,7 @@ module MysqlBinlog
488
495
  # Parse a single row image, which is comprised of a series of columns. Not
489
496
  # all columns are present in the row image, the columns_used array of true
490
497
  # and false values identifies which columns are present.
491
- def _generic_rows_event_row_image_v1(header, fields, columns_used)
498
+ def _generic_rows_event_row_image(header, fields, columns_used)
492
499
  row_image = []
493
500
  start_position = reader.position
494
501
  columns_null = parser.read_bit_array(fields[:table][:columns].size)
@@ -512,7 +519,7 @@ module MysqlBinlog
512
519
  size: end_position-start_position
513
520
  }
514
521
  end
515
- private :_generic_rows_event_row_image_v1
522
+ private :_generic_rows_event_row_image
516
523
 
517
524
  def diff_row_images(before, after)
518
525
  diff = {}
@@ -530,19 +537,19 @@ module MysqlBinlog
530
537
  # Parse the row images present in a row-based replication row event. This
531
538
  # is rather incomplete right now due missing support for many MySQL types,
532
539
  # but can parse some basic events.
533
- def _generic_rows_event_row_images_v1(header, fields, columns_used)
540
+ def _generic_rows_event_row_images(header, fields, columns_used)
534
541
  row_images = []
535
542
  end_position = reader.position + reader.remaining(header)
536
543
  while reader.position < end_position
537
544
  row_image = {}
538
545
  case header[:event_type]
539
- when :write_rows_event_v1
540
- row_image[:after] = _generic_rows_event_row_image_v1(header, fields, columns_used[:after])
541
- when :delete_rows_event_v1
542
- row_image[:before] = _generic_rows_event_row_image_v1(header, fields, columns_used[:before])
543
- when :update_rows_event_v1
544
- row_image[:before] = _generic_rows_event_row_image_v1(header, fields, columns_used[:before])
545
- row_image[:after] = _generic_rows_event_row_image_v1(header, fields, columns_used[:after])
546
+ when :write_rows_event_v1, :write_rows_event_v2
547
+ row_image[:after] = _generic_rows_event_row_image(header, fields, columns_used[:after])
548
+ when :delete_rows_event_v1, :delete_rows_event_v1
549
+ row_image[:before] = _generic_rows_event_row_image(header, fields, columns_used[:before])
550
+ when :update_rows_event_v1, :update_rows_event_v2
551
+ row_image[:before] = _generic_rows_event_row_image(header, fields, columns_used[:before])
552
+ row_image[:after] = _generic_rows_event_row_image(header, fields, columns_used[:after])
546
553
  row_image[:diff] = diff_row_images(row_image[:before][:image], row_image[:after][:image])
547
554
  end
548
555
  row_images << row_image
@@ -557,7 +564,17 @@ module MysqlBinlog
557
564
 
558
565
  row_images
559
566
  end
560
- private :_generic_rows_event_row_images_v1
567
+ private :_generic_rows_event_row_images
568
+
569
+ # Parse the variable header from a v2 rows event. This is only used for
570
+ # ROWS_V_EXTRAINFO_TAG which is used by NDB. Ensure it can be skipped
571
+ # properly but don't bother parsing it.
572
+ def _generic_rows_event_vh
573
+ vh_payload_len = parser.read_uint16 - 2
574
+ return unless vh_payload_len > 0
575
+
576
+ reader.read(vh_payload_len)
577
+ end
561
578
 
562
579
  # Parse fields for any of the row-based replication row events:
563
580
  # * +Write_rows+ which is used for +INSERT+.
@@ -567,30 +584,48 @@ module MysqlBinlog
567
584
  # Implemented in sql/log_event.cc line ~8039
568
585
  # in Rows_log_event::write_data_header
569
586
  # and Rows_log_event::write_data_body
570
- def generic_rows_event_v1(header)
587
+ def _generic_rows_event(header, contains_vh: false)
571
588
  fields = {}
572
589
  table_id = parser.read_uint48
573
590
  fields[:table] = @table_map[table_id]
574
591
  fields[:flags] = parser.read_uint_bitmap_by_size_and_name(2, GENERIC_ROWS_EVENT_FLAGS)
592
+
593
+ # Rows_log_event v2 events contain a variable-sized header. Only NDB
594
+ # uses it right now, so let's just make sure it's skipped properly.
595
+ _generic_rows_event_vh if contains_vh
596
+
575
597
  columns = parser.read_varint
576
598
  columns_used = {}
577
599
  case header[:event_type]
578
- when :write_rows_event_v1
600
+ when :write_rows_event_v1, :write_rows_event_v2
579
601
  columns_used[:after] = parser.read_bit_array(columns)
580
- when :delete_rows_event_v1
602
+ when :delete_rows_event_v1, :delete_rows_event_v2
581
603
  columns_used[:before] = parser.read_bit_array(columns)
582
- when :update_rows_event_v1
604
+ when :update_rows_event_v1, :update_rows_event_v2
583
605
  columns_used[:before] = parser.read_bit_array(columns)
584
606
  columns_used[:after] = parser.read_bit_array(columns)
585
607
  end
586
- fields[:row_image] = _generic_rows_event_row_images_v1(header, fields, columns_used)
608
+ fields[:row_image] = _generic_rows_event_row_images(header, fields, columns_used)
587
609
  fields
588
610
  end
611
+ private :_generic_rows_event
612
+
613
+ def generic_rows_event_v1(header)
614
+ _generic_rows_event(header, contains_vh: false)
615
+ end
589
616
 
590
617
  alias :write_rows_event_v1 :generic_rows_event_v1
591
618
  alias :update_rows_event_v1 :generic_rows_event_v1
592
619
  alias :delete_rows_event_v1 :generic_rows_event_v1
593
620
 
621
+ def generic_rows_event_v2(header)
622
+ _generic_rows_event(header, contains_vh: true)
623
+ end
624
+
625
+ alias :write_rows_event_v2 :generic_rows_event_v2
626
+ alias :update_rows_event_v2 :generic_rows_event_v2
627
+ alias :delete_rows_event_v2 :generic_rows_event_v2
628
+
594
629
  def rows_query_log_event(header)
595
630
  reader.read(1) # skip useless byte length which is unused
596
631
  { query: reader.read(header[:payload_length]-1) }
@@ -1,3 +1,3 @@
1
1
  module MysqlBinlog
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql_binlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Cole
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-06 00:00:00.000000000 Z
11
+ date: 2019-08-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Library for parsing MySQL binary logs in Ruby
14
14
  email: jeremy@jcole.us