Commit 4652c6b0 authored by unknown's avatar unknown

updated patch for BUG#4680 (incomplete DROP DATABASE breaking replication).

We binlog the DROP TABLE for each table that was actually dropped. Per Sergei's 
suggestion a fixed buffer for the DROP TABLE query is pre-allocated from THD pool, and 
logging now is done in batches - new batch is started if the buffer becomes full.
Reduced memory usage by reusing the table list instead of accumulating a list of 
dropped table names. Also fixed the problem if the table was not actually dropped, eg
due to permissions. Extended the test case to make sure batched query 
logging does work.  


mysql-test/r/rpl_drop_db.result:
  test for query buffer overrun
mysql-test/t/rpl_drop_db.test:
  test for query buffer overrun
sql/mysql_priv.h:
  updated patch for BUG#4680 (incomplete DROP DATABASE breaking replication)
BitKeeper/etc/ignore:
  Added support-files/MacOSX/postflight support-files/MacOSX/preflight to the ignore list
sql/sql_db.cc:
  updated patch for BUG#4680 (incomplete DROP DATABASE breaking replication)
sql/sql_table.cc:
  updated patch for BUG#4680 (incomplete DROP DATABASE breaking replication)
sql/table.h:
  updated patch for BUG#4680 (incomplete DROP DATABASE breaking replication)
parent 6345af6d
......@@ -1054,3 +1054,5 @@ vio/test-sslclient
vio/test-sslserver
vio/viotest-ssl
ndb/tools/ndb_config
support-files/MacOSX/postflight
support-files/MacOSX/preflight
This diff is collapsed.
......@@ -17,6 +17,19 @@ create table d1.t3 (n int);
drop database d1;
use d1;
show tables;
# test the branch of the code that deals with the query buffer overflow
let $1=1000;
while ($1)
{
eval create table d1.t$1(n int);
dec $1;
}
--error 1010
drop database d1;
use d1;
show tables;
use test;
create table t1 (n int);
insert into t1 values (1234);
......
......@@ -447,7 +447,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
bool drop_temporary, bool log_query);
int mysql_rm_table_part2_with_lock(THD *thd, TABLE_LIST *tables,
bool if_exists, bool drop_temporary,
bool log_query, List<String> *dropped_tables);
bool log_query);
int quick_rm_table(enum db_type base,const char *db,
const char *table_name);
bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list);
......
......@@ -25,13 +25,19 @@
#include <direct.h>
#endif
#define MAX_DROP_TABLE_Q_LEN 1024
const char *del_exts[]= {".frm", ".BAK", ".TMD",".opt", NullS};
static TYPELIB deletable_extentions=
{array_elements(del_exts)-1,"del_exts", del_exts, NULL};
static long mysql_rm_known_files(THD *thd, MY_DIR *dirp,
const char *db, const char *path,
uint level, List<String> *dropped_tables);
const char *db, const char *path, uint level,
TABLE_LIST** dropped_tables);
static inline void write_to_binlog(THD* thd, char* query, uint q_len,
char* db, uint db_len);
/* Database options hash */
static HASH dboptions;
......@@ -57,6 +63,19 @@ static byte* dboptions_get_key(my_dbopt_t *opt, uint *length,
return (byte*) opt->name;
}
/*
Helper function to write a query to binlog used by mysql_rm_db()
*/
static inline void write_to_binlog(THD* thd, char* query, uint q_len,
char* db, uint db_len)
{
Query_log_event qinfo(thd, query, q_len, 0, 0);
qinfo.error_code= 0;
qinfo.db= db;
qinfo.db_len= db_len;
mysql_bin_log.write(&qinfo);
}
/*
Function to free dboptions hash element
......@@ -584,8 +603,8 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
int error= 0;
char path[FN_REFLEN+16], tmp_db[NAME_LEN+1];
MY_DIR *dirp;
List<String> dropped_tables;
uint length;
TABLE_LIST* dropped_tables= 0;
DBUG_ENTER("mysql_rm_db");
VOID(pthread_mutex_lock(&LOCK_mysql_create_db));
......@@ -675,36 +694,44 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
send_ok(thd, (ulong) deleted);
thd->server_status&= ~SERVER_STATUS_DB_DROPPED;
}
else if (!dropped_tables.is_empty() && mysql_bin_log.is_open())
{
List_iterator<String> it(dropped_tables);
String* dropped_table;
int q_len= 11; /* drop table */
int db_len= strlen(db);
for (;(dropped_table= it++);)
else if (mysql_bin_log.is_open())
{
q_len += dropped_table->length() + 2 + db_len;
}
q_len--; /* no last comma */
char* query= thd->alloc(MAX_DROP_TABLE_Q_LEN);
char* query= thd->alloc(q_len);
if (!query)
goto exit; /* not much else we can do */
char* p= strmov(query,"drop table ");
it.rewind();
char* p_end= query + MAX_DROP_TABLE_Q_LEN;
TABLE_LIST* tbl;
bool last_query_needs_write= 0;
uint db_len= strlen(db);
for (tbl= dropped_tables;tbl;tbl= tbl->next)
{
if (!tbl->was_dropped)
continue;
for (;(dropped_table= it++);)
/* 3 for the quotes and the comma*/
uint tbl_name_len= strlen(tbl->real_name) + 3;
if (p + tbl_name_len + 1 >= p_end)
{
p= strmov(p,db);
*p++ = '.';
p= strnmov(p,dropped_table->ptr(),dropped_table->length());
*--p= 0; /* kill , */
write_to_binlog(thd, query, p - query, db, db_len);
p= query + 11; /* reuse the initial "drop table" */
}
*p++ = '`';
p= strmov(p,tbl->real_name);
*p++ = '`';
*p++ = ',';
last_query_needs_write= 1;
}
if (last_query_needs_write)
{
*--p= 0;
Query_log_event qinfo(thd, query, q_len, 0, 0);
qinfo.error_code= 0;
mysql_bin_log.write(&qinfo);
write_to_binlog(thd, query, p - query, db, db_len);
}
}
exit:
......@@ -750,7 +777,7 @@ exit2:
*/
static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
const char *org_path, uint level, List<String> *dropped_tables)
const char *org_path, uint level, TABLE_LIST** dropped_tables)
{
long deleted=0;
ulong found_other_files=0;
......@@ -839,8 +866,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
}
}
if (thd->killed ||
(tot_list && mysql_rm_table_part2_with_lock(thd, tot_list, 1, 0,
1,dropped_tables)))
(tot_list && mysql_rm_table_part2_with_lock(thd, tot_list, 1, 0, 1)))
goto err;
/* Remove RAID directories */
......@@ -853,6 +879,9 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
}
my_dirend(dirp);
if (dropped_tables)
*dropped_tables= tot_list;
/*
If the directory is a symbolic link, remove the link first, then
remove the directory the symbolic link pointed at
......
......@@ -156,8 +156,7 @@ int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
int mysql_rm_table_part2_with_lock(THD *thd,
TABLE_LIST *tables, bool if_exists,
bool drop_temporary, bool dont_log_query,
List<String>* dropped_tables)
bool drop_temporary, bool dont_log_query)
{
int error;
thd->mysys_var->current_mutex= &LOCK_open;
......@@ -166,23 +165,6 @@ int mysql_rm_table_part2_with_lock(THD *thd,
error=mysql_rm_table_part2(thd,tables, if_exists, drop_temporary,
dont_log_query);
/*
For now we assume that if we got success all the tables in the list
were actually dropped, otherwise, assume none were dropped.
TODO: fix it to work with a partial drop - extremely rare case, but
can happen.
*/
if (!error && dropped_tables)
{
TABLE_LIST* tbl;
for (tbl= tables; tbl; tbl= tbl->next)
{
String *dropped_table= new (thd->mem_root)
String(tbl->real_name,&my_charset_latin1);
dropped_tables->push_back(dropped_table);
}
}
pthread_mutex_unlock(&LOCK_open);
......@@ -238,6 +220,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
for (table=tables ; table ; table=table->next)
{
char *db=table->db;
table->was_dropped= 0;
mysql_ha_flush(thd, table, MYSQL_HA_CLOSE_FINAL);
if (!close_temporary_table(thd, db, table->real_name))
{
......@@ -298,6 +281,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
wrong_tables.append(',');
wrong_tables.append(String(table->real_name,system_charset_info));
}
else
table->was_dropped= 1;
}
thd->tmp_table_used= tmp_table_deleted;
error= 0;
......
......@@ -235,6 +235,9 @@ typedef struct st_table_list
bool cacheable_table; /* stop PS caching */
/* used in multi-upd privelege check */
bool table_in_update_from_clause;
/* used for proper partially successful DROP DATABASE binlogging */
bool was_dropped;
} TABLE_LIST;
typedef struct st_changed_table_list
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment