#At file:///home/acorreia/workspace.sun/repository.mysql.new/bzrwork/wl-2775/mysql-next-mr-rpl-merge.crash-safe.2775/ based on revid:alfranio.correia@stripped
3028 Alfranio Correia 2010-09-14
Reorganized the functions that write to the system tables by closing tables
after committing or rolling back the statement.
modified:
sql/rpl_info_table.cc
sql/rpl_info_table_access.cc
sql/rpl_info_table_access.h
=== modified file 'sql/rpl_info_table.cc'
--- a/sql/rpl_info_table.cc 2010-09-13 22:34:27 +0000
+++ b/sql/rpl_info_table.cc 2010-09-13 23:08:23 +0000
@@ -82,10 +82,10 @@ end:
/*
Unlocks and closes the rpl_info table.
*/
- access->close_table(thd, table, &backup);
+ access->close_table(thd, table, &backup, error);
reenable_binlog(thd);
thd->variables.sql_mode= saved_mode;
- access->drop_bootstrap_thd(thd, error);
+ access->drop_bootstrap_thd(thd);
DBUG_RETURN(test(error));
}
@@ -104,7 +104,7 @@ int Rpl_info_table::do_flush_info(const
if (!(force || (sync_period &&
++(sync_counter) >= sync_period)))
{
- access->drop_bootstrap_thd(thd, 0);
+ access->drop_bootstrap_thd(thd);
DBUG_RETURN(0);
}
@@ -173,10 +173,10 @@ end:
/*
Unlocks and closes the rpl_info table.
*/
- access->close_table(thd, table, &backup);
+ access->close_table(thd, table, &backup, error);
reenable_binlog(thd);
thd->variables.sql_mode= saved_mode;
- access->drop_bootstrap_thd(thd, error);
+ access->drop_bootstrap_thd(thd);
DBUG_RETURN(test(error));
}
@@ -225,10 +225,10 @@ end:
/*
Unlocks and closes the rpl_info table.
*/
- access->close_table(thd, table, &backup);
+ access->close_table(thd, table, &backup, error);
reenable_binlog(thd);
thd->variables.sql_mode= saved_mode;
- access->drop_bootstrap_thd(thd, error);
+ access->drop_bootstrap_thd(thd);
DBUG_RETURN(test(error));
}
@@ -274,9 +274,9 @@ end:
/*
Unlocks and closes the rpl_info table.
*/
- access->close_table(thd, table, &backup);
+ access->close_table(thd, table, &backup, error);
thd->variables.sql_mode= saved_mode;
- access->drop_bootstrap_thd(thd, error);
+ access->drop_bootstrap_thd(thd);
DBUG_RETURN(test(error));
}
@@ -462,9 +462,9 @@ bool Rpl_info_table::do_is_transactional
&table, &backup))
is_trans= table->file->has_transactions();
- access->close_table(thd, table, &backup);
+ access->close_table(thd, table, &backup, 0);
thd->variables.sql_mode= saved_mode;
- access->drop_bootstrap_thd(thd, 0);
+ access->drop_bootstrap_thd(thd);
DBUG_RETURN(is_trans);
}
=== modified file 'sql/rpl_info_table_access.cc'
--- a/sql/rpl_info_table_access.cc 2010-09-13 22:34:27 +0000
+++ b/sql/rpl_info_table_access.cc 2010-09-13 23:08:23 +0000
@@ -58,12 +58,8 @@ bool Rpl_info_table_access::open_table(T
/*
This is equivalent to a new "statement". For that reason, we call both
- lex_start() and mysql_reset_thd_for_next_command. Note that the calls
- may reset the value of current_stmt_binlog_format. So we need to save
- the value outside the function and restore it after executing the new
- "statement".
+ lex_start() and mysql_reset_thd_for_next_command.
*/
-
if (thd->slave_thread || !current_thd)
{
lex_start(thd);
@@ -102,26 +98,47 @@ bool Rpl_info_table_access::open_table(T
}
/**
- Unlocks and closes a table.
+ Commits the changes, unlocks the table and closes it. This method
+ needs to be called even if the open_table fails, in order to ensure
+ the lock info is properly restored.
@param[in] thd Thread requesting to close the table
@param[in] table Table to be closed
@param[in] backup Restore the lock info from here
+ @param[in] error If there was an error while updating
+ the table
- This method needs to be called even if the open_table fails,
- in order to ensure the lock info is properly restored.
-
+ If there is an error, rolls back the current statement. Otherwise,
+ commits it. However, if a new thread was created and there is an
+ error, the transaction must be rolled back. Otherwise, it must be
+ committed. In this case, the changes were not done on behalf of
+ any user transaction and if not finished, there would be pending
+ changes.
+
@return
@retval FALSE No error
@retval TRUE Failure
*/
bool Rpl_info_table_access::close_table(THD *thd, TABLE* table,
- Open_tables_backup *backup)
+ Open_tables_backup *backup,
+ bool error)
{
DBUG_ENTER("Rpl_info_table_access::close_table");
if (table)
{
+ if (error)
+ ha_rollback_trans(thd, FALSE);
+ else
+ ha_commit_trans(thd, FALSE);
+
+ if (saved_current_thd != current_thd)
+ {
+ if (error)
+ ha_rollback_trans(thd, TRUE);
+ else
+ ha_commit_trans(thd, TRUE);
+ }
close_thread_tables(thd);
thd->restore_backup_open_tables_state(backup);
}
@@ -278,9 +295,7 @@ THD *Rpl_info_table_access::create_boots
thd->store_globals();
}
else
- {
thd= current_thd;
- }
saved_thd_type= thd->system_thread;
thd->system_thread= SYSTEM_THREAD_INFO;
@@ -289,37 +304,23 @@ THD *Rpl_info_table_access::create_boots
}
/**
- Destroys the created thread if necessary and does the following actions:
+ Destroys the created thread if necessary and restores the
+ system_thread information.
- - Restores the system_thread information.
- - If there is an error, rolls back the current statement. Otherwise,
- commits it.
- - If a new thread was created and there is an error, the transaction
- must be rolled back. Otherwise, it must be committed. In this case,
- the changes were not done on behalf of any user transaction and if
- not finished, there would be pending changes.
+ @param[in] thd Thread requesting to be destroyed
@return
- @retval THD* Pointer to thread structure
+ @retval FALSE No error
+ @retval TRUE Failure
*/
-bool Rpl_info_table_access::drop_bootstrap_thd(THD *thd, bool error)
+bool Rpl_info_table_access::drop_bootstrap_thd(THD *thd)
{
DBUG_ENTER("Rpl_info::drop_bootstrap_thd");
thd->system_thread= saved_thd_type;
- if (error)
- ha_rollback_trans(thd, FALSE);
- else
- ha_commit_trans(thd, FALSE);
-
if (saved_current_thd != current_thd)
{
- if (error)
- ha_rollback_trans(thd, TRUE);
- else
- ha_commit_trans(thd, TRUE);
-
delete thd;
my_pthread_setspecific_ptr(THR_THD, NULL);
}
=== modified file 'sql/rpl_info_table_access.h'
--- a/sql/rpl_info_table_access.h 2010-09-13 22:34:27 +0000
+++ b/sql/rpl_info_table_access.h 2010-09-13 23:08:23 +0000
@@ -39,7 +39,8 @@ public:
enum thr_lock_type lock_type,
TABLE** table,
Open_tables_backup* backup);
- bool close_table(THD* thd, TABLE* table, Open_tables_backup* backup);
+ bool close_table(THD* thd, TABLE* table, Open_tables_backup* backup,
+ bool error);
enum enum_return_id find_info_id(ulong server_id, uint idx, Rpl_info_fields *,
TABLE *table);
bool load_info_fields(uint max_num_field, Field **fields,
@@ -47,7 +48,7 @@ public:
bool store_info_fields(uint max_num_field, Field **fields,
Rpl_info_fields *field_values);
THD *create_bootstrap_thd();
- bool drop_bootstrap_thd(THD* thd, bool error);
+ bool drop_bootstrap_thd(THD* thd);
private:
THD *saved_current_thd;
Attachment: [text/bzr-bundle] bzr/alfranio.correia@oracle.com-20100913230823-rpvcjwu78dkrosv8.bundle
| Thread |
|---|
| • bzr commit into mysql-next-mr-rpl-merge branch (alfranio.correia:3028) | Alfranio Correia | 14 Sep |