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
=== modified file 'mydumper.c'
--- mydumper.c 2014-06-04 18:29:03 +0000
+++ mydumper.c 2014-06-26 17:29:18 +0000
@@ -68,6 +68,7 @@
68int compress_output= 0;68int compress_output= 0;
69int killqueries= 0;69int killqueries= 0;
70int detected_server= 0;70int detected_server= 0;
71int lock_all_tables=0;
71guint snapshot_interval= 60;72guint snapshot_interval= 60;
72gboolean daemon_mode= FALSE;73gboolean daemon_mode= FALSE;
7374
@@ -98,6 +99,7 @@
98gint non_innodb_table_counter= 0;99gint non_innodb_table_counter= 0;
99gint non_innodb_done= 0;100gint non_innodb_done= 0;
100guint less_locking_threads = 0;101guint less_locking_threads = 0;
102guint updated_since = 0;
101103
102// For daemon mode, 0 or 1104// For daemon mode, 0 or 1
103guint dump_number= 0;105guint dump_number= 0;
@@ -137,6 +139,8 @@
137 { "skip-tz-utc", 0, 0, G_OPTION_ARG_NONE, &skip_tz, "", NULL },139 { "skip-tz-utc", 0, 0, G_OPTION_ARG_NONE, &skip_tz, "", NULL },
138 { "use-savepoints", 0, 0, G_OPTION_ARG_NONE, &use_savepoints, "Use savepoints to reduce metadata locking issues, needs SUPER privilege", NULL },140 { "use-savepoints", 0, 0, G_OPTION_ARG_NONE, &use_savepoints, "Use savepoints to reduce metadata locking issues, needs SUPER privilege", NULL },
139 { "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},141 { "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},
142 { "lock-all-tables", 0, 0, G_OPTION_ARG_NONE, &lock_all_tables, "Use LOCK TABLE for all, instead of FTWRL", NULL},
143 //{ "updated-since", 'U', 0, G_OPTION_ARG_INT, &updated_since, "Use Update_time to dump only tables updated in the last U days", NULL}
140 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }144 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
141};145};
142146
@@ -772,7 +776,7 @@
772 start_dump(conn);776 start_dump(conn);
773 }777 }
774778
775 sleep(5);779 //sleep(5);
776 mysql_thread_end();780 mysql_thread_end();
777 mysql_library_end();781 mysql_library_end();
778 g_free(output_directory);782 g_free(output_directory);
@@ -894,6 +898,7 @@
894 char *p;898 char *p;
895 char *p2;899 char *p2;
896 char *p3;900 char *p3;
901
897 guint64 nits[num_threads];902 guint64 nits[num_threads];
898 GList* nitl[num_threads];903 GList* nitl[num_threads];
899 int tn = 0;904 int tn = 0;
@@ -964,9 +969,91 @@
964 }969 }
965970
966 if (!no_locks) {971 if (!no_locks) {
967 if (mysql_query(conn, "FLUSH TABLES WITH READ LOCK")) {972 if(lock_all_tables){
968 g_critical("Couldn't acquire global lock, snapshots will not be consistent: %s",mysql_error(conn));973 // LOCK ALL TABLES
969 errors++;974 GString *query= g_string_sized_new(16777216);
975 gchar *dbtb = NULL;
976 GList *tables_lock = NULL;
977 GList *iter = NULL;
978 guint success = 0;
979 guint retry = 0;
980 guint lock = 1;
981 int i = 0;
982
983 if(db){
984 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);
985 }else{
986 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'))");
987 }
988 if(mysql_query(conn, query->str)){
989 g_critical("Couldn't get table list for lock all tables: %s",mysql_error(conn));
990 errors++;
991 }else{
992 MYSQL_RES *res = mysql_store_result(conn);
993 MYSQL_ROW row;
994
995 while ((row=mysql_fetch_row(res))) {
996 lock = 1;
997 if (tables) {
998 int table_found=0;
999 for (i = 0; tables[i] != NULL; i++)
1000 if (g_ascii_strcasecmp(tables[i], row[1]) == 0)
1001 table_found = 1;
1002 if (!table_found)
1003 lock = 0;
1004 }
1005 if (lock && regexstring && !check_regex(row[0],row[1]))
1006 continue;
1007
1008 if(lock) {
1009 dbtb = g_strdup_printf("`%s`.`%s`",row[0],row[1]);
1010 tables_lock = g_list_append(tables_lock,dbtb);
1011 }
1012 }
1013 // Try three times to get the lock, this is in case of tmp tables disappearing
1014 while(!success && retry < 4){
1015 n = 0;
1016 iter = tables_lock;
1017 for (iter= g_list_first(iter); iter; iter= g_list_next(iter)) {
1018 if(n == 0){
1019 g_string_printf(query, "LOCK TABLE %s READ", (char *) iter->data);
1020 n = 1;
1021 }else{
1022 g_string_append_printf(query, ", %s READ",(char *) iter->data);
1023 }
1024 }
1025 if(mysql_query(conn,query->str)){
1026 gchar *failed_table = NULL;
1027 gchar **tmp_fail;
1028
1029 tmp_fail = g_strsplit(mysql_error(conn), "'",0);
1030 tmp_fail = g_strsplit(tmp_fail[1], ".", 0);
1031 failed_table = g_strdup_printf("`%s`.`%s`", tmp_fail[0], tmp_fail[1]);
1032 iter = tables_lock;
1033 for (iter= g_list_first(iter); iter; iter= g_list_next(iter)) {
1034 if(strcmp (iter->data, failed_table) == 0){
1035 tables_lock = g_list_remove(tables_lock, iter->data);
1036 }
1037 }
1038 g_free(tmp_fail);
1039 g_free(failed_table);
1040 }else{
1041 success = 1;
1042 }
1043 retry += 1;
1044 }
1045 if(!success){
1046 g_critical("Lock all tables fail: %s", mysql_error(conn));
1047 exit(EXIT_FAILURE);
1048 }
1049 }
1050 g_free(query->str);
1051 g_list_free(tables_lock);
1052 }else{
1053 if(mysql_query(conn, "FLUSH TABLES WITH READ LOCK")) {
1054 g_critical("Couldn't acquire global lock, snapshots will not be consistent: %s",mysql_error(conn));
1055 errors++;
1056 }
970 }1057 }
971 } else {1058 } else {
972 g_warning("Executing in no-locks mode, snapshot will notbe consistent");1059 g_warning("Executing in no-locks mode, snapshot will notbe consistent");

Subscribers

People subscribed via source and target branches