MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Sergey Vojtovich Date:April 1 2010 11:27am
Subject:bzr commit into mysql-5.1-bugteam branch (svoj:3468) Bug#41609
View as plain text  
#At file:///home/svoj/devel/innodb-snapshots/mysql-5.1-bugteam/ based on revid:svoj@stripped

 3468 Sergey Vojtovich	2010-04-01
      Applying InnoDB snapshot, fixes BUG#41609.
      
      Detailed revision comments:
      
      r6521 | marko | 2010-01-27 10:49:01 +0200 (Wed, 27 Jan 2010) | 17 lines
      branches/zip: Drop temporary tables at startup.
      This addresses the third aspect of Bug #41609.
      
      row_mysql_drop_temp_tables(): New function, to drop all temporary
      tables. These can be distinguished by the least significant bit of
      MIX_LEN. However, we will skip ROW_FORMAT=REDUNDANT tables, because in
      the records for those tables, that bit may be garbage.
      
      recv_recovery_from_checkpoint_finish(): Invoke
      row_mysql_drop_temp_tables().  Normally, if the .frm files for the
      temporary tables exist at startup, MySQL will ask InnoDB to drop the
      temporary tables.  However, if the files are deleted, for instance, by
      the boot scripts of the operating system, the tables would remain in
      the InnoDB data dictionary unless someone digs them up by
      innodb_table_monitor and creates .frm files for dropping the tables.
      
      rb://221 approved by Sunny Bains.

    modified:
      storage/innodb_plugin/ChangeLog
      storage/innodb_plugin/include/row0mysql.h
      storage/innodb_plugin/log/log0recv.c
      storage/innodb_plugin/row/row0mysql.c
=== modified file 'storage/innodb_plugin/ChangeLog'
--- a/storage/innodb_plugin/ChangeLog	2010-04-01 11:25:39 +0000
+++ b/storage/innodb_plugin/ChangeLog	2010-04-01 11:26:39 +0000
@@ -1,3 +1,10 @@
+2010-01-27	The InnoDB Team
+
+	* include/row0mysql.h, log/log0recv.c, row/row0mysql.c:
+	Drop temporary tables at startup.
+	This addresses the third aspect of
+	Bug#41609 Crash recovery does not work for InnoDB temporary tables.
+
 2010-01-21	The InnoDB Team
 
 	* buf/buf0buf.c:

=== modified file 'storage/innodb_plugin/include/row0mysql.h'
--- a/storage/innodb_plugin/include/row0mysql.h	2009-11-03 10:22:15 +0000
+++ b/storage/innodb_plugin/include/row0mysql.h	2010-04-01 11:26:39 +0000
@@ -451,6 +451,12 @@ row_drop_table_for_mysql(
 	const char*	name,	/*!< in: table name */
 	trx_t*		trx,	/*!< in: transaction handle */
 	ibool		drop_db);/*!< in: TRUE=dropping whole database */
+/*********************************************************************//**
+Drop all temporary tables during crash recovery. */
+UNIV_INTERN
+void
+row_mysql_drop_temp_tables(void);
+/*============================*/
 
 /*********************************************************************//**
 Discards the tablespace of a table which stored in an .ibd file. Discarding

=== modified file 'storage/innodb_plugin/log/log0recv.c'
--- a/storage/innodb_plugin/log/log0recv.c	2010-04-01 11:10:01 +0000
+++ b/storage/innodb_plugin/log/log0recv.c	2010-04-01 11:26:39 +0000
@@ -3264,6 +3264,8 @@ recv_recovery_from_checkpoint_finish(voi
 
 	/* Drop partially created indexes. */
 	row_merge_drop_temp_indexes();
+	/* Drop temporary tables. */
+	row_mysql_drop_temp_tables();
 
 #ifdef UNIV_SYNC_DEBUG
 	/* Wait for a while so that created threads have time to suspend

=== modified file 'storage/innodb_plugin/row/row0mysql.c'
--- a/storage/innodb_plugin/row/row0mysql.c	2010-04-01 11:19:38 +0000
+++ b/storage/innodb_plugin/row/row0mysql.c	2010-04-01 11:26:39 +0000
@@ -3363,6 +3363,99 @@ funct_exit:
 	return((int) err);
 }
 
+/*********************************************************************//**
+Drop all temporary tables during crash recovery. */
+UNIV_INTERN
+void
+row_mysql_drop_temp_tables(void)
+/*============================*/
+{
+	trx_t*	trx;
+	ulint	err;
+
+	trx = trx_allocate_for_background();
+	trx->op_info = "dropping temporary tables";
+	row_mysql_lock_data_dictionary(trx);
+
+	err = que_eval_sql(
+		NULL,
+		"PROCEDURE DROP_TEMP_TABLES_PROC () IS\n"
+		"table_name CHAR;\n"
+		"table_id CHAR;\n"
+		"foreign_id CHAR;\n"
+		"index_id CHAR;\n"
+		"DECLARE CURSOR c IS SELECT NAME,ID FROM SYS_TABLES\n"
+		"WHERE N_COLS > 2147483647\n"
+		/* N_COLS>>31 is set unless ROW_FORMAT=REDUNDANT,
+		and MIX_LEN may be garbage for those tables */
+		"AND MIX_LEN=(MIX_LEN/2*2+1);\n"
+		/* MIX_LEN & 1 is set for temporary tables */
+#if DICT_TF2_TEMPORARY != 1
+# error "DICT_TF2_TEMPORARY != 1"
+#endif
+		"BEGIN\n"
+		"OPEN c;\n"
+		"WHILE 1=1 LOOP\n"
+		"	FETCH c INTO table_name, table_id;\n"
+		"	IF (SQL % NOTFOUND) THEN\n"
+		"		EXIT;\n"
+		"	END IF;\n"
+		"	WHILE 1=1 LOOP\n"
+		"		SELECT ID INTO index_id\n"
+		"		FROM SYS_INDEXES\n"
+		"		WHERE TABLE_ID = table_id\n"
+		"		LOCK IN SHARE MODE;\n"
+		"		IF (SQL % NOTFOUND) THEN\n"
+		"			EXIT;\n"
+		"		END IF;\n"
+
+		/* Do not drop tables for which there exist
+		foreign key constraints. */
+		"		SELECT ID INTO foreign_id\n"
+		"		FROM SYS_FOREIGN\n"
+		"		WHERE FOR_NAME = table_name\n"
+		"		AND TO_BINARY(FOR_NAME)\n"
+		"		  = TO_BINARY(table_name)\n;"
+		"		IF NOT (SQL % NOTFOUND) THEN\n"
+		"			EXIT;\n"
+		"		END IF;\n"
+
+		"		SELECT ID INTO foreign_id\n"
+		"		FROM SYS_FOREIGN\n"
+		"		WHERE REF_NAME = table_name\n"
+		"		AND TO_BINARY(REF_NAME)\n"
+		"		  = TO_BINARY(table_name)\n;"
+		"		IF NOT (SQL % NOTFOUND) THEN\n"
+		"			EXIT;\n"
+		"		END IF;\n"
+
+		"		DELETE FROM SYS_FIELDS\n"
+		"		WHERE INDEX_ID = index_id;\n"
+		"		DELETE FROM SYS_INDEXES\n"
+		"		WHERE ID = index_id\n"
+		"		AND TABLE_ID = table_id;\n"
+		"	END LOOP;\n"
+		"	DELETE FROM SYS_COLUMNS\n"
+		"	WHERE TABLE_ID = table_id;\n"
+		"	DELETE FROM SYS_TABLES\n"
+		"	WHERE ID = table_id;\n"
+		"END LOOP;\n"
+		"COMMIT WORK;\n"
+		"END;\n"
+		, FALSE, trx);
+
+	if (err != DB_SUCCESS) {
+		ut_print_timestamp(stderr);
+		fprintf(stderr,
+			"  InnoDB: Failed to drop temporary tables:"
+			" error %lu occurred\n",
+			(ulong) err);
+	}
+
+	row_mysql_unlock_data_dictionary(trx);
+	trx_free_for_background(trx);
+}
+
 /*******************************************************************//**
 Drop all foreign keys in a database, see Bug#18942.
 Called at the end of row_drop_database_for_mysql().


Attachment: [text/bzr-bundle] bzr/svoj@sun.com-20100401112639-xalx8eged695yv1y.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (svoj:3468) Bug#41609Sergey Vojtovich1 Apr