2012-03-28 01:04:46 +02:00
|
|
|
/* Copyright (c) 2006, 2011, Oracle and/or its affiliates.
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-27 02:23:51 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2019-05-11 20:29:06 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
|
2006-01-12 19:51:02 +01:00
|
|
|
|
2017-06-18 05:42:16 +02:00
|
|
|
#include "mariadb.h"
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_priv.h"
|
2006-01-12 19:51:02 +01:00
|
|
|
#include "rpl_injector.h"
|
2009-12-03 19:37:38 +01:00
|
|
|
#include "transaction.h"
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_parse.h" // begin_trans, end_trans, COMMIT
|
|
|
|
#include "sql_base.h" // close_thread_tables
|
|
|
|
#include "log_event.h" // Incident_log_event
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
injector::transaction - member definitions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* inline since it's called below */
|
|
|
|
inline
|
2006-05-05 08:45:58 +02:00
|
|
|
injector::transaction::transaction(MYSQL_BIN_LOG *log, THD *thd)
|
2006-02-24 16:19:55 +01:00
|
|
|
: m_state(START_STATE), m_thd(thd)
|
2006-01-12 19:51:02 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Default initialization of m_start_pos (which initializes it to garbage).
|
|
|
|
We need to fill it in using the code below.
|
|
|
|
*/
|
|
|
|
LOG_INFO log_info;
|
|
|
|
log->get_current_log(&log_info);
|
|
|
|
/* !!! binlog_pos does not follow RAII !!! */
|
2020-01-29 13:50:26 +01:00
|
|
|
m_start_pos.m_file_name= my_strdup(key_memory_binlog_pos,
|
|
|
|
log_info.log_file_name, MYF(0));
|
2006-01-12 19:51:02 +01:00
|
|
|
m_start_pos.m_file_pos= log_info.pos;
|
|
|
|
|
WL#3072 Maria Recovery
All statements doing an implicit commit now also do one in Maria.
This is useful because LOCK TABLES; REPAIR; crash; is not rollback-able,
the implicit commit of REPAIR avoid that Recovery tries to rollback
and fails.
Fix for BUG#33827 "COMMIT AND CHAIN causes serious Valgrind error"
(maybe not the definite one, depends on the assigned dev).
mysql-test/t/maria-recovery.test:
test of REPAIR's implicit commit. I cannot commit the result file
because maria-recovery fails in vanilla tree (seen in pushbuild) but
its new section looks like:
repair table t1;
Table Op Msg_type Msg_text
mysqltest.t1 repair status OK
insert into t1 values(2);
select * from t1;
a
1
2
3
SET SESSION debug="+d,maria_flush_whole_log,maria_flush_whole_page_cache,maria_crash";
* crashing mysqld intentionally
set global maria_checkpoint_interval=1;
ERROR HY000: Lost connection to MySQL server during query
* recovery happens
check table t1 extended;
Table Op Msg_type Msg_text
mysqltest.t1 check status OK
* testing that checksum after recovery is as expected
Checksum-check
failure
use mysqltest;
select * from t1;
a
1
3
Which is as it should be.
sql/rpl_injector.cc:
fix for BUG#33827
sql/sql_parse.cc:
- All DDLs and mysql_admin_table() (REPAIR etc) use end_actrive_trans()
to do an implicit commit so we add there an implicit commit of the
Maria transaction.
- Fix for BUG#33827
storage/maria/ha_maria.cc:
- A method to do implicit commit in Maria
- After an implicit commit, if it was under LOCK TABLES, the locked
tables have a stale file->trn: update it.
storage/maria/ha_maria.h:
new static method
storage/maria/ma_check.c:
bugfix: this disabling of transactionality had the effect that if
LOCK TABLES; REPAIR; INSERT then the INSERT ran non-transactional
(so couldn't be undone in case of crash, if, by bad chance, its
effect on pages went to disk).
storage/maria/ma_checkpoint.c:
indentation
storage/maria/ma_recovery.c:
dbug statements
storage/maria/trnman.c:
When doing an implicit commit we need to know the number of locked
tables of the committed transaction and copy it to the new transaction
storage/maria/trnman_public.h:
prototype change
2008-01-11 22:48:54 +01:00
|
|
|
m_thd->lex->start_transaction_opt= 0; /* for begin_trans() */
|
2009-12-03 19:37:38 +01:00
|
|
|
trans_begin(m_thd);
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
injector::transaction::~transaction()
|
|
|
|
{
|
2006-03-11 06:58:48 +01:00
|
|
|
if (!good())
|
|
|
|
return;
|
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
/* Needed since my_free expects a 'char*' (instead of 'void*'). */
|
|
|
|
char* const the_memory= const_cast<char*>(m_start_pos.m_file_name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
We set the first character to null just to give all the copies of the
|
|
|
|
start position a (minimal) chance of seening that the memory is lost.
|
|
|
|
All assuming the my_free does not step over the memory, of course.
|
|
|
|
*/
|
|
|
|
*the_memory= '\0';
|
|
|
|
|
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly
slow as it checks all allocated blocks for overrun at each
memory management primitive, yielding a almost exponential
slowdown for the memory management functions (malloc, realloc,
free). The overrun check basically consists of verifying some
bytes of a block for certain magic keys, which catches some
simple forms of overrun. Another minor problem is violation
of aliasing rules and that its own internal list of blocks
is prone to corruption.
Another issue with safemalloc is rather the maintenance cost
as the tool has a significant impact on the server code.
Given the magnitude of memory debuggers available nowadays,
especially those that are provided with the platform malloc
implementation, maintenance of a in-house and largely obsolete
memory debugger becomes a burden that is not worth the effort
due to its slowness and lack of support for detecting more
common forms of heap corruption.
Since there are third-party tools that can provide the same
functionality at a lower or comparable performance cost, the
solution is to simply remove safemalloc. Third-party tools
can provide the same functionality at a lower or comparable
performance cost.
The removal of safemalloc also allows a simplification of the
malloc wrappers, removing quite a bit of kludge: redefinition
of my_malloc, my_free and the removal of the unused second
argument of my_free. Since free() always check whether the
supplied pointer is null, redudant checks are also removed.
Also, this patch adds unit testing for my_malloc and moves
my_realloc implementation into the same file as the other
memory allocation primitives.
client/mysqldump.c:
Pass my_free directly as its signature is compatible with the
callback type -- which wasn't the case for free_table_ent.
2010-07-08 23:20:08 +02:00
|
|
|
my_free(the_memory);
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2010-02-04 21:15:47 +01:00
|
|
|
/**
|
|
|
|
@retval 0 transaction committed
|
|
|
|
@retval 1 transaction rolled back
|
|
|
|
*/
|
2006-01-12 19:51:02 +01:00
|
|
|
int injector::transaction::commit()
|
|
|
|
{
|
2020-11-30 14:29:32 +01:00
|
|
|
DBUG_ENTER("injector::transaction::commit()");
|
|
|
|
int error= m_thd->binlog_flush_pending_rows_event(true);
|
|
|
|
/*
|
|
|
|
Cluster replication does not preserve statement or
|
|
|
|
transaction boundaries of the master. Instead, a new
|
|
|
|
transaction on replication slave is started when a new GCI
|
|
|
|
(global checkpoint identifier) is issued, and is committed
|
|
|
|
when the last event of the check point has been received and
|
|
|
|
processed. This ensures consistency of each cluster in
|
|
|
|
cluster replication, and there is no requirement for stronger
|
|
|
|
consistency: MySQL replication is asynchronous with other
|
|
|
|
engines as well.
|
A fix and a test case for Bug#12713 "Error in a stored function called from
a SELECT doesn't cause ROLLBACK of statem".
The idea of the fix is to ensure that we always commit the current
statement at the end of dispatch_command(). In order to not issue
redundant disc syncs, an optimization of the two-phase commit
protocol is implemented to bypass the two phase commit if
the transaction is read-only.
mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result:
Update test results.
mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result:
Update test results.
mysql-test/suite/rpl_ndb/t/disabled.def:
Disable the tests, for which this changeset reveals a bug:
the injector thread does not always add 'statement commit' to the
rows injected in circular replication set up.
To be investigated separately.
sql/ha_ndbcluster_binlog.cc:
Add close_thread_tables() to run_query: this ensures
that all tables are closed and there is no pending statement transaction.
sql/handler.cc:
Implement optimisation of read-only transactions.
If a transaction consists only of DML statements that do not change
data, we do not perform a two-phase commit for it
(run one phase commit only).
sql/handler.h:
Implement optimisation of read-only transactions.
If a transaction consists only of DML statements that do not change
data, we do not perform a two-phase commit for it
(run one phase commit only).
sql/log.cc:
Mark the binlog transaction read-write whenever it's started.
We never read from binlog, so it's safe and least intrusive to add
this mark up here.
sql/log_event.cc:
Update to the new layout of thd->transaction.
sql/rpl_injector.cc:
Always commit statement transaction before committing the global one.
sql/sp.cc:
Ad comments.
sql/sp_head.cc:
Add comments.
sql/sql_base.cc:
Commit transaction at the end of the statement. Always.
sql/sql_class.cc:
Update thd_ha_data to return the right pointer in the new layout.
Fix select_dumpvar::send_data to properly return operation status.
A test case from commit.inc would lead to an assertion failure in the
diagnostics area (double assignment). Not test otherwise by the test suite.
sql/sql_class.h:
Implement a new layout of storage engine transaction info in which
it is easy to access all members related to the handlerton only
based on ht->slot.
sql/sql_cursor.cc:
Update to the new layout of thd->transaction.
sql/sql_delete.cc:
Remove wrong and now redundant calls to ha_autocommit_or_rollback.
The transaction is committed in one place, at the end of the statement.
Remove calls to mysql_unlock_tables, since some engines count locks
and commit statement transaction in unlock_tables(), which essentially
equates mysql_unlock_tables to ha_autocommit_or_rollback.
Previously it was necessary to unlock tables soon because we wanted
to avoid sending of 'ok' packet to the client under locked tables.
This is no longer necessary, since OK packet is also sent from one place
at the end of transaction.
sql/sql_do.cc:
Add DO always clears the error, we must rollback the current
statement before this happens. Otherwise the statement will be committed,
and not rolled back in the end.
sql/sql_insert.cc:
Remove wrong and now redundant calls to ha_autocommit_or_rollback.
The transaction is committed in one place, at the end of the statement.
Remove calls to mysql_unlock_tables, since some engines count locks
and commit statement transaction in unlock_tables(), which essentially
equates mysql_unlock_tables to ha_autocommit_or_rollback.
Previously it was necessary to unlock tables soon because we wanted
to avoid sending of 'ok' packet to the client under locked tables.
This is no longer necessary, since OK packet is also sent from one place
at the end of transaction.
sql/sql_load.cc:
Remove wrong and now redundant calls to ha_autocommit_or_rollback.
The transaction is committed in one place, at the end of the statement.
Remove calls to mysql_unlock_tables, since some engines count locks
and commit statement transaction in unlock_tables(), which essentially
equates mysql_unlock_tables to ha_autocommit_or_rollback.
Previously it was necessary to unlock tables soon because we wanted
to avoid sending of 'ok' packet to the client under locked tables.
This is no longer necessary, since OK packet is also sent from one place
at the end of transaction.
sql/sql_parse.cc:
Implement optimisation of read-only transactions: bypass 2-phase
commit for them.
Always commit statement transaction before commiting the global one.
Fix an unrelated crash in check_table_access, when called from
information_schema.
sql/sql_partition.cc:
Partitions commit at the end of a DDL operation.
Make sure that send_ok() is done only if the commit has succeeded.
sql/sql_table.cc:
Use ha_autocommit_or_rollback and end_active_trans everywhere.
Add end_trans to mysql_admin_table, so that it leaves no pending
transaction.
sql/sql_udf.cc:
Remvove a redundant call to close_thread_tables()
sql/sql_update.cc:
Remove wrong and now redundant calls to ha_autocommit_or_rollback.
The transaction is committed in one place, at the end of the statement.
Remove calls to mysql_unlock_tables, since some engines count locks
and commit statement transaction in unlock_tables(), which essentially
equates mysql_unlock_tables to ha_autocommit_or_rollback.
Previously it was necessary to unlock tables soon because we wanted
to avoid sending of 'ok' packet to the client under locked tables.
This is no longer necessary, since OK packet is also sent from one place
at the end of transaction.
mysql-test/include/commit.inc:
New BitKeeper file ``mysql-test/include/commit.inc''
mysql-test/r/commit_1innodb.result:
New BitKeeper file ``mysql-test/r/commit_1innodb.result''
mysql-test/t/commit_1innodb.test:
New BitKeeper file ``mysql-test/t/commit_1innodb.test''
2008-02-19 12:43:01 +01:00
|
|
|
|
2020-11-30 14:29:32 +01:00
|
|
|
A practical consequence of that is that row level replication
|
|
|
|
stream passed through the injector thread never contains
|
|
|
|
COMMIT events.
|
|
|
|
Here we should preserve the server invariant that there is no
|
|
|
|
outstanding statement transaction when the normal transaction
|
|
|
|
is committed by committing the statement transaction
|
|
|
|
explicitly.
|
|
|
|
*/
|
|
|
|
trans_commit_stmt(m_thd);
|
|
|
|
if (!trans_commit(m_thd))
|
|
|
|
{
|
|
|
|
close_thread_tables(m_thd);
|
|
|
|
m_thd->release_transactional_locks();
|
|
|
|
}
|
|
|
|
DBUG_RETURN(error);
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
Backport of revno ## 2617.31.1, 2617.31.3, 2617.31.4, 2617.31.5,
2617.31.12, 2617.31.15, 2617.31.15, 2617.31.16, 2617.43.1
- initial changeset that introduced the fix for
Bug#989 and follow up fixes for all test suite failures
introduced in the initial changeset.
------------------------------------------------------------
revno: 2617.31.1
committer: Davi Arnaut <Davi.Arnaut@Sun.COM>
branch nick: 4284-6.0
timestamp: Fri 2009-03-06 19:17:00 -0300
message:
Bug#989: If DROP TABLE while there's an active transaction, wrong binlog order
WL#4284: Transactional DDL locking
Currently the MySQL server does not keep metadata locks on
schema objects for the duration of a transaction, thus failing
to guarantee the integrity of the schema objects being used
during the transaction and to protect then from concurrent
DDL operations. This also poses a problem for replication as
a DDL operation might be replicated even thought there are
active transactions using the object being modified.
The solution is to defer the release of metadata locks until
a active transaction is either committed or rolled back. This
prevents other statements from modifying the table for the
entire duration of the transaction. This provides commitment
ordering for guaranteeing serializability across multiple
transactions.
- Incompatible change:
If MySQL's metadata locking system encounters a lock conflict,
the usual schema is to use the try and back-off technique to
avoid deadlocks -- this schema consists in releasing all locks
and trying to acquire them all in one go.
But in a transactional context this algorithm can't be utilized
as its not possible to release locks acquired during the course
of the transaction without breaking the transaction commitments.
To avoid deadlocks in this case, the ER_LOCK_DEADLOCK will be
returned if a lock conflict is encountered during a transaction.
Let's consider an example:
A transaction has two statements that modify table t1, then table
t2, and then commits. The first statement of the transaction will
acquire a shared metadata lock on table t1, and it will be kept
utill COMMIT to ensure serializability.
At the moment when the second statement attempts to acquire a
shared metadata lock on t2, a concurrent ALTER or DROP statement
might have locked t2 exclusively. The prescription of the current
locking protocol is that the acquirer of the shared lock backs off
-- gives up all his current locks and retries. This implies that
the entire multi-statement transaction has to be rolled back.
- Incompatible change:
FLUSH commands such as FLUSH PRIVILEGES and FLUSH TABLES WITH READ
LOCK won't cause locked tables to be implicitly unlocked anymore.
mysql-test/extra/binlog_tests/drop_table.test:
Add test case for Bug#989.
mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test:
Fix test case to reflect the fact that transactions now hold
metadata locks for the duration of a transaction.
mysql-test/include/mix1.inc:
Fix test case to reflect the fact that transactions now hold
metadata locks for the duration of a transaction.
mysql-test/include/mix2.inc:
Fix test case to reflect the fact that transactions now hold
metadata locks for the duration of a transaction.
mysql-test/r/flush_block_commit.result:
Update test case result (WL#4284).
mysql-test/r/flush_block_commit_notembedded.result:
Update test case result (WL#4284).
mysql-test/r/innodb.result:
Update test case result (WL#4284).
mysql-test/r/innodb_mysql.result:
Update test case result (WL#4284).
mysql-test/r/lock.result:
Add test case result for an effect of WL#4284/Bug#989
(all locks should be released when a connection terminates).
mysql-test/r/mix2_myisam.result:
Update test case result (effects of WL#4284/Bug#989).
mysql-test/r/not_embedded_server.result:
Update test case result (effects of WL#4284/Bug#989).
Add a test case for interaction of WL#4284 and FLUSH PRIVILEGES.
mysql-test/r/partition_innodb_semi_consistent.result:
Update test case result (effects of WL#4284/Bug#989).
mysql-test/r/partition_sync.result:
Temporarily disable the test case for Bug#43867,
which will be fixed by a subsequent backport.
mysql-test/r/ps.result:
Add a test case for effect of PREPARE on transactional
locks: we take a savepoint at beginning of PREAPRE
and release it at the end. Thus PREPARE does not
accumulate metadata locks (Bug#989/WL#4284).
mysql-test/r/read_only_innodb.result:
Update test case result (effects of WL#4284/Bug#989).
mysql-test/suite/binlog/r/binlog_row_drop_tbl.result:
Add a test case result (WL#4284/Bug#989).
mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result:
Update test case result (effects of WL#4284/Bug#989).
mysql-test/suite/binlog/r/binlog_stm_drop_tbl.result:
Add a test case result (WL#4284/Bug#989).
mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result:
Update test case result (effects of WL#4284/Bug#989).
mysql-test/suite/binlog/r/binlog_unsafe.result:
A side effect of Bug#989 -- slightly different table map ids.
mysql-test/suite/binlog/t/binlog_row_drop_tbl.test:
Add a test case for WL#4284/Bug#989.
mysql-test/suite/binlog/t/binlog_stm_drop_tbl.test:
Add a test case for WL#4284/Bug#989.
mysql-test/suite/binlog/t/binlog_stm_row.test:
Update to the new state name. This
is actually a follow up to another patch for WL#4284,
that changes Locked thread state to Table lock.
mysql-test/suite/ndb/r/ndb_index_ordered.result:
Remove result for disabled part of the test case.
mysql-test/suite/ndb/t/disabled.def:
Temporarily disable a test case (Bug#45621).
mysql-test/suite/ndb/t/ndb_index_ordered.test:
Disable a part of a test case (needs update to
reflect semantics of Bug#989).
mysql-test/suite/rpl/t/disabled.def:
Disable tests made meaningless by transactional metadata
locking.
mysql-test/suite/sys_vars/r/autocommit_func.result:
Add a commit (Bug#989).
mysql-test/suite/sys_vars/t/autocommit_func.test:
Add a commit (Bug#989).
mysql-test/t/flush_block_commit.test:
Fix test case to reflect the fact that transactions now hold
metadata locks for the duration of a transaction.
mysql-test/t/flush_block_commit_notembedded.test:
Fix test case to reflect the fact that transactions now hold
metadata locks for the duration of a transaction.
Add a test case for transaction-scope locks and the global
read lock (Bug#989/WL#4284).
mysql-test/t/innodb.test:
Fix test case to reflect the fact that transactions now hold
metadata locks for the duration of a transaction
(effects of Bug#989/WL#4284).
mysql-test/t/lock.test:
Add a test case for Bug#989/WL#4284.
mysql-test/t/not_embedded_server.test:
Add a test case for Bug#989/WL#4284.
mysql-test/t/partition_innodb_semi_consistent.test:
Replace TRUNCATE with DELETE, to not issue
an implicit commit of a transaction, and not depend
on metadata locks.
mysql-test/t/partition_sync.test:
Temporarily disable the test case for Bug#43867,
which needs a fix to be backported from 6.0.
mysql-test/t/ps.test:
Add a test case for semantics of PREPARE and transaction-scope
locks: metadata locks on tables used in PREPARE are enclosed into a
temporary savepoint, taken at the beginning of PREPARE,
and released at the end. Thus PREPARE does not effect
what locks a transaction owns.
mysql-test/t/read_only_innodb.test:
Fix test case to reflect the fact that transactions now hold
metadata locks for the duration of a transaction
(Bug#989/WL#4284).
Wait for the read_only statement to actually flush tables before
sending other concurrent statements that depend on its state.
mysql-test/t/xa.test:
Fix test case to reflect the fact that transactions now hold
metadata locks for the duration of a transaction
(Bug#989/WL#4284).
sql/ha_ndbcluster_binlog.cc:
Backport bits of changes of ha_ndbcluster_binlog.cc
from 6.0, to fix the failing binlog test suite with
WL#4284. WL#4284 implementation does not work
with 5.1 implementation of ndbcluster binlog index.
sql/log_event.cc:
Release metadata locks after issuing a commit.
sql/mdl.cc:
Style changes (WL#4284).
sql/mysql_priv.h:
Rename parameter to match the name used in the definition (WL#4284).
sql/rpl_injector.cc:
Release metadata locks on commit (WL#4284).
sql/rpl_rli.cc:
Remove assert made meaningless, metadata locks are released
at the end of the transaction.
sql/set_var.cc:
Close tables and release locks if autocommit mode is set.
sql/slave.cc:
Release metadata locks after a rollback.
sql/sql_acl.cc:
Don't implicitly unlock locked tables. Issue a implicit commit
at the end and unlock tables.
sql/sql_base.cc:
Defer the release of metadata locks when closing tables
if not required to.
Issue a deadlock error if the locking protocol requires
that a transaction re-acquire its locks.
Release metadata locks when closing tables for reopen.
sql/sql_class.cc:
Release metadata locks if the thread is killed.
sql/sql_parse.cc:
Release metadata locks after implicitly committing a active
transaction, or after explicit commits or rollbacks.
sql/sql_plugin.cc:
Allocate MDL request on the stack as the use of the table
is contained within the function. It will be removed from
the context once close_thread_tables is called at the end
of the function.
sql/sql_prepare.cc:
The problem is that the prepare phase of the CREATE TABLE
statement takes a exclusive metadata lock lock and this can
cause a self-deadlock the thread already holds a shared lock
on the table being that should be created.
The solution is to make the prepare phase take a shared
metadata lock when preparing a CREATE TABLE statement. The
execution of the statement will still acquire a exclusive
lock, but won't cause any problem as it issues a implicit
commit.
After some discussions with stakeholders it has been decided that
metadata locks acquired during a PREPARE statement must be released
once the statement is prepared even if it is prepared within a multi
statement transaction.
sql/sql_servers.cc:
Don't implicitly unlock locked tables. Issue a implicit commit
at the end and unlock tables.
sql/sql_table.cc:
Close table and release metadata locks after a admin operation.
sql/table.h:
The problem is that the prepare phase of the CREATE TABLE
statement takes a exclusive metadata lock lock and this can
cause a self-deadlock the thread already holds a shared lock
on the table being that should be created.
The solution is to make the prepare phase take a shared
metadata lock when preparing a CREATE TABLE statement. The
execution of the statement will still acquire a exclusive
lock, but won't cause any problem as it issues a implicit
commit.
sql/transaction.cc:
Release metadata locks after the implicitly committed due
to a new transaction being started. Also, release metadata
locks acquired after a savepoint if the transaction is rolled
back to the save point.
The problem is that in some cases transaction-long metadata locks
could be released before the transaction was committed. This could
happen when a active transaction was ended by a "START TRANSACTION"
or "BEGIN" statement, in which case the metadata locks would be
released before the actual commit of the active transaction.
The solution is to defer the release of metadata locks to after the
transaction has been implicitly committed. No test case is provided
as the effort to provide one is too disproportional to the size of
the fix.
2009-12-05 00:02:48 +01:00
|
|
|
|
2020-01-28 22:23:51 +01:00
|
|
|
#ifdef TO_BE_DELETED
|
2006-02-24 16:19:55 +01:00
|
|
|
int injector::transaction::use_table(server_id_type sid, table tbl)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("injector::transaction::use_table");
|
|
|
|
|
|
|
|
int error;
|
|
|
|
|
2018-04-04 11:16:12 +02:00
|
|
|
if (unlikely((error= check_state(TABLE_STATE))))
|
2006-02-24 16:19:55 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
|
2012-10-23 12:46:29 +02:00
|
|
|
server_id_type save_id= m_thd->variables.server_id;
|
2006-02-24 16:19:55 +01:00
|
|
|
m_thd->set_server_id(sid);
|
2020-01-28 22:23:51 +01:00
|
|
|
DBUG_ASSERT(tbl.is_transactional() == tbl.get_table()->file->row_logging_has_trans);
|
|
|
|
error= m_thd->binlog_write_table_map(tbl.get_table(), 0);
|
2007-04-12 16:13:49 +02:00
|
|
|
m_thd->set_server_id(save_id);
|
2006-02-24 16:19:55 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
2020-01-28 22:23:51 +01:00
|
|
|
#endif
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
injector::transaction::binlog_pos injector::transaction::start_pos() const
|
|
|
|
{
|
|
|
|
return m_start_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
injector - member definitions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* This constructor is called below */
|
2023-02-07 12:57:20 +01:00
|
|
|
inline injector::injector() = default;
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
static injector *s_injector= 0;
|
|
|
|
injector *injector::instance()
|
|
|
|
{
|
|
|
|
if (s_injector == 0)
|
|
|
|
s_injector= new injector;
|
|
|
|
/* "There can be only one [instance]" */
|
|
|
|
return s_injector;
|
|
|
|
}
|
|
|
|
|
2006-06-19 14:31:22 +02:00
|
|
|
void injector::free_instance()
|
|
|
|
{
|
|
|
|
injector *inj = s_injector;
|
|
|
|
|
|
|
|
if (inj != 0)
|
|
|
|
{
|
|
|
|
s_injector= 0;
|
|
|
|
delete inj;
|
|
|
|
}
|
|
|
|
}
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
injector::transaction injector::new_trans(THD *thd)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("injector::new_trans(THD*)");
|
|
|
|
/*
|
|
|
|
Currently, there is no alternative to using 'mysql_bin_log' since that
|
|
|
|
is hardcoded into the way the handler is using the binary log.
|
|
|
|
*/
|
|
|
|
DBUG_RETURN(transaction(&mysql_bin_log, thd));
|
|
|
|
}
|
|
|
|
|
|
|
|
void injector::new_trans(THD *thd, injector::transaction *ptr)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("injector::new_trans(THD *, transaction *)");
|
|
|
|
/*
|
|
|
|
Currently, there is no alternative to using 'mysql_bin_log' since that
|
|
|
|
is hardcoded into the way the handler is using the binary log.
|
|
|
|
*/
|
|
|
|
transaction trans(&mysql_bin_log, thd);
|
|
|
|
ptr->swap(trans);
|
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
2007-03-29 20:31:09 +02:00
|
|
|
|
|
|
|
int injector::record_incident(THD *thd, Incident incident)
|
|
|
|
{
|
|
|
|
Incident_log_event ev(thd, incident);
|
2018-04-04 11:16:12 +02:00
|
|
|
int error;
|
|
|
|
if (unlikely((error= mysql_bin_log.write(&ev))))
|
2007-03-29 20:31:09 +02:00
|
|
|
return error;
|
2011-10-27 16:14:41 +02:00
|
|
|
return mysql_bin_log.rotate_and_purge(true);
|
2007-03-29 20:31:09 +02:00
|
|
|
}
|
|
|
|
|
2018-01-08 14:33:23 +01:00
|
|
|
int injector::record_incident(THD *thd, Incident incident,
|
|
|
|
const LEX_CSTRING *message)
|
2007-03-29 20:31:09 +02:00
|
|
|
{
|
|
|
|
Incident_log_event ev(thd, incident, message);
|
2018-04-04 11:16:12 +02:00
|
|
|
int error;
|
|
|
|
if (unlikely((error= mysql_bin_log.write(&ev))))
|
2007-03-29 20:31:09 +02:00
|
|
|
return error;
|
2011-10-27 16:14:41 +02:00
|
|
|
return mysql_bin_log.rotate_and_purge(true);
|
2007-03-29 20:31:09 +02:00
|
|
|
}
|