Merge lp:~max-bubenick/mydumper/rds into lp:mydumper/0.6

Proposed by Max Bubenick
Status: Merged
Merge reported by: Max Bubenick
Merged at revision: not available
Proposed branch: lp:~max-bubenick/mydumper/rds
Merge into: lp:mydumper/0.6
Diff against target: 140 lines (+91/-4)
1 file modified
mydumper.c (+91/-4)
To merge this branch: bzr merge lp:~max-bubenick/mydumper/rds
Reviewer Review Type Date Requested Status
Max Bubenick Approve
Review via email: mp+224694@code.launchpad.net

Description of the change

--lock-all-tables option added, usefull for RDS

To post a comment you must log in.
Revision history for this message
Max Bubenick (max-bubenick) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mydumper.c'
2--- mydumper.c 2014-06-04 18:29:03 +0000
3+++ mydumper.c 2014-06-26 17:29:18 +0000
4@@ -68,6 +68,7 @@
5 int compress_output= 0;
6 int killqueries= 0;
7 int detected_server= 0;
8+int lock_all_tables=0;
9 guint snapshot_interval= 60;
10 gboolean daemon_mode= FALSE;
11
12@@ -98,6 +99,7 @@
13 gint non_innodb_table_counter= 0;
14 gint non_innodb_done= 0;
15 guint less_locking_threads = 0;
16+guint updated_since = 0;
17
18 // For daemon mode, 0 or 1
19 guint dump_number= 0;
20@@ -137,6 +139,8 @@
21 { "skip-tz-utc", 0, 0, G_OPTION_ARG_NONE, &skip_tz, "", NULL },
22 { "use-savepoints", 0, 0, G_OPTION_ARG_NONE, &use_savepoints, "Use savepoints to reduce metadata locking issues, needs SUPER privilege", NULL },
23 { "success-on-1146", 0, 0, G_OPTION_ARG_NONE, &success_on_1146, "Not increment error count and Warning instead of Critical in case of table doesn't exist", NULL},
24+ { "lock-all-tables", 0, 0, G_OPTION_ARG_NONE, &lock_all_tables, "Use LOCK TABLE for all, instead of FTWRL", NULL},
25+ //{ "updated-since", 'U', 0, G_OPTION_ARG_INT, &updated_since, "Use Update_time to dump only tables updated in the last U days", NULL}
26 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
27 };
28
29@@ -772,7 +776,7 @@
30 start_dump(conn);
31 }
32
33- sleep(5);
34+ //sleep(5);
35 mysql_thread_end();
36 mysql_library_end();
37 g_free(output_directory);
38@@ -894,6 +898,7 @@
39 char *p;
40 char *p2;
41 char *p3;
42+
43 guint64 nits[num_threads];
44 GList* nitl[num_threads];
45 int tn = 0;
46@@ -964,9 +969,91 @@
47 }
48
49 if (!no_locks) {
50- if (mysql_query(conn, "FLUSH TABLES WITH READ LOCK")) {
51- g_critical("Couldn't acquire global lock, snapshots will not be consistent: %s",mysql_error(conn));
52- errors++;
53+ if(lock_all_tables){
54+ // LOCK ALL TABLES
55+ GString *query= g_string_sized_new(16777216);
56+ gchar *dbtb = NULL;
57+ GList *tables_lock = NULL;
58+ GList *iter = NULL;
59+ guint success = 0;
60+ guint retry = 0;
61+ guint lock = 1;
62+ int i = 0;
63+
64+ if(db){
65+ g_string_printf(query, "SELECT TABLE_SCHEMA, TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '%s' AND TABLE_TYPE ='BASE TABLE' AND NOT (TABLE_SCHEMA = 'mysql' AND (TABLE_NAME = 'slow_log' OR TABLE_NAME = 'general_log'))", db);
66+ }else{
67+ g_string_printf(query, "SELECT TABLE_SCHEMA, TABLE_NAME FROM information_schema.TABLES WHERE TABLE_TYPE ='BASE TABLE' AND TABLE_SCHEMA NOT IN ('information_schema', 'performance_schema', 'data_dictionary') AND NOT (TABLE_SCHEMA = 'mysql' AND (TABLE_NAME = 'slow_log' OR TABLE_NAME = 'general_log'))");
68+ }
69+ if(mysql_query(conn, query->str)){
70+ g_critical("Couldn't get table list for lock all tables: %s",mysql_error(conn));
71+ errors++;
72+ }else{
73+ MYSQL_RES *res = mysql_store_result(conn);
74+ MYSQL_ROW row;
75+
76+ while ((row=mysql_fetch_row(res))) {
77+ lock = 1;
78+ if (tables) {
79+ int table_found=0;
80+ for (i = 0; tables[i] != NULL; i++)
81+ if (g_ascii_strcasecmp(tables[i], row[1]) == 0)
82+ table_found = 1;
83+ if (!table_found)
84+ lock = 0;
85+ }
86+ if (lock && regexstring && !check_regex(row[0],row[1]))
87+ continue;
88+
89+ if(lock) {
90+ dbtb = g_strdup_printf("`%s`.`%s`",row[0],row[1]);
91+ tables_lock = g_list_append(tables_lock,dbtb);
92+ }
93+ }
94+ // Try three times to get the lock, this is in case of tmp tables disappearing
95+ while(!success && retry < 4){
96+ n = 0;
97+ iter = tables_lock;
98+ for (iter= g_list_first(iter); iter; iter= g_list_next(iter)) {
99+ if(n == 0){
100+ g_string_printf(query, "LOCK TABLE %s READ", (char *) iter->data);
101+ n = 1;
102+ }else{
103+ g_string_append_printf(query, ", %s READ",(char *) iter->data);
104+ }
105+ }
106+ if(mysql_query(conn,query->str)){
107+ gchar *failed_table = NULL;
108+ gchar **tmp_fail;
109+
110+ tmp_fail = g_strsplit(mysql_error(conn), "'",0);
111+ tmp_fail = g_strsplit(tmp_fail[1], ".", 0);
112+ failed_table = g_strdup_printf("`%s`.`%s`", tmp_fail[0], tmp_fail[1]);
113+ iter = tables_lock;
114+ for (iter= g_list_first(iter); iter; iter= g_list_next(iter)) {
115+ if(strcmp (iter->data, failed_table) == 0){
116+ tables_lock = g_list_remove(tables_lock, iter->data);
117+ }
118+ }
119+ g_free(tmp_fail);
120+ g_free(failed_table);
121+ }else{
122+ success = 1;
123+ }
124+ retry += 1;
125+ }
126+ if(!success){
127+ g_critical("Lock all tables fail: %s", mysql_error(conn));
128+ exit(EXIT_FAILURE);
129+ }
130+ }
131+ g_free(query->str);
132+ g_list_free(tables_lock);
133+ }else{
134+ if(mysql_query(conn, "FLUSH TABLES WITH READ LOCK")) {
135+ g_critical("Couldn't acquire global lock, snapshots will not be consistent: %s",mysql_error(conn));
136+ errors++;
137+ }
138 }
139 } else {
140 g_warning("Executing in no-locks mode, snapshot will notbe consistent");

Subscribers

People subscribed via source and target branches