Merge lp:~xavier+ubuntu/mydumper/mydumper into lp:mydumper

Proposed by Xavier G. on 2015-03-18
Status: Needs review
Proposed branch: lp:~xavier+ubuntu/mydumper/mydumper
Merge into: lp:mydumper
Diff against target: 166 lines (+49/-0)
5 files modified
common.h (+2/-0)
docs/mydumper_usage.rst (+5/-0)
docs/myloader_usage.rst (+5/-0)
mydumper.c (+20/-0)
myloader.c (+17/-0)
To merge this branch: bzr merge lp:~xavier+ubuntu/mydumper/mydumper
Reviewer Review Type Date Requested Status
Max Bubenick 2015-03-18 Pending
Review via email: mp+253344@code.launchpad.net

Description of the change

A few months ago, I needed to specify the wait_timeout parameter when loading a database (mydumper enforces it but myloader does not). That day, I simply patched and recompiled myloader so it works for me and took note that I should report a fix for that issue.
Initially, I wanted to implement a --wait-timeout option but it quickly occurred to me that it would be more practical to enable users to insert their own SQL statements after connection to database is established. That is why I have implemented a --init-command switch, which can be used to insert one or several custom commands before mydumper and myloader actually perform their job.

Example: myloader -o -h mysqlserver -u me -p $password -B dbname -d dbname/ \
           --init-command='SET SESSION net_write_timeout = 2147483' \
           --init-command='SET GLOBAL SESSION wait_timeout = 2147483'

To post a comment you must log in.

Unmerged revisions

171. By Xavier G. <email address hidden> on 2015-03-18

Add the "--init-command" option.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'common.h'
2--- common.h 2011-05-16 13:52:26 +0000
3+++ common.h 2015-03-18 12:25:28 +0000
4@@ -17,6 +17,7 @@
5 #ifndef _common_h
6 #define _common_h
7
8+char **init_commands=NULL;
9 char *hostname=NULL;
10 char *username=NULL;
11 char *password=NULL;
12@@ -30,6 +31,7 @@
13
14 GOptionEntry common_entries[] =
15 {
16+ { "init-command", 0, 0, G_OPTION_ARG_STRING_ARRAY, &init_commands, "Custom initial command; may appear more than once on the command line", NULL },
17 { "host", 'h', 0, G_OPTION_ARG_STRING, &hostname, "The host to connect to", NULL },
18 { "user", 'u', 0, G_OPTION_ARG_STRING, &username, "Username with privileges to run the dump", NULL },
19 { "password", 'p', 0, G_OPTION_ARG_STRING, &password, "User password", NULL },
20
21=== modified file 'docs/mydumper_usage.rst'
22--- docs/mydumper_usage.rst 2015-03-13 15:03:16 +0000
23+++ docs/mydumper_usage.rst 2015-03-18 12:25:28 +0000
24@@ -56,6 +56,11 @@
25
26 The UNIX domain socket file to use for the connection
27
28+.. option:: --init-command
29+
30+ Run the given SQL query after connection was established. May appear more
31+ than once on the command line.
32+
33 .. option:: --database, -B
34
35 Database to dump
36
37=== modified file 'docs/myloader_usage.rst'
38--- docs/myloader_usage.rst 2015-03-13 15:03:16 +0000
39+++ docs/myloader_usage.rst 2015-03-18 12:25:28 +0000
40@@ -49,6 +49,11 @@
41
42 The UNIX domain socket file to use for the connection
43
44+.. option:: --init-command
45+
46+ Run the given SQL query after connection was established. May appear more
47+ than once on the command line.
48+
49 .. option:: --threads, -t
50
51 The number of threads to use for restoring data, default is 4
52
53=== modified file 'mydumper.c'
54--- mydumper.c 2015-03-16 19:04:52 +0000
55+++ mydumper.c 2015-03-18 12:25:28 +0000
56@@ -191,6 +191,7 @@
57 MYSQL *create_main_connection();
58 void *exec_thread(void *data);
59 void write_log_file(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data);
60+void run_init_commands(MYSQL *c);
61
62 void no_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data) {
63 (void) log_domain;
64@@ -409,6 +410,8 @@
65 }
66 mysql_query(thrconn, "/*!40101 SET NAMES binary*/");
67
68+ run_init_commands(thrconn);
69+
70 g_async_queue_push(conf->ready,GINT_TO_POINTER(1));
71
72 struct job* job= NULL;
73@@ -584,6 +587,8 @@
74 }
75 mysql_query(thrconn, "/*!40101 SET NAMES binary*/");
76
77+ run_init_commands(thrconn);
78+
79 g_async_queue_push(conf->ready_less_locking,GINT_TO_POINTER(1));
80
81 struct job* job= NULL;
82@@ -894,6 +899,17 @@
83 exit(errors ? EXIT_FAILURE : EXIT_SUCCESS);
84 }
85
86+void run_init_commands(MYSQL *c) {
87+ int i;
88+ if (init_commands == NULL) {
89+ return;
90+ }
91+
92+ for (i = 0; init_commands[i]; i++) {
93+ mysql_query(c, init_commands[i]);
94+ }
95+}
96+
97 MYSQL *create_main_connection()
98 {
99 MYSQL *conn;
100@@ -914,6 +930,8 @@
101 g_warning("Failed to increase net_write_timeout: %s", mysql_error(conn));
102 }
103
104+ run_init_commands(conn);
105+
106 switch (detected_server) {
107 case SERVER_TYPE_MYSQL:
108 g_message("Connected to a MySQL server");
109@@ -973,6 +991,8 @@
110 exit(EXIT_FAILURE);
111 }
112
113+ run_init_commands(conn);
114+
115 mysql_query(conn,"SHOW MASTER STATUS");
116 master= mysql_store_result(conn);
117 if (master && (row= mysql_fetch_row(master))) {
118
119=== modified file 'myloader.c'
120--- myloader.c 2015-03-16 19:52:34 +0000
121+++ myloader.c 2015-03-18 12:25:28 +0000
122@@ -53,6 +53,7 @@
123 void no_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data);
124 void set_verbose(guint verbosity);
125 void create_database(MYSQL *conn, gchar *database);
126+void run_init_commands(MYSQL *c);
127
128 static GOptionEntry entries[] =
129 {
130@@ -143,6 +144,9 @@
131 mysql_query(conn, "SET SQL_LOG_BIN=0");
132
133 mysql_query(conn, "/*!40014 SET FOREIGN_KEY_CHECKS=0*/");
134+
135+ run_init_commands(conn);
136+
137 conf.queue= g_async_queue_new();
138 conf.ready= g_async_queue_new();
139
140@@ -336,6 +340,17 @@
141 return;
142 }
143
144+void run_init_commands(MYSQL *c) {
145+ int i;
146+ if (init_commands == NULL) {
147+ return;
148+ }
149+
150+ for (i = 0; init_commands[i]; i++) {
151+ mysql_query(c, init_commands[i]);
152+ }
153+}
154+
155 void add_schema(const gchar* filename, MYSQL *conn) {
156 // 0 is database, 1 is table with -schema on the end
157 gchar** split_file= g_strsplit(filename, ".", 0);
158@@ -413,6 +428,8 @@
159 mysql_query(thrconn, "/*!40014 SET UNIQUE_CHECKS=0 */");
160 mysql_query(thrconn, "SET autocommit=0");
161
162+ run_init_commands(thrconn);
163+
164 g_async_queue_push(conf->ready, GINT_TO_POINTER(1));
165
166 struct job* job= NULL;

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: