diff options
author | unknown <mats@mysql.com> | 2006-02-16 08:30:53 +0100 |
---|---|---|
committer | unknown <mats@mysql.com> | 2006-02-16 08:30:53 +0100 |
commit | 41f7d138539c01afbcb6efb2f772fae0e9c3cd05 (patch) | |
tree | 24121bf489f59c8a8cbd3d4c0e587c27e3a9e0ed /sql/log.cc | |
parent | a89c10fd9b79a5d4eb42ae7d7ac00130919f456f (diff) | |
download | mariadb-git-41f7d138539c01afbcb6efb2f772fae0e9c3cd05.tar.gz |
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.
Diffstat (limited to 'sql/log.cc')
-rw-r--r-- | sql/log.cc | 128 |
1 files changed, 53 insertions, 75 deletions
diff --git a/sql/log.cc b/sql/log.cc index 7232d3a24dd..5ec3746ec1f 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -125,6 +125,12 @@ binlog_end_trans(THD *thd, binlog_trx_data *trx_data, Log_event *end_ev) if (end_ev) { + /* + We can always end the statement when ending a transaction since + transactions are not allowed inside stored functions. If they + were, we would have to ensure that we're not ending a statement + inside a stored function. + */ thd->binlog_flush_pending_rows_event(true); error= mysql_bin_log.write(thd, trans_log, end_ev); } @@ -144,7 +150,7 @@ binlog_end_trans(THD *thd, binlog_trx_data *trx_data, Log_event *end_ev) generated instead of the one that was written to the thrown-away transaction cache. */ - ++mysql_bin_log.m_table_map_version; + mysql_bin_log.update_table_map_version(); statistic_increment(binlog_cache_use, &LOCK_status); if (trans_log->disk_writes != 0) @@ -1678,6 +1684,38 @@ int THD::binlog_setup_trx_data() DBUG_RETURN(0); } +int THD::binlog_write_table_map(TABLE *table, bool is_trans) +{ + DBUG_ENTER("THD::binlog_write_table_map"); + DBUG_PRINT("enter", ("table=%p (%s: #%u)", + table, table->s->table_name, table->s->table_map_id)); + + /* Pre-conditions */ + DBUG_ASSERT(binlog_row_based && mysql_bin_log.is_open()); + DBUG_ASSERT(table->s->table_map_id != ULONG_MAX); + + Table_map_log_event::flag_set const + flags= Table_map_log_event::TM_NO_FLAGS; + + Table_map_log_event + the_event(this, table, table->s->table_map_id, is_trans, flags); + + /* + This function is called from ha_external_lock() after the storage + engine has registered for the transaction. + */ + if (is_trans) + trans_register_ha(this, options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN), + &binlog_hton); + + if (int error= mysql_bin_log.write(&the_event)) + DBUG_RETURN(error); + + ++binlog_table_maps; + table->s->table_map_version= mysql_bin_log.table_map_version(); + DBUG_RETURN(0); +} + Rows_log_event* THD::binlog_get_pending_rows_event() const { @@ -1695,8 +1733,12 @@ THD::binlog_get_pending_rows_event() const void THD::binlog_set_pending_rows_event(Rows_log_event* ev) { + if (ha_data[binlog_hton.slot] == NULL) + binlog_setup_trx_data(); + binlog_trx_data *const trx_data= (binlog_trx_data*) ha_data[binlog_hton.slot]; + DBUG_ASSERT(trx_data); trx_data->pending= ev; } @@ -1740,15 +1782,6 @@ int MYSQL_LOG::flush_and_set_pending_rows_event(THD *thd, Rows_log_event* event) pthread_mutex_lock(&LOCK_log); /* - Write a table map if necessary - */ - if (pending->maybe_write_table_map(thd, file, this)) - { - pthread_mutex_unlock(&LOCK_log); - DBUG_RETURN(2); - } - - /* Write pending event to log file or transaction cache */ if (pending->write(file)) @@ -1789,18 +1822,8 @@ int MYSQL_LOG::flush_and_set_pending_rows_event(THD *thd, Rows_log_event* event) pthread_mutex_unlock(&LOCK_log); } - else if (event && event->get_cache_stmt()) /* && pending == 0 */ - { - /* - If we are setting a non-null event for a table that is - transactional, we start a transaction here as well. - */ - trans_register_ha(thd, - thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN), - &binlog_hton); - } - trx_data->pending= event; + thd->binlog_set_pending_rows_event(event); DBUG_RETURN(error); } @@ -1832,21 +1855,13 @@ bool MYSQL_LOG::write(Log_event *event_info) mutex, we do this before aquiring the LOCK_log mutex in this function. - This is not optimal, but necessary in the current implementation - since there is code that writes rows to system tables without - using some way to flush the pending event (e.g., binlog_query()). - - TODO: There shall be no writes to any system table after calling - binlog_query(), so these writes has to be moved to before the call - of binlog_query() for correct functioning. - - This is necessesary not only for RBR, but the master might crash - after binlogging the query but before changing the system tables. - This means that the slave and the master are not in the same state - (after the master has restarted), so therefore we have to - eliminate this problem. + We only end the statement if we are in a top-level statement. If + we are inside a stored function, we do not end the statement since + this will close all tables on the slave. */ - thd->binlog_flush_pending_rows_event(true); + bool const end_stmt= + thd->prelocked_mode && thd->lex->requires_prelocking(); + thd->binlog_flush_pending_rows_event(end_stmt); pthread_mutex_lock(&LOCK_log); @@ -1869,8 +1884,9 @@ bool MYSQL_LOG::write(Log_event *event_info) (!binlog_filter->db_ok(local_db))) { VOID(pthread_mutex_unlock(&LOCK_log)); - DBUG_PRINT("info",("db_ok('%s')==%d", local_db, - binlog_filter->db_ok(local_db))); + DBUG_PRINT("info",("OPTION_BIN_LOG is %s, db_ok('%s') == %d", + (thd->options & OPTION_BIN_LOG) ? "set" : "clear", + local_db, binlog_filter->db_ok(local_db))); DBUG_RETURN(0); } #endif /* HAVE_REPLICATION */ @@ -2544,44 +2560,6 @@ void MYSQL_LOG::signal_update() DBUG_VOID_RETURN; } -#ifndef MYSQL_CLIENT -bool MYSQL_LOG::write_table_map(THD *thd, IO_CACHE *file, TABLE* table, - bool is_transactional) -{ - DBUG_ENTER("MYSQL_LOG::write_table_map()"); - DBUG_PRINT("enter", ("table=%p (%s: %u)", - table, table->s->table_name, table->s->table_map_id)); - - /* Pre-conditions */ - DBUG_ASSERT(binlog_row_based && is_open()); - DBUG_ASSERT(table->s->table_map_id != ULONG_MAX); - -#ifndef DBUG_OFF - /* - We only need to execute under the LOCK_log mutex if we are writing - to the log file; otherwise, we are writing to a thread-specific - transaction cache and there is no need to serialize this event - with events in other threads. - */ - if (file == &log_file) - safe_mutex_assert_owner(&LOCK_log); -#endif - - Table_map_log_event::flag_set const - flags= Table_map_log_event::TM_NO_FLAGS; - - Table_map_log_event - the_event(thd, table, table->s->table_map_id, is_transactional, flags); - - if (the_event.write(file)) - DBUG_RETURN(1); - - table->s->table_map_version= m_table_map_version; - DBUG_RETURN(0); -} -#endif /* !defined(MYSQL_CLIENT) */ - - #ifdef __NT__ void print_buffer_to_nt_eventlog(enum loglevel level, char *buff, uint length, int buffLen) |