mydumper is tocuhing internal MySQL API it should not be. upstream has disabled

the binlog support until something can be done to fix it properly.

"The real problem here is that no application should ever include sql_common.h
or try to execute, the internal to libmysql functions, simple_command() or
advanced_command() directly.

The primary reason for this is that these functions are not safe for internal
API or structure changes and may cause applications crashes between even minor
versions of libmysql.a"

https://bugs.launchpad.net/mydumper/+bug/1316001

ok giovanni@
This commit is contained in:
brad 2014-09-15 17:10:45 +00:00
parent 2aa4bbe141
commit fd4b0044b4
4 changed files with 245 additions and 14 deletions

View File

@ -1,10 +1,10 @@
# $OpenBSD: Makefile,v 1.5 2014/09/13 18:09:20 brad Exp $$
# $OpenBSD: Makefile,v 1.6 2014/09/15 17:10:45 brad Exp $$
COMMENT = utility for quick MySQL dumping
V = 0.6.1
DISTNAME = mydumper-${V}
REVISION = 0
REVISION = 1
CATEGORIES = databases
MAINTAINER = Giovanni Bechis <giovanni@openbsd.org>
@ -12,7 +12,8 @@ MAINTAINER = Giovanni Bechis <giovanni@openbsd.org>
# GPLv3+
PERMIT_PACKAGE_CDROM = Yes
WANTLIB += c glib-2.0 gthread-2.0 m mysqlclient_r pcre pthread z
WANTLIB += c crypto glib-2.0 gthread-2.0 m mysqlclient_r pcre pthread
WANTLIB += ssl z
MASTER_SITES = https://launchpad.net/mydumper/${V:R}/${V}/+download/

View File

@ -1,12 +1,46 @@
$OpenBSD: patch-CMakeLists_txt,v 1.1.1.1 2013/09/24 14:44:44 giovanni Exp $
--- CMakeLists.txt.orig Tue Sep 24 14:55:22 2013
+++ CMakeLists.txt Tue Sep 24 14:56:43 2013
@@ -16,7 +16,7 @@ if (BUILD_DOCS)
$OpenBSD: patch-CMakeLists_txt,v 1.2 2014/09/15 17:10:45 brad Exp $
binlog code now is optional, disabled by default
http://bazaar.launchpad.net/~perconardba/mydumper/0.6/revision/144
--- CMakeLists.txt.orig Tue Feb 25 10:18:05 2014
+++ CMakeLists.txt Sun Sep 14 12:32:25 2014
@@ -16,8 +16,10 @@ if (BUILD_DOCS)
add_subdirectory(docs)
endif (BUILD_DOCS)
-set(CMAKE_C_FLAGS "-Wall -Wno-deprecated-declarations -Wunused -Wwrite-strings -Wno-strict-aliasing -Wextra -Wshadow -Werror -O3 -g ${MYSQL_CFLAGS}")
+set(CMAKE_C_FLAGS "-Wall -Wno-deprecated-declarations -Wunused -Wwrite-strings -Wno-strict-aliasing -Wextra -Wshadow -Werror ${MYSQL_CFLAGS}")
+option(WITH_BINLOG "Build binlog dump options" OFF)
+set(CMAKE_C_FLAGS "-Wall -Wno-deprecated-declarations -Wunused -Wwrite-strings -Wno-strict-aliasing -Wextra -Wshadow -Werror ${MYSQL_CFLAGS}")
+
include_directories(${MYDUMPER_SOURCE_DIR} ${MYSQL_INCLUDE_DIR} ${GLIB2_INCLUDE_DIR} ${PCRE_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS})
if (NOT CMAKE_INSTALL_PREFIX)
@@ -27,9 +29,15 @@ MARK_AS_ADVANCED(CMAKE)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h)
-add_executable(mydumper mydumper.c binlog.c server_detect.c g_unix_signal.c)
-target_link_libraries(mydumper ${MYSQL_LIBRARIES_mysqlclient_r} ${GLIB2_LIBRARIES} ${GTHREAD2_LIBRARIES} ${PCRE_PCRE_LIBRARY} ${ZLIB_LIBRARIES})
+if (WITH_BINLOG)
+ add_executable(mydumper mydumper.c binlog.c server_detect.c g_unix_signal.c)
+else (WITH_BINLOG)
+ add_executable(mydumper mydumper.c server_detect.c g_unix_signal.c)
+endif (WITH_BINLOG)
+target_link_libraries(mydumper ${MYSQL_LIBRARIES} ${GLIB2_LIBRARIES} ${GTHREAD2_LIBRARIES} ${PCRE_PCRE_LIBRARY} ${ZLIB_LIBRARIES})
+
+
add_executable(myloader myloader.c)
target_link_libraries(myloader ${MYSQL_LIBRARIES_mysqlclient_r} ${GLIB2_LIBRARIES} ${GTHREAD2_LIBRARIES} ${PCRE_PCRE_LIBRARY} ${ZLIB_LIBRARIES})
@@ -55,6 +63,7 @@ MESSAGE(STATUS "--------------------------------------
MESSAGE(STATUS "MYSQL_CONFIG = ${MYSQL_CONFIG}")
MESSAGE(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
MESSAGE(STATUS "BUILD_DOCS = ${BUILD_DOCS}")
+MESSAGE(STATUS "WITH_BINLOG = ${WITH_BINLOG}")
MESSAGE(STATUS "RUN_CPPCHECK = ${RUN_CPPCHECK}")
MESSAGE(STATUS "Change a values with: cmake -D<Variable>=<Value>")
MESSAGE(STATUS "------------------------------------------------")

View File

@ -0,0 +1,15 @@
$OpenBSD: patch-config_h_in,v 1.1 2014/09/15 17:10:45 brad Exp $
binlog code now is optional, disabled by default
http://bazaar.launchpad.net/~perconardba/mydumper/0.6/revision/144
--- config.h.in.orig Tue Feb 25 10:18:05 2014
+++ config.h.in Sun Sep 14 12:26:03 2014
@@ -2,5 +2,6 @@
#define CONFIG_H
#cmakedefine VERSION "@VERSION@"
+#cmakedefine WITH_BINLOG
#endif

View File

@ -1,15 +1,164 @@
$OpenBSD: patch-mydumper_c,v 1.1.1.1 2013/09/24 14:44:44 giovanni Exp $
--- mydumper.c.orig Mon Sep 16 09:04:58 2013
+++ mydumper.c Mon Sep 16 09:21:48 2013
@@ -579,6 +579,7 @@ MYSQL *create_main_connection()
$OpenBSD: patch-mydumper_c,v 1.2 2014/09/15 17:10:45 brad Exp $
binlog code now is optional, disabled by default
http://bazaar.launchpad.net/~perconardba/mydumper/0.6/revision/144
--- mydumper.c.orig Sun Sep 14 12:26:44 2014
+++ mydumper.c Sun Sep 14 12:26:03 2014
@@ -34,18 +34,24 @@
#include <pcre.h>
#include <signal.h>
#include <glib/gstdio.h>
+#include "config.h"
+#ifdef WITH_BINLOG
#include "binlog.h"
+#else
+#include "mydumper.h"
+#endif
#include "server_detect.h"
#include "common.h"
#include "g_unix_signal.h"
-#include "config.h"
#include <math.h>
char *regexstring=NULL;
const char DIRECTORY[]= "export";
+#ifdef WITH_BINLOG
const char BINLOG_DIRECTORY[]= "binlog_snapshot";
const char DAEMON_BINLOGS[]= "binlogs";
+#endif
static GMutex * init_mutex = NULL;
@@ -70,9 +76,11 @@ char **ignore= NULL;
gchar *tables_list= NULL;
char **tables= NULL;
+#ifdef WITH_BINLOG
gboolean need_binlogs= FALSE;
gchar *binlog_directory= NULL;
gchar *daemon_binlog_directory= NULL;
+#endif
gchar *logfile= NULL;
FILE *logoutfile= NULL;
@@ -118,7 +126,9 @@ static GOptionEntry entries[] =
{ "less-locking", 0, 0, G_OPTION_ARG_NONE, &less_locking, "Minimize locking time on InnoDB tables.", NULL},
{ "long-query-guard", 'l', 0, G_OPTION_ARG_INT, &longquery, "Set long query timer in seconds, default 60", NULL },
{ "kill-long-queries", 'k', 0, G_OPTION_ARG_NONE, &killqueries, "Kill long running queries (instead of aborting)", NULL },
+#ifdef WITH_BINLOG
{ "binlogs", 'b', 0, G_OPTION_ARG_NONE, &need_binlogs, "Get a snapshot of the binary logs as well as dump data", NULL },
+#endif
{ "daemon", 'D', 0, G_OPTION_ARG_NONE, &daemon_mode, "Enable daemon mode", NULL },
{ "snapshot-interval", 'I', 0, G_OPTION_ARG_INT, &snapshot_interval, "Interval between each dump snapshot (in minutes), requires --daemon, default 60", NULL },
{ "logfile", 'L', 0, G_OPTION_ARG_FILENAME, &logfile, "Log file name to use, by default stdout is used", NULL },
@@ -145,10 +155,12 @@ gboolean write_data(FILE *,GString*);
gboolean check_regex(char *database, char *table);
void no_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data);
void set_verbose(guint verbosity);
+#ifdef WITH_BINLOG
MYSQL *reconnect_for_binlog(MYSQL *thrconn);
+void *binlog_thread(void *data);
+#endif
void start_dump(MYSQL *conn);
MYSQL *create_main_connection();
-void *binlog_thread(void *data);
void *exec_thread(void *data);
void write_log_file(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data);
@@ -368,8 +380,9 @@ void *process_queue(struct thread_data *td) {
struct job* job= NULL;
struct table_job* tj= NULL;
struct schema_job* sj= NULL;
+ #ifdef WITH_BINLOG
struct binlog_job* bj= NULL;
-
+ #endif
/* if less locking we need to wait until that threads finish
progressively waking up this threads */
if(less_locking){
@@ -446,6 +459,7 @@ void *process_queue(struct thread_data *td) {
g_free(sj);
g_free(job);
break;
+ #ifdef WITH_BINLOG
case JOB_BINLOG:
thrconn= reconnect_for_binlog(thrconn);
g_message("Thread %d connected using MySQL connection ID %lu (in binlog mode)", td->thread_id, mysql_thread_id(thrconn));
@@ -457,6 +471,7 @@ void *process_queue(struct thread_data *td) {
g_free(bj);
g_free(job);
break;
+ #endif
case JOB_SHUTDOWN:
g_message("Thread %d shutting down", td->thread_id);
if (thrconn)
@@ -599,7 +614,7 @@ void *process_queue_less_locking(struct thread_data *t
mysql_thread_end();
return NULL;
}
-
+#ifdef WITH_BINLOG
MYSQL *reconnect_for_binlog(MYSQL *thrconn) {
if (thrconn) {
mysql_close(thrconn);
@@ -620,7 +635,7 @@ MYSQL *reconnect_for_binlog(MYSQL *thrconn) {
}
return thrconn;
}
-
+#endif
int main(int argc, char *argv[])
{
GError *error = NULL;
@@ -697,15 +712,17 @@ int main(int argc, char *argv[])
dump_directory= g_strdup_printf("%s/1", output_directory);
create_backup_dir(dump_directory);
g_free(dump_directory);
+ #ifdef WITH_BINLOG
daemon_binlog_directory= g_strdup_printf("%s/%s", output_directory, DAEMON_BINLOGS);
create_backup_dir(daemon_binlog_directory);
+ #endif
}
-
+ #ifdef WITH_BINLOG
if (need_binlogs) {
binlog_directory = g_strdup_printf("%s/%s", output_directory, BINLOG_DIRECTORY);
create_backup_dir(binlog_directory);
}
-
+ #endif
/* Give ourselves an array of engines to ignore */
if (ignore_engines)
ignore = g_strsplit(ignore_engines, ",", 0);
@@ -716,14 +733,14 @@ int main(int argc, char *argv[])
if (daemon_mode) {
GError* terror;
-
+ #ifdef WITH_BINLOG
GThread *bthread= g_thread_create(binlog_thread, GINT_TO_POINTER(1), FALSE, &terror);
if (bthread == NULL) {
g_critical("Could not create binlog thread: %s", terror->message);
g_error_free(terror);
exit(EXIT_FAILURE);
}
-
+ #endif
start_scheduled_dump= g_async_queue_new();
GThread *ethread= g_thread_create(exec_thread, GINT_TO_POINTER(1), FALSE, &terror);
if (ethread == NULL) {
@@ -770,6 +787,7 @@ MYSQL *create_main_connection()
if (!mysql_real_connect(conn, hostname, username, password, db, port, socket_path, 0)) {
g_critical("Error connecting to database: %s", mysql_error(conn));
+ rmdir(output_directory);
exit(EXIT_FAILURE);
}
if ((detected_server == SERVER_TYPE_MYSQL) && mysql_query(conn, "SET SESSION wait_timeout = 2147483")){
@@ -598,6 +599,7 @@ MYSQL *create_main_connection()
@@ -791,6 +809,7 @@ MYSQL *create_main_connection()
break;
default:
g_critical("Cannot detect server type");
@ -17,3 +166,35 @@ $OpenBSD: patch-mydumper_c,v 1.1.1.1 2013/09/24 14:44:44 giovanni Exp $
exit(EXIT_FAILURE);
break;
}
@@ -827,7 +846,7 @@ void *exec_thread(void *data) {
}
return NULL;
}
-
+#ifdef WITH_BINLOG
void *binlog_thread(void *data) {
(void) data;
MYSQL_RES *master= NULL;
@@ -863,7 +882,7 @@ void *binlog_thread(void *data) {
mysql_thread_end();
return NULL;
}
-
+#endif
void start_dump(MYSQL *conn)
{
struct configuration conf = { 1, NULL, NULL, NULL, NULL, NULL, NULL, 0 };
@@ -1087,11 +1106,11 @@ void start_dump(MYSQL *conn)
g_message("Non-InnoDB dump complete, unlocking tables");
mysql_query(conn, "UNLOCK TABLES /* FTWRL */");
}
-
+ #ifdef WITH_BINLOG
if (need_binlogs) {
get_binlogs(conn, &conf);
}
-
+ #endif
// close main connection
mysql_close(conn);