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

Proposed by Andrew Hutchings
Status: Merged
Approved by: Andrew Hutchings
Approved revision: 71
Merged at revision: 70
Proposed branch: lp:~linuxjedi/libdrizzle/5.1-binlog-csums
Merge into: lp:libdrizzle
Diff against target: 271 lines (+144/-2)
9 files modified
configure.ac (+1/-0)
libdrizzle-5.1/constants.h (+3/-0)
libdrizzle-5.1/return.h (+1/-0)
libdrizzle/binlog.cc (+50/-2)
libdrizzle/error.cc (+1/-0)
libdrizzle/include.am (+4/-0)
libdrizzle/result.cc (+1/-0)
libdrizzle/structs.h (+3/-0)
m4/zlib.m4 (+80/-0)
To merge this branch: bzr merge lp:~linuxjedi/libdrizzle/5.1-binlog-csums
Reviewer Review Type Date Requested Status
Drizzle Trunk Pending
Review via email: mp+141460@code.launchpad.net

Description of the change

Adds support for MySQL 5.6 checksummed binary logs.

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 'configure.ac'
2--- configure.ac 2012-12-29 10:49:09 +0000
3+++ configure.ac 2012-12-29 17:35:25 +0000
4@@ -58,6 +58,7 @@
5 # Checks for libraries.
6 AX_CXX_GCC_ABI_DEMANGLE
7 AX_CHECK_OPENSSL
8+AC_PATH_ZLIB
9
10 # Checks for header files.
11 AC_DEFUN([CHECK_FOR_CXXABI],
12
13=== modified file 'libdrizzle-5.1/constants.h'
14--- libdrizzle-5.1/constants.h 2012-12-24 10:20:04 +0000
15+++ libdrizzle-5.1/constants.h 2012-12-29 17:35:25 +0000
16@@ -84,6 +84,9 @@
17 #define DRIZZLE_DEFAULT_SOCKET_SEND_SIZE 32768
18 #define DRIZZLE_DEFAULT_SOCKET_RECV_SIZE 32768
19 #define DRIZZLE_MYSQL_PASSWORD_HASH 41
20+#define DRIZZLE_BINLOG_CRC32_LEN 4
21+// If this version or higher then we are doing checksums
22+#define DRIZZLE_BINLOG_CHECKSUM_VERSION "5.6.1"
23
24 #define DRIZZLE_BINLOG_MAGIC "\xFE\x62\x69\x6E"
25
26
27=== modified file 'libdrizzle-5.1/return.h'
28--- libdrizzle-5.1/return.h 2012-12-23 01:05:57 +0000
29+++ libdrizzle-5.1/return.h 2012-12-29 17:35:25 +0000
30@@ -70,6 +70,7 @@
31 DRIZZLE_RETURN_SSL_ERROR,
32 DRIZZLE_RETURN_EOF,
33 DRIZZLE_RETURN_STMT_ERROR,
34+ DRIZZLE_RETURN_BINLOG_CRC,
35 DRIZZLE_RETURN_MAX /* Always add new codes to the end before this one. */
36 };
37
38
39=== modified file 'libdrizzle/binlog.cc'
40--- libdrizzle/binlog.cc 2012-12-29 08:51:15 +0000
41+++ libdrizzle/binlog.cc 2012-12-29 17:35:25 +0000
42@@ -37,6 +37,7 @@
43
44 #include "config.h"
45 #include "libdrizzle/common.h"
46+#include <zlib.h>
47
48 drizzle_result_st *drizzle_start_binlog(drizzle_st *con,
49 uint32_t server_id,
50@@ -47,6 +48,15 @@
51 uint8_t data[128];
52 uint8_t *ptr;
53 uint8_t len= 0, fn_len= 0;
54+ drizzle_result_st *result;
55+
56+ // Hack in 5.6 to say that client support checksums
57+ result= drizzle_query_str(con, "SET @master_binlog_checksum='NONE'", ret_ptr);
58+ drizzle_result_free(result);
59+ if (*ret_ptr != DRIZZLE_RETURN_OK)
60+ {
61+ return NULL;
62+ }
63
64 ptr= data;
65
66@@ -297,11 +307,49 @@
67 con->buffer_size-= 27;
68 con->packet_size-= 27;
69 binlog_event->data= (uint8_t*)realloc(binlog_event->data, binlog_event->length);
70- memcpy(binlog_event->data, con->buffer_ptr, binlog_event->length);
71+ /* 5.6.1 or higher is automatic checksums on */
72+ if (binlog_event->type == DRIZZLE_EVENT_TYPE_FORMAT_DESCRIPTION)
73+ {
74+ if (strncmp((const char*)con->buffer_ptr + 2, DRIZZLE_BINLOG_CHECKSUM_VERSION, strlen(DRIZZLE_BINLOG_CHECKSUM_VERSION)) <= 0)
75+ {
76+ con->result->binlog_checksums= true;
77+ }
78+ }
79+ /* A checksum is basically a CRC32 at the end of the event data (4 bytes) */
80+ if (con->result->binlog_checksums)
81+ {
82+ memcpy(binlog_event->data, con->buffer_ptr, binlog_event->length - DRIZZLE_BINLOG_CRC32_LEN);
83+ }
84+ else
85+ {
86+ memcpy(binlog_event->data, con->buffer_ptr, binlog_event->length);
87+ }
88 con->buffer_ptr+= binlog_event->length;
89 con->buffer_size-= binlog_event->length;
90 con->packet_size-= binlog_event->length;
91- }
92+ /* Remove the CRC32 from the event length */
93+ if (con->result->binlog_checksums)
94+ {
95+ binlog_event->length-= DRIZZLE_BINLOG_CRC32_LEN;
96+ }
97+ }
98+
99+ /* Check if checksum is correct
100+ * each event is checksummed individually, the checksum is the last 4 bytes
101+ * of the binary log event
102+ * */
103+ if (con->result->binlog_checksums)
104+ {
105+ uint32_t event_crc;
106+ memcpy(&binlog_event->checksum, binlog_event->raw_data + (binlog_event->raw_length - DRIZZLE_BINLOG_CRC32_LEN), DRIZZLE_BINLOG_CRC32_LEN);
107+ event_crc= crc32(0, binlog_event->raw_data, (binlog_event->raw_length - DRIZZLE_BINLOG_CRC32_LEN));
108+ if (event_crc != binlog_event->checksum)
109+ {
110+ drizzle_set_error(con, __func__, "CRC doesn't match: 0x%lX, 0x%lX", event_crc, binlog_event->checksum);
111+ return DRIZZLE_RETURN_BINLOG_CRC;
112+ }
113+ }
114+
115 if (con->packet_size != 0)
116 {
117 drizzle_set_error(con, "drizzle_state_binlog_read",
118
119=== modified file 'libdrizzle/error.cc'
120--- libdrizzle/error.cc 2012-12-23 01:05:57 +0000
121+++ libdrizzle/error.cc 2012-12-29 17:35:25 +0000
122@@ -69,6 +69,7 @@
123 case DRIZZLE_RETURN_SSL_ERROR: return "DRIZZLE_RETURN_SSL_ERROR";
124 case DRIZZLE_RETURN_EOF: return "DRIZZLE_RETURN_EOF";
125 case DRIZZLE_RETURN_STMT_ERROR: return "DRIZZLE_RETURN_STMT_ERROR";
126+ case DRIZZLE_RETURN_BINLOG_CRC: return "DRIZZLE_RETURN_BINLOG_CRC";
127 case DRIZZLE_RETURN_MAX: return "DRIZZLE_RETURN_MAX";
128 }
129
130
131=== modified file 'libdrizzle/include.am'
132--- libdrizzle/include.am 2012-12-23 01:05:57 +0000
133+++ libdrizzle/include.am 2012-12-29 17:35:25 +0000
134@@ -18,8 +18,12 @@
135
136 libdrizzle_libdrizzle_la_CFLAGS+= @OPENSSL_INCLUDES@
137 libdrizzle_libdrizzle_la_CXXFLAGS+= @OPENSSL_INCLUDES@
138+libdrizzle_libdrizzle_la_CFLAGS+= @ZLIB_CFLAGS@
139+libdrizzle_libdrizzle_la_CXXFLAGS+= @ZLIB_CFLAGS@
140 libdrizzle_libdrizzle_la_LIBADD+= @OPENSSL_LIBS@
141+libdrizzle_libdrizzle_la_LIBADD+= @ZLIB_LIBS@
142 libdrizzle_libdrizzle_la_LDFLAGS+= @OPENSSL_LDFLAGS@
143+libdrizzle_libdrizzle_la_LDFLAGS+= @ZLIB_LDFLAGS@
144
145 libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/binlog.cc
146 libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/command.cc
147
148=== modified file 'libdrizzle/result.cc'
149--- libdrizzle/result.cc 2012-12-28 10:37:41 +0000
150+++ libdrizzle/result.cc 2012-12-29 17:35:25 +0000
151@@ -62,6 +62,7 @@
152 return NULL;
153 }
154
155+ result->binlog_checksums= false;
156 result->binlog_event= NULL;
157 result->column_list= NULL;
158 result->options= DRIZZLE_RESULT_NONE;
159
160=== modified file 'libdrizzle/structs.h'
161--- libdrizzle/structs.h 2012-12-23 10:47:57 +0000
162+++ libdrizzle/structs.h 2012-12-29 17:35:25 +0000
163@@ -186,6 +186,7 @@
164 size_t *field_sizes;
165 size_t **field_sizes_list;
166 drizzle_binlog_st *binlog_event;
167+ bool binlog_checksums;
168 uint8_t **null_bitmap_list;
169 uint8_t *null_bitmap;
170 uint8_t null_bitmap_length;
171@@ -221,6 +222,7 @@
172 field_sizes(NULL),
173 field_sizes_list(NULL),
174 binlog_event(NULL),
175+ binlog_checksums(false),
176 null_bitmap_list(NULL),
177 null_bitmap(NULL),
178 null_bitmap_length(0),
179@@ -242,6 +244,7 @@
180 uint32_t next_pos;
181 uint16_t flags;
182 uint16_t extra_flags;
183+ uint32_t checksum;
184 uint8_t *data;
185 uint8_t *raw_data;
186 uint32_t raw_length;
187
188=== added file 'm4/zlib.m4'
189--- m4/zlib.m4 1970-01-01 00:00:00 +0000
190+++ m4/zlib.m4 2012-12-29 17:35:25 +0000
191@@ -0,0 +1,80 @@
192+ AC_DEFUN([AC_PATH_ZLIB], [
193+ AC_ARG_WITH(zlib,
194+ AC_HELP_STRING([--with-zlib=DIR],
195+ [search for ZLIB in DIR/include and DIR/lib]),
196+ [for dir in `echo "$withval" | tr : ' '`; do
197+ if test -d $dir/include; then
198+ ZLIB_CFLAGS="$ZLIB_CFLAGS -I$dir/include"
199+ fi
200+ if test -d $dir/lib; then
201+ ZLIB_LDFLAGS="$ZLIB_LDFLAGS -L$dir/lib"
202+ fi
203+ done[]])
204+
205+ AC_ARG_WITH(zlib-includes,
206+ AC_HELP_STRING([--with-zlib-includes=DIR],
207+ [search for ZLIB includes in DIR]),
208+ [for dir in `echo "$withval" | tr : ' '`; do
209+ if test -d $dir; then
210+ ZLIB_CFLAGS="$ZLIB_CFLAGS -I$dir"
211+ fi
212+ done[]])
213+
214+ac_zlib_saved_CFLAGS="$CFLAGS"
215+ac_zlib_saved_LDFLAGS="$LDFLAGS"
216+ac_zlib_saved_LIBS="$LIBS"
217+CFLAGS="$CFLAGS $ZLIB_CFLAGS"
218+LDFLAGS="$LDFLAGS $ZLIB_LDFLAGS"
219+ac_have_zlibh=no
220+ac_have_zlib=no
221+ touch /tmp/dummy1_zlib.h
222+ AC_CHECK_HEADERS([/tmp/dummy1_zlib.h], [ac_have_zlibh=yes], [ac_have_zlibh=no],
223+ [#include "zlib.h"])
224+ rm /tmp/dummy1_zlib.h
225+ if test $ac_have_zlibh = yes; then
226+ AC_SEARCH_LIBS(gzopen, [z], [ac_have_zlib=yes], [ac_have_zlib=no])
227+ fi
228+# List of places to try
229+testdirs="$HOME/opt/zlib $OBITINSTALL/other"
230+for dir in $testdirs; do
231+ if test $ac_have_zlib = no; then
232+ if test -f $dir/include/zlib.h; then
233+ ZLIB_CFLAGS="-I$dir/include"
234+ CPPFLAGS="$ac_zlib_saved_CPPFLAGS $ZLIB_CFLAGS"
235+ ZLIB_LDFLAGS="-L$dir/lib"
236+ LDFLAGS="$ac_zlib_saved_LDFLAGS $ZLIB_LDFLAGS"
237+ touch /tmp/dummy3_zlib.h
238+ AC_CHECK_HEADERS([/tmp/dummy3_zlib.h], [ac_have_zlibh=yes], [ac_have_zlibh=no],
239+ [#include "zlib.h"])
240+ rm /tmp/dummy3_zlib.h
241+ if test $ac_have_zlibh = yes; then
242+ # Force check
243+ ac_cv_search_gzopen=" "
244+ AC_SEARCH_LIBS(gzopen, [z], [ac_have_zlib=yes], [ac_have_zlib=no])
245+ fi
246+ if test $ac_have_zlib = yes ; then
247+ if test $ac_have_zlibh = yes ; then
248+ break;
249+ fi
250+ fi
251+ fi
252+ fi
253+done[]
254+if test $ac_have_zlib = no; then
255+ AC_MSG_WARN([cannot find ZLIB library])
256+fi
257+if test $ac_have_zlibh = no; then
258+ AC_MSG_WARN([cannot find ZLIB headers])
259+ ac_have_zlib=no
260+fi
261+if test $ac_have_zlib = yes; then
262+ AC_DEFINE(HAVE_ZLIB, 1, [Define to 1 if ZLIB is available.])
263+fi
264+ZLIB_LIBS="$LIBS"
265+CFLAGS="$ac_zlib_saved_CFLAGS"
266+LDFLAGS="$ac_zlib_saved_LDFLAGS"
267+LIBS="$ac_zlib_saved_LIBS"
268+ AC_SUBST(ZLIB_CFLAGS)
269+ AC_SUBST(ZLIB_LDFLAGS)
270+ AC_SUBST(ZLIB_LIBS)
271+])

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: