Merge lp:~max-bubenick/mydumper/updated-since into lp:mydumper/0.6

Proposed by Max Bubenick
Status: Merged
Merged at revision: 152
Proposed branch: lp:~max-bubenick/mydumper/updated-since
Merge into: lp:mydumper/0.6
Diff against target: 146 lines (+52/-5)
1 file modified
mydumper.c (+52/-5)
To merge this branch: bzr merge lp:~max-bubenick/mydumper/updated-since
Reviewer Review Type Date Requested Status
Percona RDBA Pending
Review via email: mp+228167@code.launchpad.net
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
=== modified file 'mydumper.c'
--- mydumper.c 2014-07-23 17:25:44 +0000
+++ mydumper.c 2014-07-24 16:52:44 +0000
@@ -77,6 +77,7 @@
7777
78gchar *tables_list= NULL;78gchar *tables_list= NULL;
79char **tables= NULL;79char **tables= NULL;
80GList *no_updated_tables=NULL;
8081
81#ifdef WITH_BINLOG82#ifdef WITH_BINLOG
82gboolean need_binlogs= FALSE;83gboolean need_binlogs= FALSE;
@@ -140,7 +141,7 @@
140 { "use-savepoints", 0, 0, G_OPTION_ARG_NONE, &use_savepoints, "Use savepoints to reduce metadata locking issues, needs SUPER privilege", NULL },141 { "use-savepoints", 0, 0, G_OPTION_ARG_NONE, &use_savepoints, "Use savepoints to reduce metadata locking issues, needs SUPER privilege", 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 { "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 { "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}144 { "updated-since", 'U', 0, G_OPTION_ARG_INT, &updated_since, "Use Update_time to dump only tables updated in the last U days", NULL},
144 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }145 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
145};146};
146147
@@ -151,8 +152,9 @@
151void dump_table(MYSQL *conn, char *database, char *table, struct configuration *conf, gboolean is_innodb);152void dump_table(MYSQL *conn, char *database, char *table, struct configuration *conf, gboolean is_innodb);
152void dump_tables(MYSQL *, GList *, struct configuration *);153void dump_tables(MYSQL *, GList *, struct configuration *);
153guint64 dump_table_data(MYSQL *, FILE *, char *, char *, char *, char *);154guint64 dump_table_data(MYSQL *, FILE *, char *, char *, char *, char *);
154void dump_database(MYSQL *, char *);155void dump_database(MYSQL *, char *, FILE *);
155void get_tables(MYSQL * conn);156void get_tables(MYSQL * conn);
157void get_not_updated(MYSQL *conn);
156GList * get_chunks_for_table(MYSQL *, char *, char*, struct configuration *conf);158GList * get_chunks_for_table(MYSQL *, char *, char*, struct configuration *conf);
157guint64 estimate_count(MYSQL *conn, char *database, char *table, char *field, char *from, char *to);159guint64 estimate_count(MYSQL *conn, char *database, char *table, char *field, char *from, char *to);
158void dump_table_data_file(MYSQL *conn, char *database, char *table, char *where, char *filename);160void dump_table_data_file(MYSQL *conn, char *database, char *table, char *where, char *filename);
@@ -899,6 +901,7 @@
899 char *p;901 char *p;
900 char *p2;902 char *p2;
901 char *p3;903 char *p3;
904 char *u;
902 905
903 guint64 nits[num_threads];906 guint64 nits[num_threads];
904 GList* nitl[num_threads];907 GList* nitl[num_threads];
@@ -907,6 +910,7 @@
907 time_t t;910 time_t t;
908 struct db_table *dbt;911 struct db_table *dbt;
909 guint n;912 guint n;
913 FILE* nufile = NULL;
910 914
911 for(n=0;n<num_threads;n++){915 for(n=0;n<num_threads;n++){
912 nits[n] = 0;916 nits[n] = 0;
@@ -924,6 +928,19 @@
924 g_critical("Couldn't write metadata file (%d)",errno);928 g_critical("Couldn't write metadata file (%d)",errno);
925 exit(EXIT_FAILURE);929 exit(EXIT_FAILURE);
926 }930 }
931
932 if(updated_since > 0){
933 if (daemon_mode)
934 u= g_strdup_printf("%s/%d/not_updated_tables", output_directory, dump_number);
935 else
936 u= g_strdup_printf("%s/not_updated_tables", output_directory);
937 nufile=g_fopen(u,"w");
938 if(!nufile) {
939 g_critical("Couldn't write not_updated_tables file (%d)",errno);
940 exit(EXIT_FAILURE);
941 }
942 get_not_updated(conn);
943 }
927944
928 /* We check SHOW PROCESSLIST, and if there're queries945 /* We check SHOW PROCESSLIST, and if there're queries
929 larger than preset value, we terminate the process.946 larger than preset value, we terminate the process.
@@ -1143,7 +1160,7 @@
1143 g_async_queue_unref(conf.ready);1160 g_async_queue_unref(conf.ready);
1144 1161
1145 if (db) {1162 if (db) {
1146 dump_database(conn, db);1163 dump_database(conn, db, nufile);
1147 } else if (tables) {1164 } else if (tables) {
1148 get_tables(conn);1165 get_tables(conn);
1149 } else {1166 } else {
@@ -1157,7 +1174,7 @@
1157 while ((row=mysql_fetch_row(databases))) {1174 while ((row=mysql_fetch_row(databases))) {
1158 if (!strcasecmp(row[0],"information_schema") || !strcasecmp(row[0], "performance_schema") || (!strcasecmp(row[0], "data_dictionary")))1175 if (!strcasecmp(row[0],"information_schema") || !strcasecmp(row[0], "performance_schema") || (!strcasecmp(row[0], "data_dictionary")))
1159 continue;1176 continue;
1160 dump_database(conn, row[0]);1177 dump_database(conn, row[0], nufile);
1161 }1178 }
1162 mysql_free_result(databases);1179 mysql_free_result(databases);
11631180
@@ -1273,6 +1290,19 @@
1273 g_free(threads);1290 g_free(threads);
1274}1291}
12751292
1293void get_not_updated(MYSQL *conn){
1294 MYSQL_RES *res=NULL;
1295 MYSQL_ROW row;
1296
1297 gchar *query = g_strdup_printf("SELECT CONCAT(TABLE_SCHEMA,'.',TABLE_NAME) FROM information_schema.TABLES WHERE UPDATE_TIME < NOW() - INTERVAL %d DAY",updated_since);
1298 mysql_query(conn,query);
1299 g_free(query);
1300
1301 res = mysql_store_result(conn);
1302 while((row = mysql_fetch_row(res)))
1303 no_updated_tables = g_list_append(no_updated_tables, row[0]);
1304}
1305
1276/* Heuristic chunks building - based on estimates, produces list of ranges for datadumping1306/* Heuristic chunks building - based on estimates, produces list of ranges for datadumping
1277 WORK IN PROGRESS1307 WORK IN PROGRESS
1278*/1308*/
@@ -1467,8 +1497,9 @@
1467 }1497 }
1468}1498}
14691499
1470void dump_database(MYSQL * conn, char *database) {1500void dump_database(MYSQL * conn, char *database, FILE *file) {
14711501
1502 GList *iter = NULL;
1472 char *query;1503 char *query;
1473 mysql_select_db(conn,database);1504 mysql_select_db(conn,database);
1474 if (detected_server == SERVER_TYPE_MYSQL)1505 if (detected_server == SERVER_TYPE_MYSQL)
@@ -1547,6 +1578,20 @@
1547 if (regexstring && !check_regex(database,row[0]))1578 if (regexstring && !check_regex(database,row[0]))
1548 continue;1579 continue;
15491580
1581 /* Check if the table was recently updated */
1582 if(no_updated_tables){
1583 iter = no_updated_tables;
1584 for (iter= g_list_first(iter); iter; iter= g_list_next(iter)) {
1585 if(g_ascii_strcasecmp (iter->data, g_strdup_printf("%s.%s", database, row[0])) == 0){
1586 g_message("NO UPDATED TABLE: %s.%s", database, row[0]);
1587 fprintf(file, "%s.%s\n", database, row[0]);
1588 dump=0;
1589 }
1590 }
1591 }
1592 if (!dump)
1593 continue;
1594
1550 /* Green light! */1595 /* Green light! */
1551 struct db_table *dbt = g_new(struct db_table, 1);1596 struct db_table *dbt = g_new(struct db_table, 1);
1552 dbt->database= g_strdup(database);1597 dbt->database= g_strdup(database);
@@ -1564,6 +1609,8 @@
1564 }1609 }
1565 }1610 }
1566 mysql_free_result(result);1611 mysql_free_result(result);
1612 if(file)
1613 fflush(file);
1567}1614}
15681615
1569void get_tables(MYSQL * conn) {1616void get_tables(MYSQL * conn) {

Subscribers

People subscribed via source and target branches