mysql_binlog 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,8 +9,10 @@ reader = BinlogFileReader.new(ARGV.first)
9
9
  #reader = DebuggingReader.new(reader, :data => true, :calls => true)
10
10
  binlog = Binlog.new(reader)
11
11
 
12
- binlog.ignore_rotate = true
12
+ #reader.tail = true
13
+ #binlog.ignore_rotate = true
13
14
 
14
15
  binlog.each_event do |event|
15
16
  pp event
17
+ puts
16
18
  end
data/lib/mysql_binlog.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'mysql_binlog/mysql_character_set'
1
2
  require 'mysql_binlog/binlog'
2
3
  require 'mysql_binlog/binlog_field_parser'
3
4
  require 'mysql_binlog/binlog_event_parser'
@@ -169,9 +169,9 @@ module MysqlBinlog
169
169
  }
170
170
  when :charset
171
171
  {
172
- :character_set_client => parser.read_uint16,
173
- :collation_connection => parser.read_uint16,
174
- :collation_server => parser.read_uint16,
172
+ :character_set_client => COLLATION[parser.read_uint16],
173
+ :collation_connection => COLLATION[parser.read_uint16],
174
+ :collation_server => COLLATION[parser.read_uint16],
175
175
  }
176
176
  when :time_zone
177
177
  parser.read_lpstring
@@ -1,16 +1,17 @@
1
1
  module MysqlBinlog
2
2
  # Read a binary log from a file on disk.
3
3
  class BinlogFileReader
4
+ attr_accessor :tail
5
+
4
6
  def initialize(filename)
5
- @filename = filename
6
- @binlog = nil
7
-
7
+ @tail = false
8
8
  open_file(filename)
9
9
  end
10
10
 
11
11
  def open_file(filename)
12
- @filename = filename
13
- @binlog = File.open(filename, mode="r")
12
+ @dirname = File.dirname(filename)
13
+ @filename = File.basename(filename)
14
+ @binlog = File.open(filename, mode="r")
14
15
 
15
16
  if (magic = read(4).unpack("V").first) != 1852400382
16
17
  raise MalformedBinlogException.new("Magic number #{magic} is incorrect")
@@ -18,8 +19,18 @@ module MysqlBinlog
18
19
  end
19
20
 
20
21
  def rotate(filename, position)
21
- open_file(filename)
22
- seek(position)
22
+ retries = 10
23
+ begin
24
+ open_file(@dirname + "/" + filename)
25
+ seek(position)
26
+ rescue Errno::ENOENT
27
+ if (retries -= 1) > 0
28
+ sleep 0.01
29
+ retry
30
+ else
31
+ raise
32
+ end
33
+ end
23
34
  end
24
35
 
25
36
  def filename
@@ -39,6 +50,7 @@ module MysqlBinlog
39
50
  end
40
51
 
41
52
  def end?
53
+ return false if tail
42
54
  @binlog.eof?
43
55
  end
44
56
 
@@ -51,6 +63,12 @@ module MysqlBinlog
51
63
  end
52
64
 
53
65
  def read(length)
66
+ if tail
67
+ needed_position = position + length
68
+ while @binlog.stat.size < needed_position
69
+ sleep 0.02
70
+ end
71
+ end
54
72
  return "" if length == 0
55
73
  data = @binlog.read(length)
56
74
  if !data
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql_binlog
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 7
10
- version: 0.1.7
9
+ - 8
10
+ version: 0.1.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeremy Cole
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-29 00:00:00 Z
18
+ date: 2012-07-02 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Library for parsing MySQL binary logs in Ruby
@@ -69,3 +69,4 @@ specification_version: 3
69
69
  summary: MySQL Binary Log Parser
70
70
  test_files: []
71
71
 
72
+ has_rdoc: