ruby-binlog 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README +33 -5
- data/ext/ruby_binlog.cpp +43 -0
- data/ext/ruby_binlog.h +3 -0
- metadata +32 -49
data/README
CHANGED
@@ -6,6 +6,7 @@ ruby-binlog is Ruby binding for MySQL Binary log API.
|
|
6
6
|
|
7
7
|
* http://www.oscon.com/oscon2011/public/schedule/detail/18785
|
8
8
|
* https://launchpad.net/mysql-replication-listener
|
9
|
+
* https://bitbucket.org/winebarrel/mysql-replication-listener
|
9
10
|
|
10
11
|
== Install
|
11
12
|
|
@@ -19,34 +20,60 @@ gem install ruby-binlog
|
|
19
20
|
|
20
21
|
== Example
|
21
22
|
|
23
|
+
#!/usr/bin/env ruby
|
24
|
+
require "rubygems"
|
22
25
|
require "binlog"
|
26
|
+
require "pstore"
|
23
27
|
|
24
|
-
|
25
|
-
|
28
|
+
$db = PStore.new("/tmp/foo")
|
29
|
+
|
30
|
+
#master_log_file = "mysql-bin.000001"
|
31
|
+
#master_log_pos = 4
|
32
|
+
|
33
|
+
master_log_file = nil
|
34
|
+
master_log_pos = nil
|
35
|
+
|
36
|
+
$db.transaction do
|
37
|
+
master_log_file = $db["master_log_file"]
|
38
|
+
master_log_pos = $db["master_log_pos"]
|
39
|
+
end
|
40
|
+
|
41
|
+
def save_position(master_log_file, master_log_pos)
|
42
|
+
$db.transaction do
|
43
|
+
$db["master_log_file"] = master_log_file
|
44
|
+
$db["master_log_pos"] = master_log_pos
|
45
|
+
end
|
46
|
+
end
|
26
47
|
|
27
48
|
begin
|
28
49
|
# XXX: Do not reuse a client instance, after connection goes out.
|
29
50
|
client = Binlog::Client.new("mysql://repl:repl@example.com")
|
30
51
|
sleep 0.3 until client.connect
|
31
|
-
|
52
|
+
|
53
|
+
if master_log_file and master_log_pos
|
54
|
+
client.set_position(master_log_file, master_log_pos)
|
55
|
+
end
|
32
56
|
|
33
57
|
while event = client.wait_for_next_event
|
58
|
+
puts "(#{event.event_type})"
|
34
59
|
master_log_pos = event.next_position
|
35
60
|
|
36
61
|
case event
|
37
62
|
when Binlog::QueryEvent
|
38
63
|
puts event.db_name
|
39
64
|
puts event.query
|
65
|
+
save_position(master_log_file, master_log_pos)
|
40
66
|
when Binlog::RowEvent
|
41
67
|
puts event.event_type
|
42
68
|
puts event.db_name
|
43
69
|
puts event.table_name
|
44
70
|
p event.columns
|
45
71
|
p event.rows
|
72
|
+
save_position(master_log_file, master_log_pos)
|
46
73
|
when Binlog::RotateEvent
|
47
74
|
master_log_file = event.binlog_file
|
48
|
-
|
49
|
-
|
75
|
+
master_log_pos = event.binlog_pos
|
76
|
+
save_position(master_log_file, master_log_pos)
|
50
77
|
end
|
51
78
|
end
|
52
79
|
rescue Binlog::Error => e
|
@@ -72,3 +99,4 @@ The following type are not supported in row mode.
|
|
72
99
|
see the following urls:
|
73
100
|
* http://bazaar.launchpad.net/~mysql/mysql-replication-listener/trunk/view/head:/src/value.cpp#L310
|
74
101
|
* https://bitbucket.org/winebarrel/ruby-binlog/downloads
|
102
|
+
* There is a patch of a library.
|
data/ext/ruby_binlog.cpp
CHANGED
@@ -58,9 +58,13 @@ struct Client {
|
|
58
58
|
int result;
|
59
59
|
|
60
60
|
Data_Get_Struct(self, Client, p);
|
61
|
+
#ifndef RUBY_UBF_IO
|
61
62
|
TRAP_BEG;
|
63
|
+
#endif
|
62
64
|
result = p->m_binlog->connect();
|
65
|
+
#ifndef RUBY_UBF_IO
|
63
66
|
TRAP_END;
|
67
|
+
#endif
|
64
68
|
|
65
69
|
return (result == 0) ? Qtrue : Qfalse;
|
66
70
|
}
|
@@ -113,9 +117,13 @@ struct Client {
|
|
113
117
|
if (driver->m_socket) {
|
114
118
|
bool socket_is_open;
|
115
119
|
|
120
|
+
#ifndef RUBY_UBF_IO
|
116
121
|
TRAP_BEG;
|
122
|
+
#endif
|
117
123
|
socket_is_open = driver->m_socket->is_open();
|
124
|
+
#ifndef RUBY_UBF_IO
|
118
125
|
TRAP_END;
|
126
|
+
#endif
|
119
127
|
|
120
128
|
return socket_is_open ? Qfalse : Qtrue;
|
121
129
|
} else {
|
@@ -137,7 +145,9 @@ struct Client {
|
|
137
145
|
int closed = 0;
|
138
146
|
timeval interval = { 0, WAIT_INTERVAL };
|
139
147
|
|
148
|
+
#ifndef RUBY_UBF_IO
|
140
149
|
TRAP_BEG;
|
150
|
+
#endif
|
141
151
|
while (1) {
|
142
152
|
if (driver->m_event_queue->is_not_empty()) {
|
143
153
|
result = p->m_binlog->wait_for_next_event(&event);
|
@@ -153,19 +163,29 @@ struct Client {
|
|
153
163
|
}
|
154
164
|
}
|
155
165
|
}
|
166
|
+
#ifndef RUBY_UBF_IO
|
156
167
|
TRAP_END;
|
168
|
+
#endif
|
157
169
|
|
158
170
|
if (closed) {
|
171
|
+
#ifndef RUBY_UBF_IO
|
159
172
|
TRAP_BEG;
|
173
|
+
#endif
|
160
174
|
driver->disconnect();
|
175
|
+
#ifndef RUBY_UBF_IO
|
161
176
|
TRAP_END;
|
177
|
+
#endif
|
162
178
|
|
163
179
|
rb_raise(rb_eBinlogError, "MySQL server has gone away");
|
164
180
|
}
|
165
181
|
} else {
|
182
|
+
#ifndef RUBY_UBF_IO
|
166
183
|
TRAP_BEG;
|
184
|
+
#endif
|
167
185
|
result = p->m_binlog->wait_for_next_event(&event);
|
186
|
+
#ifndef RUBY_UBF_IO
|
168
187
|
TRAP_END;
|
188
|
+
#endif
|
169
189
|
}
|
170
190
|
|
171
191
|
|
@@ -246,17 +266,25 @@ struct Client {
|
|
246
266
|
if (NIL_P(position)) {
|
247
267
|
unsigned long i_position;
|
248
268
|
i_position = NUM2ULONG(filename);
|
269
|
+
#ifndef RUBY_UBF_IO
|
249
270
|
TRAP_BEG;
|
271
|
+
#endif
|
250
272
|
result = p->m_binlog->set_position(i_position);
|
273
|
+
#ifndef RUBY_UBF_IO
|
251
274
|
TRAP_END;
|
275
|
+
#endif
|
252
276
|
} else {
|
253
277
|
unsigned long i_position;
|
254
278
|
Check_Type(filename, T_STRING);
|
255
279
|
i_position = NUM2ULONG(position);
|
256
280
|
std::string s_filename(StringValuePtr(filename));
|
281
|
+
#ifndef RUBY_UBF_IO
|
257
282
|
TRAP_BEG;
|
283
|
+
#endif
|
258
284
|
result = p->m_binlog->set_position(s_filename, i_position);
|
285
|
+
#ifndef RUBY_UBF_IO
|
259
286
|
TRAP_END;
|
287
|
+
#endif
|
260
288
|
}
|
261
289
|
|
262
290
|
switch (result) {
|
@@ -273,15 +301,22 @@ struct Client {
|
|
273
301
|
return retval;
|
274
302
|
}
|
275
303
|
|
304
|
+
// XXX: deprecated
|
276
305
|
static VALUE set_position2(VALUE self, VALUE position) {
|
277
306
|
Client *p;
|
278
307
|
VALUE retval = Qnil;
|
279
308
|
int result;
|
280
309
|
|
310
|
+
rb_warn("Binlog::Clien#position= is deprecated, use set_position instead.");
|
311
|
+
|
281
312
|
Data_Get_Struct(self, Client, p);
|
313
|
+
#ifndef RUBY_UBF_IO
|
282
314
|
TRAP_BEG;
|
315
|
+
#endif
|
283
316
|
result = p->m_binlog->set_position(NUM2ULONG(position));
|
317
|
+
#ifndef RUBY_UBF_IO
|
284
318
|
TRAP_END;
|
319
|
+
#endif
|
285
320
|
|
286
321
|
switch (result) {
|
287
322
|
case ERR_OK:
|
@@ -310,9 +345,13 @@ struct Client {
|
|
310
345
|
} else {
|
311
346
|
Check_Type(filename, T_STRING);
|
312
347
|
std::string s_filename(StringValuePtr(filename));
|
348
|
+
#ifndef RUBY_UBF_IO
|
313
349
|
TRAP_BEG;
|
350
|
+
#endif
|
314
351
|
position = p->m_binlog->get_position(s_filename);
|
352
|
+
#ifndef RUBY_UBF_IO
|
315
353
|
TRAP_END;
|
354
|
+
#endif
|
316
355
|
}
|
317
356
|
|
318
357
|
return ULONG2NUM(position);
|
@@ -323,9 +362,13 @@ struct Client {
|
|
323
362
|
Data_Get_Struct(self, Client, p);
|
324
363
|
unsigned long position;
|
325
364
|
|
365
|
+
#ifndef RUBY_UBF_IO
|
326
366
|
TRAP_BEG;
|
367
|
+
#endif
|
327
368
|
position = p->m_binlog->get_position();
|
369
|
+
#ifndef RUBY_UBF_IO
|
328
370
|
TRAP_END;
|
371
|
+
#endif
|
329
372
|
|
330
373
|
return ULONG2NUM(position);
|
331
374
|
}
|
data/ext/ruby_binlog.h
CHANGED
metadata
CHANGED
@@ -1,83 +1,66 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-binlog
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 8
|
10
|
-
version: 0.1.8
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- winebarrel
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2012-11-17 00:00:00 Z
|
12
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
14
|
description: Ruby binding for MySQL Binary log API.
|
22
15
|
email: sgwr_dts@yahoo.co.jp
|
23
16
|
executables: []
|
24
|
-
|
25
|
-
extensions:
|
17
|
+
extensions:
|
26
18
|
- ext/extconf.rb
|
27
|
-
extra_rdoc_files:
|
19
|
+
extra_rdoc_files:
|
28
20
|
- README
|
29
|
-
files:
|
30
|
-
- ext/
|
21
|
+
files:
|
22
|
+
- ext/ruby_binlog_unimplemented_event.cpp
|
23
|
+
- ext/ruby_binlog_table_map_event.cpp
|
24
|
+
- ext/ruby_binlog_rotate_event.cpp
|
25
|
+
- ext/ruby_binlog_cast_to_tcp_driver.cpp
|
31
26
|
- ext/ruby_binlog_xid_event.cpp
|
32
|
-
- ext/ruby_binlog.cpp
|
33
|
-
- ext/ruby_binlog_query_event.cpp
|
34
|
-
- ext/ruby_binlog_event.cpp
|
35
|
-
- ext/ruby_binlog_format_event.cpp
|
36
27
|
- ext/ruby_binlog_row_event.cpp
|
37
|
-
- ext/
|
38
|
-
- ext/
|
28
|
+
- ext/ruby_binlog_format_event.cpp
|
29
|
+
- ext/ruby_binlog_query_event.cpp
|
30
|
+
- ext/ruby_binlog_incident_event.cpp
|
39
31
|
- ext/ruby_binlog_int_var_event.cpp
|
40
|
-
- ext/
|
41
|
-
- ext/
|
32
|
+
- ext/ruby_binlog.cpp
|
33
|
+
- ext/ruby_binlog_event.cpp
|
42
34
|
- ext/ruby_binlog_user_var_event.cpp
|
43
|
-
- ext/
|
44
|
-
- ext/ruby_binlog_event.h
|
35
|
+
- ext/ruby_binlog_get_field_type_str.cpp
|
45
36
|
- ext/ruby_binlog.h
|
37
|
+
- ext/ruby_binlog_event.h
|
46
38
|
- ext/extconf.rb
|
47
39
|
- README
|
48
40
|
homepage: https://bitbucket.org/winebarrel/ruby-binlog
|
49
41
|
licenses: []
|
50
|
-
|
51
42
|
post_install_message:
|
52
|
-
rdoc_options:
|
43
|
+
rdoc_options:
|
53
44
|
- --title
|
54
45
|
- ruby-binlog - Ruby binding for MySQL Binary log API.
|
55
|
-
require_paths:
|
46
|
+
require_paths:
|
56
47
|
- lib
|
57
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
49
|
none: false
|
59
|
-
requirements:
|
60
|
-
- -
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
|
63
|
-
|
64
|
-
- 0
|
65
|
-
version: "0"
|
66
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
55
|
none: false
|
68
|
-
requirements:
|
69
|
-
- -
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
72
|
-
segments:
|
73
|
-
- 0
|
74
|
-
version: "0"
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
75
60
|
requirements: []
|
76
|
-
|
77
61
|
rubyforge_project:
|
78
|
-
rubygems_version: 1.8.
|
62
|
+
rubygems_version: 1.8.23
|
79
63
|
signing_key:
|
80
64
|
specification_version: 3
|
81
65
|
summary: Ruby binding for MySQL Binary log API.
|
82
66
|
test_files: []
|
83
|
-
|