From: Jon Olav Hauglid Date: March 25 2011 3:13pm Subject: bzr commit into mysql-trunk branch (jon.hauglid:3327) Bug#11766752 List-Archive: http://lists.mysql.com/commits/133898 X-Bug: 11766752 Message-Id: <201103251513.p2PFDqvP019301@acsmt356.oracle.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2734782274505187357==" --===============2734782274505187357== MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline #At file:///export/home/x/mysql-trunk-bug11766752/ based on revid:georgi.kodinov@stripped 3327 Jon Olav Hauglid 2011-03-25 Bug #11766752 (former 59936) Multiple XA assertions - transactional statement fuzzer The problem was that the server for several statements did not check the state of the current XA transaction (if any) before trying to execute the statement. Specifically, you are not supposed to do anything other than XA PREPARE / XA COMMIT ONE PHASE when in IDLE state, or anything other than XA COMMIT / XA ROLLBACK in PREPARED state. The assertions triggered by the testcase posted in the bug report, was triggered by trying to access a table or rollback to a savepoint when the current XA transaction was in PREPARED state. This patch fixes the problem by reporting ER_XAER_RMFAIL error if 1) A statement is issued which requires a table to be opened when XA state is IDLE or PREPARED. 2) SAVEPOINT or ROLLBACK TO SAVEPOINT is executed with an active XA transaction. (Similar to what is already done for COMMIT/ROLLBACK) These are incompatible changes and must be reflected in the documentation. Test case added to xa.test. Also verified with the C testcase posted on the bug report. modified: mysql-test/r/xa.result mysql-test/t/xa.test sql/sql_base.cc sql/transaction.cc === modified file 'mysql-test/r/xa.result' --- a/mysql-test/r/xa.result 2011-02-14 13:16:31 +0000 +++ b/mysql-test/r/xa.result 2011-03-25 15:13:41 +0000 @@ -166,3 +166,35 @@ ERROR XA102: XA_RBDEADLOCK: Transaction XA END 'b'; XA ROLLBACK 'b'; DROP TABLE t1; +# +# Bug#11766752 59936: multiple xa assertions - transactional +# statement fuzzer +# +CREATE TABLE t1 (a INT) engine=InnoDB; +XA START 'a'; +INSERT INTO t1 VALUES (1); +SAVEPOINT savep; +ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the ACTIVE state +XA END 'a'; +SELECT * FROM t1; +ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the IDLE state +INSERT INTO t1 VALUES (2); +ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the IDLE state +SAVEPOINT savep; +ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the IDLE state +SET @a=(SELECT * FROM t1); +ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the IDLE state +XA PREPARE 'a'; +SELECT * FROM t1; +ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state +INSERT INTO t1 VALUES (2); +ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state +SAVEPOINT savep; +ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state +SET @a=(SELECT * FROM t1); +ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state +XA COMMIT 'a'; +SELECT * FROM t1; +a +1 +DROP TABLE t1; === modified file 'mysql-test/t/xa.test' --- a/mysql-test/t/xa.test 2011-02-14 13:16:31 +0000 +++ b/mysql-test/t/xa.test 2011-03-25 15:13:41 +0000 @@ -287,6 +287,43 @@ DROP TABLE t1; disconnect con1; +--echo # +--echo # Bug#11766752 59936: multiple xa assertions - transactional +--echo # statement fuzzer +--echo # + +CREATE TABLE t1 (a INT) engine=InnoDB; +XA START 'a'; +INSERT INTO t1 VALUES (1); + +--error ER_XAER_RMFAIL +SAVEPOINT savep; + +XA END 'a'; +--error ER_XAER_RMFAIL +SELECT * FROM t1; +--error ER_XAER_RMFAIL +INSERT INTO t1 VALUES (2); +--error ER_XAER_RMFAIL +SAVEPOINT savep; +--error ER_XAER_RMFAIL +SET @a=(SELECT * FROM t1); + +XA PREPARE 'a'; +--error ER_XAER_RMFAIL +SELECT * FROM t1; # used to cause InnoDB assert +--error ER_XAER_RMFAIL +INSERT INTO t1 VALUES (2); # used to cause InnoDB assert +--error ER_XAER_RMFAIL +SAVEPOINT savep; +--error ER_XAER_RMFAIL +SET @a=(SELECT * FROM t1); # used to cause InnoDB assert + +XA COMMIT 'a'; +SELECT * FROM t1; +DROP TABLE t1; + + # Wait till all disconnects are completed --source include/wait_until_count_sessions.inc === modified file 'sql/sql_base.cc' --- a/sql/sql_base.cc 2011-03-17 17:39:31 +0000 +++ b/sql/sql_base.cc 2011-03-25 15:13:41 +0000 @@ -4771,6 +4771,14 @@ bool open_tables(THD *thd, TABLE_LIST ** bool has_prelocking_list; DBUG_ENTER("open_tables"); + /* Accessing data in XA_IDLE or XA_PREPARED is not allowed. */ + enum xa_states xa_state= thd->transaction.xid_state.xa_state; + if (*start && (xa_state == XA_IDLE || xa_state == XA_PREPARED)) + { + my_error(ER_XAER_RMFAIL, MYF(0), xa_state_names[xa_state]); + DBUG_RETURN(true); + } + /* temporary mem_root for new .frm parsing. TODO: variables for size === modified file 'sql/transaction.cc' --- a/sql/transaction.cc 2011-03-22 11:44:40 +0000 +++ b/sql/transaction.cc 2011-03-25 15:13:41 +0000 @@ -358,6 +358,13 @@ bool trans_savepoint(THD *thd, LEX_STRIN !opt_using_transactions) DBUG_RETURN(FALSE); + enum xa_states xa_state= thd->transaction.xid_state.xa_state; + if (xa_state != XA_NOTR) + { + my_error(ER_XAER_RMFAIL, MYF(0), xa_state_names[xa_state]); + DBUG_RETURN(TRUE); + } + sv= find_savepoint(thd, name); if (*sv) /* old savepoint of the same name exists */ @@ -431,6 +438,13 @@ bool trans_rollback_to_savepoint(THD *th DBUG_RETURN(TRUE); } + enum xa_states xa_state= thd->transaction.xid_state.xa_state; + if (xa_state != XA_NOTR) + { + my_error(ER_XAER_RMFAIL, MYF(0), xa_state_names[xa_state]); + DBUG_RETURN(TRUE); + } + if (ha_rollback_to_savepoint(thd, sv)) res= TRUE; else if (((thd->variables.option_bits & OPTION_KEEP_LOG) || --===============2734782274505187357== MIME-Version: 1.0 Content-Type: text/bzr-bundle; charset="us-ascii"; name="bzr/jon.hauglid@stripped" Content-Transfer-Encoding: 7bit Content-Disposition: inline # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: jon.hauglid@stripped # target_branch: file:///export/home/x/mysql-trunk-bug11766752/ # testament_sha1: 3fc33575489e891e726ab85b47db058629e496eb # timestamp: 2011-03-25 16:13:45 +0100 # base_revision_id: georgi.kodinov@stripped\ # lw2g411ffimrgmtt # # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWTZEKfYABXnfgEEQeff//3// 32q////+YAvPvD7ud7td7YAAevb2XSWjzjoBRo3bTWtm66eEkpPJMhPU9U9oTwpqfkU2p6npHqek NGjaCD01A00PUNBKJJMaep6o9Gmgj1PU00Ymg0YJiZA0ADQAOYTQGgNGjCNBiNMTJiaDCNAyAZMB IiCSp7U8xVP1PU0aTwjTKH6gnlBiMjR6mE0yGmgEUhAmTUaaExHqDRoDTQAyZA000ABkBJITJoAT QJgRk0EaTKeo0BkAaBoGEtK0wMqu9MRSnbJB3PKMVXDkLyZffq+vbFuGLq/y27b1khFZJl4Z26XR e+jPQ5zBj9mrFDdb6e1/i+yubJH58xpMpkiAZA7ChtuVvykE6Z0fKc74HvYavnviY4W578R7p2yk KosthCzQUgTYoMgqftfp+v0KIjs+gW/tOx/EVN1xFv6Wicu+H7hwA222xsN73oxp1u3EPu9uD5pv w0UO14Try7CxNSrnRHNwGQd3Po4ivjDUyENFQn82bQ1+0YDkeuyp0cGwJmBP36UjRYchx76FQrml m34KyTsQW0DtalbRhGdHG7ubPE/d1qgwujQVtqef95JEKFBzJHG2H30ma+ckEWDFsPlTWtCCE1a/ bVjByBqinjJA76I7CXsD3UjNxmzsy6QSgiBryqi2AtV50aW2xm2kSfZSka6nIL2BAxaC3VpAaQSJ SEIFJFlOfow1VeiBqwwoCnWk4lv7ybLpGR3UHAyiHd9xZ1EmiUTI5vP5uTh0YNdBynoGjj1hjwc7 7BVYIx+9sbZ+TO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 oIOmKxCSJM96hpNI0rC08isR8CbpoqJqi5ea+J81LQTpGYqMIiBEoJSHDEK4whhgHeXLe7ENKrLR JZzLc/ClEO0mSEILHE0zIFaJTIARAjLiPXtn03dgZKLHIFE7i9HcguJ0JzGHR/RJLX/rQVaXGkmC w0wF6vFoIXLETC1+QENKdiYLQemWAKRp6e7oULIzY06hFoqubAwmgL42FhoUguJHApHE36C41GWo +R135Acbi9GQkzdOCRKTtxNhRjYwRKmmxUZ8xUpINbddbRRLLlrTrWsNOYxENR1MiNU34IXobSwA yrHMwNMhgoTN5Z7aw6RZgnNYhSdwhVyshHJhrS1binsXK17IcrrdVSVQ5dmNAQxScHtkLV3I+IfF maIyG5KRIzGZYvzSA+2mhiEJCsaCGTQzmorOVFeBdl6YLiLjhS4jKlYINFopFwR37yFeEBzUgEij JANTF1xisxc9SoitBNrjCwmIbIckjFi80HsUvbDIa5IewhwVJ1FIiGRKVPcCxcDcytIf6qPGCcO3 mFlU1ZxEuagrjv5/bEYbWAPPXgVHvpX1YGK220FbxloUXpHuOpUo4mDrYNFwsv0bs1rO3R2is272 QMo84MG6Vl6kWQObhmHck3imX4phXJFOPE7ElsIpGmXFZ3vIriP0nMoNhfJUnsQWkxDam18i3yOB tBZwLNavX3MH+LuSKcKEgbIhT7A= --===============2734782274505187357==--