1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

MDEV-18465 Logging of DDL statements during backup

Many of the changes was needed to be able to collect and print engine
name and table version id's in the ddl log.
This commit is contained in:
Monty
2021-03-30 17:06:55 +03:00
committed by Sergei Golubchik
parent 496a14e187
commit 83e529eced
46 changed files with 1841 additions and 145 deletions

View File

@ -5034,6 +5034,20 @@ bool select_create::send_eof()
mysql_mutex_unlock(&thd->LOCK_thd_data);
}
#endif /* WITH_WSREP */
/* Log query to ddl log */
backup_log_info ddl_log;
bzero(&ddl_log, sizeof(ddl_log));
ddl_log.query= { C_STRING_WITH_LEN("CREATE") };
if ((ddl_log.org_partitioned= (create_info->db_type == partition_hton)))
ddl_log.org_storage_engine_name= create_info->new_storage_engine_name;
else
lex_string_set(&ddl_log.org_storage_engine_name,
ha_resolve_storage_engine_name(create_info->db_type));
ddl_log.org_database= create_table->db;
ddl_log.org_table= create_table->table_name;
ddl_log.org_table_id= create_info->tabledef_version;
backup_log_ddl(&ddl_log);
}
/*
If are using statement based replication the table will be deleted here
@ -5154,21 +5168,39 @@ void select_create::abort_result_set()
drop_open_table(thd, table, &create_table->db, &create_table->table_name);
table=0; // Safety
if (thd->log_current_statement && mysql_bin_log.is_open())
if (thd->log_current_statement)
{
/* Remove logging of drop, create + insert rows */
binlog_reset_cache(thd);
/* Original table was deleted. We have to log it */
if (table_creation_was_logged)
if (mysql_bin_log.is_open())
{
thd->binlog_xid= thd->query_id;
ddl_log_update_xid(&ddl_log_state_create, thd->binlog_xid);
ddl_log_update_xid(&ddl_log_state_rm, thd->binlog_xid);
debug_crash_here("ddl_log_create_before_binlog");
log_drop_table(thd, &create_table->db, &create_table->table_name,
tmp_table);
debug_crash_here("ddl_log_create_after_binlog");
thd->binlog_xid= 0;
/* Remove logging of drop, create + insert rows */
binlog_reset_cache(thd);
/* Original table was deleted. We have to log it */
if (table_creation_was_logged)
{
thd->binlog_xid= thd->query_id;
ddl_log_update_xid(&ddl_log_state_create, thd->binlog_xid);
ddl_log_update_xid(&ddl_log_state_rm, thd->binlog_xid);
debug_crash_here("ddl_log_create_before_binlog");
log_drop_table(thd, &create_table->db, &create_table->table_name,
&create_info->org_storage_engine_name,
create_info->db_type == partition_hton,
&create_info->tabledef_version,
tmp_table);
debug_crash_here("ddl_log_create_after_binlog");
thd->binlog_xid= 0;
}
}
else if (!tmp_table)
{
backup_log_info ddl_log;
bzero(&ddl_log, sizeof(ddl_log));
ddl_log.query= { C_STRING_WITH_LEN("DROP_AFTER_CREATE") };
ddl_log.org_partitioned= (create_info->db_type == partition_hton);
ddl_log.org_storage_engine_name= create_info->org_storage_engine_name;
ddl_log.org_database= create_table->db;
ddl_log.org_table= create_table->table_name;
ddl_log.org_table_id= create_info->tabledef_version;
backup_log_ddl(&ddl_log);
}
}
}