Skip to content

Commit

Permalink
Merge pull request #697 from mydumper/fix_615
Browse files Browse the repository at this point in the history
Adding AFTER_IMPORT_PER_TABLE and AFTER_IMPORT_ALL_TABLES and finxing…
  • Loading branch information
davidducos committed May 20, 2022
2 parents 9278345 + 846e611 commit afd34b0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
22 changes: 21 additions & 1 deletion src/myloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ gchar *directory = NULL;
gchar *pwd=NULL;
gboolean overwrite_tables = FALSE;
gboolean innodb_optimize_keys = FALSE;
gboolean innodb_optimize_keys_per_table = FALSE;
gboolean innodb_optimize_keys_all_tables = FALSE;
gboolean enable_binlog = FALSE;
gboolean disable_redo_log = FALSE;
gboolean skip_triggers = FALSE;
Expand All @@ -88,6 +90,24 @@ const char DIRECTORY[] = "import";
gchar *pmm_resolution = NULL;
gchar *pmm_path = NULL;
gboolean pmm = FALSE;
gboolean arguments_callback(const gchar *option_name,const gchar *value, gpointer data, GError **error){
*error=NULL;
(void) data;
if (g_strstr_len(option_name,22,"--innodb-optimize-keys")){
innodb_optimize_keys = TRUE;
if (g_strstr_len(value,22,"AFTER_IMPORT_PER_TABLE")){
innodb_optimize_keys_per_table = TRUE;
innodb_optimize_keys_all_tables = FALSE;
return TRUE;
}
if (g_strstr_len(value,23,"AFTER_IMPORT_ALL_TABLES")){
innodb_optimize_keys_all_tables = TRUE;
innodb_optimize_keys_per_table = FALSE;
return TRUE;
}
}
return FALSE;
}

static GOptionEntry entries[] = {
{"directory", 'd', 0, G_OPTION_ARG_STRING, &input_directory,
Expand All @@ -102,7 +122,7 @@ static GOptionEntry entries[] = {
"Database to restore", NULL},
{"enable-binlog", 'e', 0, G_OPTION_ARG_NONE, &enable_binlog,
"Enable binary logging of the restore data", NULL},
{"innodb-optimize-keys", 0, 0, G_OPTION_ARG_NONE, &innodb_optimize_keys,
{"innodb-optimize-keys", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK , &arguments_callback,
"Creates the table without the indexes and it adds them at the end", NULL},
{ "set-names",0, 0, G_OPTION_ARG_STRING, &set_names_str,
"Sets the names, use it at your own risk, default binary", NULL },
Expand Down
17 changes: 13 additions & 4 deletions src/myloader_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

extern guint num_threads;
extern gboolean innodb_optimize_keys;
extern gboolean innodb_optimize_keys_per_table;
extern gboolean innodb_optimize_keys_all_tables;
extern gchar *directory;
extern guint errors;
extern gboolean skip_post;
Expand Down Expand Up @@ -305,11 +307,18 @@ void *process_directory_queue(struct thread_data * td) {
dbt->current_threads--;
dbt->start_index_time=g_date_time_new_now_local();
g_mutex_unlock(dbt->mutex);
if (dbt->indexes != NULL) {
g_message("Thread %d restoring indexes `%s`.`%s`", td->thread_id,
if (dbt->indexes != NULL){
if (innodb_optimize_keys_per_table ) {
g_message("Thread %d restoring indexes `%s`.`%s`", td->thread_id,
dbt->real_database, dbt->real_table);
guint query_counter=0;
restore_data_in_gstring(td, dbt->indexes, FALSE, &query_counter);
guint query_counter=0;
restore_data_in_gstring(td, dbt->indexes, FALSE, &query_counter);
}else if (innodb_optimize_keys_all_tables ){
struct restore_job *rj = new_schema_restore_job(strdup("index"),JOB_RESTORE_STRING, dbt, dbt->real_database,dbt->indexes,"indexes");
g_async_queue_push(td->conf->post_table_queue, new_job(JOB_RESTORE,rj,dbt->real_database));
}else{
g_critical("This should not happen, wrong config on --innodb-optimize-keys");
}
}
dbt->finish_time=g_date_time_new_now_local();
}else{
Expand Down
5 changes: 3 additions & 2 deletions src/myloader_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ void free_dbt(struct db_table * dbt){
g_free(dbt->database);
g_free(dbt->real_database);
g_free(dbt->table);
if (dbt->constraints!=NULL) g_string_free(dbt->constraints,TRUE);
// if (dbt->constraints!=NULL) g_string_free(dbt->constraints,TRUE);
dbt->constraints = NULL; // It should be free after constraint is executed
g_async_queue_unref(dbt->queue);
g_mutex_clear(dbt->mutex);
}
Expand Down Expand Up @@ -183,7 +184,7 @@ void load_schema(struct db_table *dbt, gchar *filename){
g_async_queue_push(conf->post_table_queue, new_job(JOB_RESTORE,rj,dbt->real_database));
}
if (flag & INCLUDE_CONSTRAINT){
struct restore_job *rj = new_schema_restore_job(filename,JOB_RESTORE_STRING,dbt, dbt->real_database, alter_table_constraint_statement, "constraint");
struct restore_job *rj = new_schema_restore_job(strdup(filename),JOB_RESTORE_STRING,dbt, dbt->real_database, alter_table_constraint_statement, "constraint");
g_async_queue_push(conf->post_table_queue, new_job(JOB_RESTORE,rj,dbt->real_database));
dbt->constraints=alter_table_constraint_statement;
}else{
Expand Down

0 comments on commit afd34b0

Please sign in to comment.