mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
Fix for BUG#1686
"If 2 master threads with same-name temp table, slave makes bad binlog" and (two birds with one stone) for BUG#1240 "slave of slave breaks when STOP SLAVE was issud on parent slave and temp tables". Here is the design change: in a slave running with --log-slave-updates, events are now logged with the thread id they had on the master. So no more id conflicts between master threads, but introduces id conflicts between one master thread and one normal client thread connected to the slave. This is solved by storing the server id in the temp table's name. New test which requires mysql-test-run to be run with --manager, otherwise it will be skipped. Undoing a Monty's change (hum, a chill runs down my spine ;) which was "Cleanup temporary tables when slave ends" in ChangeSet 1.1572.1.1.
This commit is contained in:
@@ -589,6 +589,8 @@ TABLE **find_temporary_table(THD *thd, const char *db, const char *table_name)
|
||||
uint key_length= (uint) (strmov(strmov(key,db)+1,table_name)-key)+1;
|
||||
TABLE *table,**prev;
|
||||
|
||||
int4store(key+key_length,thd->server_id);
|
||||
key_length += 4;
|
||||
int4store(key+key_length,thd->slave_proxy_id);
|
||||
key_length += 4;
|
||||
|
||||
@@ -617,18 +619,27 @@ bool close_temporary_table(THD *thd, const char *db, const char *table_name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Used by ALTER TABLE when the table is a temporary one. It changes something
|
||||
only if the ALTER contained a RENAME clause (otherwise, table_name is the old
|
||||
name).
|
||||
Prepares a table cache key, which is the concatenation of db, table_name and
|
||||
thd->slave_proxy_id, separated by '\0'.
|
||||
*/
|
||||
bool rename_temporary_table(THD* thd, TABLE *table, const char *db,
|
||||
const char *table_name)
|
||||
{
|
||||
char *key;
|
||||
if (!(key=(char*) alloc_root(&table->mem_root,
|
||||
(uint) strlen(db)+
|
||||
(uint) strlen(table_name)+6)))
|
||||
(uint) strlen(table_name)+6+4)))
|
||||
return 1; /* purecov: inspected */
|
||||
table->key_length=(uint)
|
||||
(strmov((table->real_name=strmov(table->table_cache_key=key,
|
||||
db)+1),
|
||||
table_name) - table->table_cache_key)+1;
|
||||
int4store(key+table->key_length,thd->server_id);
|
||||
table->key_length += 4;
|
||||
int4store(key+table->key_length,thd->slave_proxy_id);
|
||||
table->key_length += 4;
|
||||
return 0;
|
||||
@@ -783,12 +794,13 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name,
|
||||
if (thd->killed)
|
||||
DBUG_RETURN(0);
|
||||
key_length= (uint) (strmov(strmov(key,db)+1,table_name)-key)+1;
|
||||
int4store(key + key_length, thd->slave_proxy_id);
|
||||
int4store(key + key_length, thd->server_id);
|
||||
int4store(key + key_length + 4, thd->slave_proxy_id);
|
||||
|
||||
for (table=thd->temporary_tables; table ; table=table->next)
|
||||
{
|
||||
if (table->key_length == key_length+4 &&
|
||||
!memcmp(table->table_cache_key,key,key_length+4))
|
||||
if (table->key_length == key_length+8 &&
|
||||
!memcmp(table->table_cache_key,key,key_length+8))
|
||||
{
|
||||
if (table->query_id == thd->query_id)
|
||||
{
|
||||
@@ -1596,7 +1608,7 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
|
||||
total of 6 extra bytes in my_malloc in addition to table/db stuff
|
||||
*/
|
||||
if (!(tmp_table=(TABLE*) my_malloc(sizeof(*tmp_table)+(uint) strlen(db)+
|
||||
(uint) strlen(table_name)+6,
|
||||
(uint) strlen(table_name)+6+4,
|
||||
MYF(MY_WME))))
|
||||
DBUG_RETURN(0); /* purecov: inspected */
|
||||
|
||||
@@ -1618,6 +1630,9 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
|
||||
strmov(tmp_table->table_cache_key,db)
|
||||
+1), table_name)
|
||||
- tmp_table->table_cache_key)+1;
|
||||
int4store(tmp_table->table_cache_key + tmp_table->key_length,
|
||||
thd->server_id);
|
||||
tmp_table->key_length += 4;
|
||||
int4store(tmp_table->table_cache_key + tmp_table->key_length,
|
||||
thd->slave_proxy_id);
|
||||
tmp_table->key_length += 4;
|
||||
|
||||
Reference in New Issue
Block a user