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
1=== modified file 'mydumper.c'
2--- mydumper.c 2014-07-23 17:25:44 +0000
3+++ mydumper.c 2014-07-24 16:52:44 +0000
4@@ -77,6 +77,7 @@
5
6 gchar *tables_list= NULL;
7 char **tables= NULL;
8+GList *no_updated_tables=NULL;
9
10 #ifdef WITH_BINLOG
11 gboolean need_binlogs= FALSE;
12@@ -140,7 +141,7 @@
13 { "use-savepoints", 0, 0, G_OPTION_ARG_NONE, &use_savepoints, "Use savepoints to reduce metadata locking issues, needs SUPER privilege", NULL },
14 { "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},
15 { "lock-all-tables", 0, 0, G_OPTION_ARG_NONE, &lock_all_tables, "Use LOCK TABLE for all, instead of FTWRL", NULL},
16- //{ "updated-since", 'U', 0, G_OPTION_ARG_INT, &updated_since, "Use Update_time to dump only tables updated in the last U days", NULL}
17+ { "updated-since", 'U', 0, G_OPTION_ARG_INT, &updated_since, "Use Update_time to dump only tables updated in the last U days", NULL},
18 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
19 };
20
21@@ -151,8 +152,9 @@
22 void dump_table(MYSQL *conn, char *database, char *table, struct configuration *conf, gboolean is_innodb);
23 void dump_tables(MYSQL *, GList *, struct configuration *);
24 guint64 dump_table_data(MYSQL *, FILE *, char *, char *, char *, char *);
25-void dump_database(MYSQL *, char *);
26+void dump_database(MYSQL *, char *, FILE *);
27 void get_tables(MYSQL * conn);
28+void get_not_updated(MYSQL *conn);
29 GList * get_chunks_for_table(MYSQL *, char *, char*, struct configuration *conf);
30 guint64 estimate_count(MYSQL *conn, char *database, char *table, char *field, char *from, char *to);
31 void dump_table_data_file(MYSQL *conn, char *database, char *table, char *where, char *filename);
32@@ -899,6 +901,7 @@
33 char *p;
34 char *p2;
35 char *p3;
36+ char *u;
37
38 guint64 nits[num_threads];
39 GList* nitl[num_threads];
40@@ -907,6 +910,7 @@
41 time_t t;
42 struct db_table *dbt;
43 guint n;
44+ FILE* nufile = NULL;
45
46 for(n=0;n<num_threads;n++){
47 nits[n] = 0;
48@@ -924,6 +928,19 @@
49 g_critical("Couldn't write metadata file (%d)",errno);
50 exit(EXIT_FAILURE);
51 }
52+
53+ if(updated_since > 0){
54+ if (daemon_mode)
55+ u= g_strdup_printf("%s/%d/not_updated_tables", output_directory, dump_number);
56+ else
57+ u= g_strdup_printf("%s/not_updated_tables", output_directory);
58+ nufile=g_fopen(u,"w");
59+ if(!nufile) {
60+ g_critical("Couldn't write not_updated_tables file (%d)",errno);
61+ exit(EXIT_FAILURE);
62+ }
63+ get_not_updated(conn);
64+ }
65
66 /* We check SHOW PROCESSLIST, and if there're queries
67 larger than preset value, we terminate the process.
68@@ -1143,7 +1160,7 @@
69 g_async_queue_unref(conf.ready);
70
71 if (db) {
72- dump_database(conn, db);
73+ dump_database(conn, db, nufile);
74 } else if (tables) {
75 get_tables(conn);
76 } else {
77@@ -1157,7 +1174,7 @@
78 while ((row=mysql_fetch_row(databases))) {
79 if (!strcasecmp(row[0],"information_schema") || !strcasecmp(row[0], "performance_schema") || (!strcasecmp(row[0], "data_dictionary")))
80 continue;
81- dump_database(conn, row[0]);
82+ dump_database(conn, row[0], nufile);
83 }
84 mysql_free_result(databases);
85
86@@ -1273,6 +1290,19 @@
87 g_free(threads);
88 }
89
90+void get_not_updated(MYSQL *conn){
91+ MYSQL_RES *res=NULL;
92+ MYSQL_ROW row;
93+
94+ gchar *query = g_strdup_printf("SELECT CONCAT(TABLE_SCHEMA,'.',TABLE_NAME) FROM information_schema.TABLES WHERE UPDATE_TIME < NOW() - INTERVAL %d DAY",updated_since);
95+ mysql_query(conn,query);
96+ g_free(query);
97+
98+ res = mysql_store_result(conn);
99+ while((row = mysql_fetch_row(res)))
100+ no_updated_tables = g_list_append(no_updated_tables, row[0]);
101+}
102+
103 /* Heuristic chunks building - based on estimates, produces list of ranges for datadumping
104 WORK IN PROGRESS
105 */
106@@ -1467,8 +1497,9 @@
107 }
108 }
109
110-void dump_database(MYSQL * conn, char *database) {
111+void dump_database(MYSQL * conn, char *database, FILE *file) {
112
113+ GList *iter = NULL;
114 char *query;
115 mysql_select_db(conn,database);
116 if (detected_server == SERVER_TYPE_MYSQL)
117@@ -1547,6 +1578,20 @@
118 if (regexstring && !check_regex(database,row[0]))
119 continue;
120
121+ /* Check if the table was recently updated */
122+ if(no_updated_tables){
123+ iter = no_updated_tables;
124+ for (iter= g_list_first(iter); iter; iter= g_list_next(iter)) {
125+ if(g_ascii_strcasecmp (iter->data, g_strdup_printf("%s.%s", database, row[0])) == 0){
126+ g_message("NO UPDATED TABLE: %s.%s", database, row[0]);
127+ fprintf(file, "%s.%s\n", database, row[0]);
128+ dump=0;
129+ }
130+ }
131+ }
132+ if (!dump)
133+ continue;
134+
135 /* Green light! */
136 struct db_table *dbt = g_new(struct db_table, 1);
137 dbt->database= g_strdup(database);
138@@ -1564,6 +1609,8 @@
139 }
140 }
141 mysql_free_result(result);
142+ if(file)
143+ fflush(file);
144 }
145
146 void get_tables(MYSQL * conn) {

Subscribers

People subscribed via source and target branches