Merge lp:~linuxjedi/libdrizzle/5.1-binlog-callback into lp:libdrizzle

Proposed by Andrew Hutchings
Status: Merged
Merged at revision: 101
Proposed branch: lp:~linuxjedi/libdrizzle/5.1-binlog-callback
Merge into: lp:libdrizzle
Diff against target: 690 lines (+266/-186)
7 files modified
libdrizzle-5.1/binlog.h (+44/-37)
libdrizzle-5.1/constants.h (+3/-0)
libdrizzle/binlog.cc (+154/-113)
libdrizzle/drizzle.cc (+5/-0)
libdrizzle/result.cc (+0/-5)
libdrizzle/structs.h (+34/-5)
tests/unit/binlog.cc (+26/-26)
To merge this branch: bzr merge lp:~linuxjedi/libdrizzle/5.1-binlog-callback
Reviewer Review Type Date Requested Status
Drizzle Trunk Pending
Review via email: mp+145080@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libdrizzle-5.1/binlog.h'
2--- libdrizzle-5.1/binlog.h 2013-01-13 22:31:54 +0000
3+++ libdrizzle-5.1/binlog.h 2013-01-27 05:24:24 +0000
4@@ -42,45 +42,52 @@
5 #endif
6
7 DRIZZLE_API
8-drizzle_result_st *drizzle_start_binlog(drizzle_st *con,
9+drizzle_binlog_st *drizzle_binlog_init(drizzle_st *con,
10+ drizzle_binlog_fn *binlog_fn,
11+ drizzle_binlog_error_fn *error_fn,
12+ void *context,
13+ bool verify_checksums);
14+
15+
16+DRIZZLE_API
17+void drizzle_binlog_free(drizzle_binlog_st *binlog);
18+
19+DRIZZLE_API
20+drizzle_return_t drizzle_binlog_start(drizzle_binlog_st *binlog,
21 uint32_t server_id,
22 const char *file,
23- uint32_t start_position,
24- bool verify_checksums,
25- drizzle_return_t *ret_ptr);
26-
27-DRIZZLE_API
28-drizzle_return_t drizzle_binlog_get_next_event(drizzle_result_st *result);
29-
30-DRIZZLE_API
31-uint32_t drizzle_binlog_event_timestamp(drizzle_result_st *result);
32-
33-DRIZZLE_API
34-drizzle_binlog_event_types_t drizzle_binlog_event_type(drizzle_result_st *result);
35-
36-DRIZZLE_API
37-uint32_t drizzle_binlog_event_server_id(drizzle_result_st *result);
38-
39-DRIZZLE_API
40-uint32_t drizzle_binlog_event_length(drizzle_result_st *result);
41-
42-DRIZZLE_API
43-uint32_t drizzle_binlog_event_next_pos(drizzle_result_st *result);
44-
45-DRIZZLE_API
46-uint16_t drizzle_binlog_event_flags(drizzle_result_st *result);
47-
48-DRIZZLE_API
49-uint16_t drizzle_binlog_event_extra_flags(drizzle_result_st *result);
50-
51-DRIZZLE_API
52-const unsigned char *drizzle_binlog_event_data(drizzle_result_st *result);
53-
54-DRIZZLE_API
55-const unsigned char *drizzle_binlog_event_raw_data(drizzle_result_st *result);
56-
57-DRIZZLE_API
58-uint32_t drizzle_binlog_event_raw_length(drizzle_result_st *result);
59+ uint32_t start_position);
60+
61+
62+DRIZZLE_API
63+uint32_t drizzle_binlog_event_timestamp(drizzle_binlog_event_st *event);
64+
65+DRIZZLE_API
66+drizzle_binlog_event_types_t drizzle_binlog_event_type(drizzle_binlog_event_st *event);
67+
68+DRIZZLE_API
69+uint32_t drizzle_binlog_event_server_id(drizzle_binlog_event_st *event);
70+
71+DRIZZLE_API
72+uint32_t drizzle_binlog_event_length(drizzle_binlog_event_st *event);
73+
74+DRIZZLE_API
75+uint32_t drizzle_binlog_event_next_pos(drizzle_binlog_event_st *event);
76+
77+DRIZZLE_API
78+uint16_t drizzle_binlog_event_flags(drizzle_binlog_event_st *event);
79+
80+DRIZZLE_API
81+uint16_t drizzle_binlog_event_extra_flags(drizzle_binlog_event_st *event);
82+
83+DRIZZLE_API
84+const unsigned char *drizzle_binlog_event_data(drizzle_binlog_event_st *event);
85+
86+DRIZZLE_API
87+const unsigned char *drizzle_binlog_event_raw_data(drizzle_binlog_event_st *event);
88+
89+DRIZZLE_API
90+uint32_t drizzle_binlog_event_raw_length(drizzle_binlog_event_st *event);
91
92 #ifdef __cplusplus
93 }
94
95=== modified file 'libdrizzle-5.1/constants.h'
96--- libdrizzle-5.1/constants.h 2013-01-26 23:09:08 +0000
97+++ libdrizzle-5.1/constants.h 2013-01-27 05:24:24 +0000
98@@ -564,6 +564,7 @@
99 typedef struct drizzle_result_st drizzle_result_st;
100 typedef struct drizzle_column_st drizzle_column_st;
101 typedef struct drizzle_binlog_st drizzle_binlog_st;
102+typedef struct drizzle_binlog_event_st drizzle_binlog_event_st;
103 typedef struct drizzle_stmt_st drizzle_stmt_st;
104 typedef struct drizzle_bind_st drizzle_bind_st;
105 typedef char *drizzle_field_t;
106@@ -571,6 +572,8 @@
107
108 typedef void (drizzle_log_fn)(const char *line, drizzle_verbose_t verbose,
109 void *context);
110+typedef void (drizzle_binlog_fn)(drizzle_binlog_event_st *event, void *context);
111+typedef void (drizzle_binlog_error_fn)(drizzle_return_t error, void *context);
112 typedef drizzle_return_t (drizzle_state_fn)(drizzle_st *con);
113 typedef void (drizzle_context_free_fn)(drizzle_st *con,
114 void *context);
115
116=== modified file 'libdrizzle/binlog.cc'
117--- libdrizzle/binlog.cc 2013-01-27 04:54:08 +0000
118+++ libdrizzle/binlog.cc 2013-01-27 05:24:24 +0000
119@@ -40,24 +40,62 @@
120
121 #include <zlib.h>
122
123-drizzle_result_st *drizzle_start_binlog(drizzle_st *con,
124- uint32_t server_id,
125- const char *file,
126- uint32_t start_position,
127- bool verify_checksums,
128- drizzle_return_t *ret_ptr)
129+drizzle_binlog_st *drizzle_binlog_init(drizzle_st *con,
130+ drizzle_binlog_fn *binlog_fn,
131+ drizzle_binlog_error_fn *error_fn,
132+ void *context,
133+ bool verify_checksums)
134+{
135+ if (con == NULL)
136+ {
137+ return NULL;
138+ }
139+
140+ drizzle_binlog_st *binlog= new (std::nothrow) drizzle_binlog_st;
141+ if (binlog == NULL)
142+ {
143+ drizzle_set_error(con, __func__, "error allocating binlog struct");
144+ return NULL;
145+ }
146+ binlog->con= con;
147+ binlog->binlog_fn= binlog_fn;
148+ binlog->error_fn= error_fn;
149+ binlog->binlog_context= context;
150+ binlog->verify_checksums= verify_checksums;
151+
152+ return binlog;
153+}
154+
155+void drizzle_binlog_free(drizzle_binlog_st *binlog)
156+{
157+ delete binlog;
158+}
159+
160+drizzle_return_t drizzle_binlog_start(drizzle_binlog_st *binlog,
161+ uint32_t server_id,
162+ const char *file,
163+ uint32_t start_position)
164 {
165 unsigned char data[128];
166 unsigned char *ptr;
167 uint8_t len= 0, fn_len= 0;
168 drizzle_result_st *result;
169+ drizzle_st *con;
170+ drizzle_return_t ret;
171+
172+ if (binlog == NULL)
173+ {
174+ return DRIZZLE_RETURN_INVALID_ARGUMENT;
175+ }
176+
177+ con= binlog->con;
178
179 // Hack in 5.6 to say that client support checksums
180- result= drizzle_query(con, "SET @master_binlog_checksum='NONE'", 0, ret_ptr);
181+ result= drizzle_query(con, "SET @master_binlog_checksum='NONE'", 0, &ret);
182 drizzle_result_free(result);
183- if (*ret_ptr != DRIZZLE_RETURN_OK)
184+ if (ret != DRIZZLE_RETURN_OK)
185 {
186- return NULL;
187+ return ret;
188 }
189
190 ptr= data;
191@@ -96,135 +134,128 @@
192 }
193
194 result= drizzle_command_write(con, NULL, DRIZZLE_COMMAND_BINLOG_DUMP,
195- data, len, len, ret_ptr);
196- result->binlog_event= new (std::nothrow) drizzle_binlog_st;
197- result->binlog_event->verify_checksums= verify_checksums;
198- return result;
199-}
200+ data, len, len, &ret);
201
202-drizzle_return_t drizzle_binlog_get_next_event(drizzle_result_st *result)
203-{
204- if (result == NULL)
205+ con->binlog= binlog;
206+ if (ret != DRIZZLE_RETURN_OK)
207 {
208- return DRIZZLE_RETURN_INVALID_ARGUMENT;
209+ return ret;
210 }
211-
212 result->push_state(drizzle_state_binlog_read);
213 result->push_state(drizzle_state_packet_read);
214-
215- return drizzle_state_loop(result->con);
216+ return drizzle_state_loop(con);
217 }
218
219-uint32_t drizzle_binlog_event_timestamp(drizzle_result_st *result)
220+uint32_t drizzle_binlog_event_timestamp(drizzle_binlog_event_st *event)
221 {
222- if ((result == NULL) || (result->binlog_event == NULL))
223+ if (event == NULL)
224 {
225 return 0;
226 }
227
228- return result->binlog_event->timestamp;
229+ return event->timestamp;
230 }
231
232-drizzle_binlog_event_types_t drizzle_binlog_event_type(drizzle_result_st *result)
233+drizzle_binlog_event_types_t drizzle_binlog_event_type(drizzle_binlog_event_st *event)
234 {
235- if ((result == NULL) || (result->binlog_event == NULL))
236+ if (event == NULL)
237 {
238 return drizzle_binlog_event_types_t();
239 }
240
241- return result->binlog_event->type;
242-}
243-
244-uint32_t drizzle_binlog_event_server_id(drizzle_result_st *result)
245-{
246- if ((result == NULL) || (result->binlog_event == NULL))
247- {
248- return 0;
249- }
250-
251- return result->binlog_event->server_id;
252-}
253-
254-uint32_t drizzle_binlog_event_length(drizzle_result_st *result)
255-{
256- if ((result == NULL) || (result->binlog_event == NULL))
257- {
258- return 0;
259- }
260-
261- return result->binlog_event->length;
262-}
263-
264-uint32_t drizzle_binlog_event_next_pos(drizzle_result_st *result)
265-{
266- if ((result == NULL) || (result->binlog_event == NULL))
267- {
268- return 0;
269- }
270-
271- return result->binlog_event->next_pos;
272-}
273-
274-uint16_t drizzle_binlog_event_flags(drizzle_result_st *result)
275-{
276- if ((result == NULL) || (result->binlog_event == NULL))
277- {
278- return 0;
279- }
280-
281- return result->binlog_event->flags;
282-}
283-
284-uint16_t drizzle_binlog_event_extra_flags(drizzle_result_st *result)
285-{
286- if ((result == NULL) || (result->binlog_event == NULL))
287- {
288- return 0;
289- }
290-
291- return result->binlog_event->extra_flags;
292-}
293-
294-const unsigned char *drizzle_binlog_event_data(drizzle_result_st *result)
295-{
296- if ((result == NULL) || (result->binlog_event == NULL))
297- {
298- return NULL;
299- }
300-
301- return result->binlog_event->data;
302-}
303-
304-const unsigned char *drizzle_binlog_event_raw_data(drizzle_result_st *result)
305-{
306- if ((result == NULL) || (result->binlog_event == NULL))
307- {
308- return NULL;
309- }
310-
311- return result->binlog_event->raw_data;
312-}
313-
314-uint32_t drizzle_binlog_event_raw_length(drizzle_result_st *result)
315-{
316- if ((result == NULL) || (result->binlog_event == NULL))
317- {
318- return 0;
319- }
320-
321- return result->binlog_event->raw_length;
322+ return event->type;
323+}
324+
325+uint32_t drizzle_binlog_event_server_id(drizzle_binlog_event_st *event)
326+{
327+ if (event == NULL)
328+ {
329+ return 0;
330+ }
331+
332+ return event->server_id;
333+}
334+
335+uint32_t drizzle_binlog_event_length(drizzle_binlog_event_st *event)
336+{
337+ if (event == NULL)
338+ {
339+ return 0;
340+ }
341+
342+ return event->length;
343+}
344+
345+uint32_t drizzle_binlog_event_next_pos(drizzle_binlog_event_st *event)
346+{
347+ if (event == NULL)
348+ {
349+ return 0;
350+ }
351+
352+ return event->next_pos;
353+}
354+
355+uint16_t drizzle_binlog_event_flags(drizzle_binlog_event_st *event)
356+{
357+ if (event == NULL)
358+ {
359+ return 0;
360+ }
361+
362+ return event->flags;
363+}
364+
365+uint16_t drizzle_binlog_event_extra_flags(drizzle_binlog_event_st *event)
366+{
367+ if (event == NULL)
368+ {
369+ return 0;
370+ }
371+
372+ return event->extra_flags;
373+}
374+
375+const unsigned char *drizzle_binlog_event_data(drizzle_binlog_event_st *event)
376+{
377+ if (event == NULL)
378+ {
379+ return NULL;
380+ }
381+
382+ return event->data;
383+}
384+
385+const unsigned char *drizzle_binlog_event_raw_data(drizzle_binlog_event_st *event)
386+{
387+ if (event == NULL)
388+ {
389+ return NULL;
390+ }
391+
392+ return event->raw_data;
393+}
394+
395+uint32_t drizzle_binlog_event_raw_length(drizzle_binlog_event_st *event)
396+{
397+ if (event == NULL)
398+ {
399+ return 0;
400+ }
401+
402+ return event->raw_length;
403 }
404
405 drizzle_return_t drizzle_state_binlog_read(drizzle_st *con)
406 {
407- drizzle_binlog_st *binlog_event;
408+ drizzle_binlog_event_st *binlog_event;
409
410 if (con == NULL)
411 {
412 return DRIZZLE_RETURN_INVALID_ARGUMENT;
413 }
414
415- binlog_event= con->result->binlog_event;
416+ binlog_event= &con->binlog->event;
417
418 if (con->packet_size != 0 && con->buffer_size < con->packet_size)
419 {
420@@ -240,6 +271,7 @@
421 con->buffer_ptr+= 5;
422 con->buffer_size-= 5;
423 con->pop_state();
424+ con->binlog->error_fn(DRIZZLE_RETURN_EOF, con->binlog->binlog_context);
425 return DRIZZLE_RETURN_EOF;
426 }
427 else if (con->buffer_ptr[0] == 255)
428@@ -267,6 +299,7 @@
429 con->packet_size= 0;
430
431 con->pop_state();
432+ con->binlog->error_fn(DRIZZLE_RETURN_ERROR_CODE, con->binlog->binlog_context);
433 return DRIZZLE_RETURN_ERROR_CODE;
434 }
435 else
436@@ -283,6 +316,7 @@
437 {
438 drizzle_set_error(con, "drizzle_state_binlog_read",
439 "packet size error:%zu:%zu", con->packet_size, binlog_event->length);
440+ con->binlog->error_fn(DRIZZLE_RETURN_UNEXPECTED_DATA, con->binlog->binlog_context);
441 return DRIZZLE_RETURN_UNEXPECTED_DATA;
442 }
443 if (binlog_event->length <= 27)
444@@ -311,7 +345,7 @@
445 {
446 if (strncmp((const char*)con->buffer_ptr + 2, DRIZZLE_BINLOG_CHECKSUM_VERSION, strlen(DRIZZLE_BINLOG_CHECKSUM_VERSION)) <= 0)
447 {
448- con->result->binlog_checksums= true;
449+ con->binlog->has_checksums= true;
450 }
451 }
452 /* A checksum is basically a CRC32 at the end of the event data (4 bytes) */
453@@ -320,7 +354,7 @@
454 con->buffer_size-= binlog_event->length;
455 con->packet_size-= binlog_event->length;
456 /* Remove the CRC32 from the event length */
457- if (con->result->binlog_checksums)
458+ if (con->binlog->has_checksums)
459 {
460 binlog_event->length-= DRIZZLE_BINLOG_CRC32_LEN;
461 }
462@@ -330,16 +364,17 @@
463 * each event is checksummed individually, the checksum is the last 4 bytes
464 * of the binary log event
465 * */
466- if (con->result->binlog_checksums)
467+ if (con->binlog->has_checksums)
468 {
469 uint32_t event_crc;
470 memcpy(&binlog_event->checksum, binlog_event->raw_data + (binlog_event->raw_length - DRIZZLE_BINLOG_CRC32_LEN), DRIZZLE_BINLOG_CRC32_LEN);
471- if (binlog_event->verify_checksums)
472+ if (con->binlog->verify_checksums)
473 {
474 event_crc= crc32(0, binlog_event->raw_data, (binlog_event->raw_length - DRIZZLE_BINLOG_CRC32_LEN));
475 if (event_crc != binlog_event->checksum)
476 {
477 drizzle_set_error(con, __func__, "CRC doesn't match: 0x%lX, 0x%lX", event_crc, binlog_event->checksum);
478+ con->binlog->error_fn(DRIZZLE_RETURN_BINLOG_CRC, con->binlog->binlog_context);
479 return DRIZZLE_RETURN_BINLOG_CRC;
480 }
481 }
482@@ -349,10 +384,16 @@
483 {
484 drizzle_set_error(con, "drizzle_state_binlog_read",
485 "unexpected data after packet:%zu", con->buffer_size);
486+ con->binlog->error_fn(DRIZZLE_RETURN_UNEXPECTED_DATA, con->binlog->binlog_context);
487 return DRIZZLE_RETURN_UNEXPECTED_DATA;
488 }
489 con->pop_state();
490 }
491+
492+ con->binlog->binlog_fn(&con->binlog->event, con->binlog->binlog_context);
493+ con->push_state(drizzle_state_binlog_read);
494+ con->push_state(drizzle_state_packet_read);
495+
496 return DRIZZLE_RETURN_OK;
497 }
498
499
500=== modified file 'libdrizzle/drizzle.cc'
501--- libdrizzle/drizzle.cc 2013-01-27 00:12:38 +0000
502+++ libdrizzle/drizzle.cc 2013-01-27 05:24:24 +0000
503@@ -240,6 +240,11 @@
504 SSL_CTX_free(con->ssl_context);
505 #endif
506
507+ if (con->binlog != NULL)
508+ {
509+ drizzle_binlog_free(con->binlog);
510+ }
511+
512 free(con->buffer);
513 delete con;
514 }
515
516=== modified file 'libdrizzle/result.cc'
517--- libdrizzle/result.cc 2013-01-27 04:54:08 +0000
518+++ libdrizzle/result.cc 2013-01-27 05:24:24 +0000
519@@ -83,11 +83,6 @@
520 return;
521 }
522
523- if (result->binlog_event != NULL)
524- {
525- delete result->binlog_event;
526- }
527-
528 for (column= result->column_list; column != NULL; column= result->column_list)
529 {
530 drizzle_column_free(column);
531
532=== modified file 'libdrizzle/structs.h'
533--- libdrizzle/structs.h 2013-01-27 04:58:03 +0000
534+++ libdrizzle/structs.h 2013-01-27 05:24:24 +0000
535@@ -252,6 +252,7 @@
536 char sqlstate[DRIZZLE_MAX_SQLSTATE_SIZE + 1];
537 char last_error[DRIZZLE_MAX_ERROR_SIZE];
538 drizzle_stmt_st *stmt;
539+ drizzle_binlog_st *binlog;
540 private:
541 size_t _state_stack_count;
542 Packet *_state_stack_list;
543@@ -296,6 +297,7 @@
544 log_fn(NULL),
545 log_context(NULL),
546 stmt(NULL),
547+ binlog(NULL),
548 _state_stack_count(0),
549 _state_stack_list(NULL)
550 {
551@@ -393,8 +395,6 @@
552 drizzle_row_t *row_list;
553 size_t *field_sizes;
554 size_t **field_sizes_list;
555- drizzle_binlog_st *binlog_event;
556- bool binlog_checksums;
557 uint8_t **null_bitmap_list;
558 uint8_t *null_bitmap;
559 uint8_t null_bitmap_length;
560@@ -427,8 +427,6 @@
561 row_list(NULL),
562 field_sizes(NULL),
563 field_sizes_list(NULL),
564- binlog_event(NULL),
565- binlog_checksums(false),
566 null_bitmap_list(NULL),
567 null_bitmap(NULL),
568 null_bitmap_length(0),
569@@ -459,7 +457,7 @@
570 }
571 };
572
573-struct drizzle_binlog_st
574+struct drizzle_binlog_event_st
575 {
576 uint32_t timestamp;
577 drizzle_binlog_event_types_t type;
578@@ -472,7 +470,38 @@
579 unsigned char *data;
580 unsigned char *raw_data;
581 uint32_t raw_length;
582+ drizzle_binlog_event_st() :
583+ timestamp(0),
584+ type(DRIZZLE_EVENT_TYPE_UNKNOWN),
585+ server_id(0),
586+ length(0),
587+ next_pos(0),
588+ flags(0),
589+ extra_flags(0),
590+ checksum(0),
591+ data(NULL),
592+ raw_data(NULL),
593+ raw_length(0)
594+ { }
595+};
596+
597+struct drizzle_binlog_st
598+{
599+ drizzle_binlog_fn *binlog_fn;
600+ drizzle_binlog_error_fn *error_fn;
601+ void *binlog_context;
602+ drizzle_binlog_event_st event;
603 bool verify_checksums;
604+ bool has_checksums;
605+ drizzle_st *con;
606+ drizzle_binlog_st() :
607+ binlog_fn(NULL),
608+ error_fn(NULL),
609+ binlog_context(NULL),
610+ verify_checksums(false),
611+ has_checksums(false),
612+ con(NULL)
613+ { }
614 };
615
616 /**
617
618=== modified file 'tests/unit/binlog.cc'
619--- tests/unit/binlog.cc 2013-01-27 00:09:17 +0000
620+++ tests/unit/binlog.cc 2013-01-27 05:24:24 +0000
621@@ -45,10 +45,33 @@
622 #include <cstdio>
623 #include <cstdlib>
624
625+void binlog_error(drizzle_return_t ret, void *context)
626+{
627+ (void) context;
628+ ASSERT_EQ_(DRIZZLE_RETURN_EOF, ret, "%s(%s)", drizzle_error(con), drizzle_strerror(ret));
629+}
630+
631+void binlog_event(drizzle_binlog_event_st *event, void *context)
632+{
633+ (void) context;
634+ uint32_t timestamp;
635+ timestamp= drizzle_binlog_event_timestamp(event);
636+ /* Test to see if timestamp is greater than 2012-01-01 00:00:00, corrupted
637+ * timestamps will have weird values that shoud fail this after several
638+ * events. Also rotate event doesn't have a timestamp so need to add 0
639+ * to this test */
640+ ASSERT_FALSE_(((timestamp < 1325376000) && (timestamp != 0)), "Bad timestamp retrieved: %u", timestamp);
641+
642+ /* An event higher than the max known is bad, either we don't know about
643+ * new events or type is corrupted */
644+ ASSERT_FALSE_((drizzle_binlog_event_type(event) >= DRIZZLE_EVENT_TYPE_END), "Bad event type: %d", drizzle_binlog_event_type(event));
645+}
646+
647 int main(int argc, char *argv[])
648 {
649 (void) argc;
650 (void) argv;
651+ drizzle_binlog_st *binlog;
652
653 con= drizzle_create_tcp(getenv("MYSQL_SERVER"),
654 getenv("MYSQL_PORT") ? atoi("MYSQL_PORT") : DRIZZLE_DEFAULT_TCP_PORT,
655@@ -62,32 +85,9 @@
656 drizzle_return_t ret= drizzle_connect(con);
657 SKIP_IF_(ret == DRIZZLE_RETURN_COULD_NOT_CONNECT, "%s(%s)", drizzle_error(con), drizzle_strerror(ret));
658 ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "%s(%s)", drizzle_error(con), drizzle_strerror(ret));
659-
660- drizzle_result_st *result= drizzle_start_binlog(con, 0, "", 0, true, &ret);
661- ASSERT_TRUE(result);
662+ binlog= drizzle_binlog_init(con, binlog_event, binlog_error, NULL, true);
663+ ret= drizzle_binlog_start(binlog, 0, "", 0);
664 SKIP_IF_(ret == DRIZZLE_RETURN_ERROR_CODE, "Binlog is not open?: %s(%s)", drizzle_error(con), drizzle_strerror(ret));
665- ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "Drizzle binlog start failure: %s(%s)", drizzle_error(con), drizzle_strerror(ret));
666-
667- while (ret == DRIZZLE_RETURN_OK)
668- {
669- uint32_t timestamp;
670- ret= drizzle_binlog_get_next_event(result);
671- if (ret == DRIZZLE_RETURN_EOF)
672- {
673- break;
674- }
675- ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "Binlog error %s\n", drizzle_error(con));
676- timestamp= drizzle_binlog_event_timestamp(result);
677- /* Test to see if timestamp is greater than 2012-01-01 00:00:00, corrupted
678- * timestamps will have weird values that shoud fail this after several
679- * events. Also rotate event doesn't have a timestamp so need to add 0
680- * to this test */
681- ASSERT_FALSE_(((timestamp < 1325376000) && (timestamp != 0)), "Bad timestamp retrieved: %u", timestamp);
682-
683- /* An event higher than the max known is bad, either we don't know about
684- * new events or type is corrupted */
685- ASSERT_FALSE_((drizzle_binlog_event_type(result) >= DRIZZLE_EVENT_TYPE_END), "Bad event type: %d", drizzle_binlog_event_type(result));
686- }
687-
688+ ASSERT_EQ_(DRIZZLE_RETURN_EOF, ret, "Drizzle binlog start failure: %s(%s)", drizzle_error(con), drizzle_strerror(ret));
689 return EXIT_SUCCESS;
690 }

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: