From 2b466692095c8e6163da8af4fa6df4b19634f534 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Feb 2006 08:30:53 +0100 Subject: WL#3023 (Use locks in a statement-like manner): Table maps are now written on aquiring locks to tables and released at the end of each logical statement. mysql-test/extra/binlog_tests/ctype_cp932.test: Disabling cleanup code mysql-test/r/binlog_row_blackhole.result: Result change mysql-test/r/binlog_row_mix_innodb_myisam.result: Result change mysql-test/r/binlog_stm_ctype_cp932.result: Result change mysql-test/r/rpl_row_charset.result: Result change mysql-test/r/rpl_row_create_table.result: Result change mysql-test/t/rpl_row_create_table.test: Binlog position change sql/handler.cc: Writing table map after external_lock() sql/handler.h: Adding class for table operation hooks. sql/log.cc: Adding binlog_write_table_map() to THD. Removing write_table_map() from MYSQL_LOG. sql/log.h: Minor interface changes to move table map writing. sql/log_event.cc: Removing pre-allocation of memory for buffers. Allowing ULONG_MAX as table id denoting an event to ignore (only used to transfer flags). Adding code to collect tables while seeing table maps and lock collected tables when seeing a binrow event. Debriding code as a result of the above changes. sql/log_event.h: Minor interface changes. sql/mysql_priv.h: Adding hooks argument to create_table_from_items(). sql/parse_file.cc: Minor fix to avoid crash in debug printout. sql/rpl_rli.h: Adding list of tables to lock to RLI structure. sql/slave.cc: Using list of tables to lock from RLI structure. sql/sql_acl.cc: Removing redundant pending events flush. sql/sql_base.cc: Moving pending event flush. Using flag to guard to clear statement transaction only if this is the original open tables state. sql/sql_class.cc: Adding flag for open tables state. Removing redundant pending events flushes. Write a dummy event to indicate that the tables to lock should be emptied on the slave. sql/sql_class.h: Adding open tables state flags. Adding binlog_write_table_map() function to THD. Changes to select_create() to support new locking scheme. sql/sql_insert.cc: Adding rollback of statement transaction on error. It can now contain events after locking tables. sql/sql_load.cc: Removing redundant pending event flush. sql/sql_table.cc: Adding hooks argument to create_table_from_items(). Calling prelock hook before starting to lock tables. sql/sql_update.cc: Removing a compiler warning. sql/table.h: Minor changes. --- sql/sql_base.cc | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'sql/sql_base.cc') diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 85c5a481d47..23ed7a53a64 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1031,21 +1031,18 @@ void close_thread_tables(THD *thd, bool lock_in_use, bool skip_derived) /* Fallthrough */ } - /* - For RBR: before calling close_thread_tables(), storage engines - should autocommit. Hence if there is a a pending event, it belongs - to a non-transactional engine, which writes directly to the table, - and should therefore be flushed before unlocking and closing the - tables. The test above for locked tables will not be triggered - since RBR locks and unlocks tables on a per-event basis. - - TODO (WL#3023): Change the semantics so that RBR does not lock and - unlock tables on a per-event basis. - */ - thd->binlog_flush_pending_rows_event(true); - if (thd->lock) { + /* + For RBR we flush the pending event just before we unlock all the + tables. This means that we are at the end of a topmost + statement, so we ensure that the STMT_END_F flag is set on the + pending event. For statements that are *inside* stored + functions, the pending event will not be flushed: that will be + handled either before writing a query log event (inside + binlog_query()) or when preparing a pending event. + */ + thd->binlog_flush_pending_rows_event(true); mysql_unlock_tables(thd, thd->lock); thd->lock=0; } @@ -1057,7 +1054,8 @@ void close_thread_tables(THD *thd, bool lock_in_use, bool skip_derived) saves some work in 2pc too) see also sql_parse.cc - dispatch_command() */ - bzero(&thd->transaction.stmt, sizeof(thd->transaction.stmt)); + if (!(thd->state_flags & Open_tables_state::BACKUPS_AVAIL)) + bzero(&thd->transaction.stmt, sizeof(thd->transaction.stmt)); if (!thd->active_transaction()) thd->transaction.xid_state.xid.null(); -- cgit v1.2.1