From 22454390c0ce1c3f90059811548a71ee18cac4f3 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Fri, 5 Jun 2009 15:05:26 +0300 Subject: [PATCH 1/7] Bug #45286: compilation warnings on mysql-5.0-bugteam on MacOSX Fixed the 5.0-bugteam MacOSX warnings. client/mysqldump.c: Bug #45286: typecasts cmd-line-utils/readline/bind.c: Bug #45286: use variable of right type cmd-line-utils/readline/display.c: Bug #45286: use variable of right type dbug/user.r: Bug #45286: no warnings in generating man pages strings/ctype.c: Bug #45286: typecasts --- client/mysqldump.c | 4 ++-- cmd-line-utils/readline/bind.c | 4 +++- cmd-line-utils/readline/display.c | 2 +- dbug/user.r | 1 + strings/ctype.c | 5 ++++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index a9d2788de05..2fd69a3d8c6 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -3122,7 +3122,7 @@ static my_bool dump_all_views_in_db(char *database) for (numrows= 0 ; (table= getTableName(1)); ) { char *end= strmov(afterdot, table); - if (include_table((uchar*) hash_key,end - hash_key)) + if (include_table((byte*) hash_key,end - hash_key)) { numrows++; dynstr_append_checked(&query, quote_name(table, table_buff, 1)); @@ -3143,7 +3143,7 @@ static my_bool dump_all_views_in_db(char *database) while ((table= getTableName(0))) { char *end= strmov(afterdot, table); - if (include_table((uchar*) hash_key, end - hash_key)) + if (include_table((byte*) hash_key, end - hash_key)) get_view_structure(table, database); } if (opt_xml) diff --git a/cmd-line-utils/readline/bind.c b/cmd-line-utils/readline/bind.c index baed1dfad49..9d0a803cc6c 100644 --- a/cmd-line-utils/readline/bind.c +++ b/cmd-line-utils/readline/bind.c @@ -699,8 +699,10 @@ rl_function_of_keyseq (keyseq, map, type) for (i = 0; keyseq && keyseq[i]; i++) { - unsigned char ic = keyseq[i]; + unsigned char uc = keyseq[i]; + int ic; + ic= uc; if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii) { if (map[ESC].type == ISKMAP) diff --git a/cmd-line-utils/readline/display.c b/cmd-line-utils/readline/display.c index 6f63faa9738..54c56954f43 100644 --- a/cmd-line-utils/readline/display.c +++ b/cmd-line-utils/readline/display.c @@ -1888,7 +1888,7 @@ rl_character_len (c, pos) uc = (unsigned char)c; - if (META_CHAR (uc)) + if (META_CHAR (c)) return ((_rl_output_meta_chars == 0) ? 4 : 1); if (uc == '\t') diff --git a/dbug/user.r b/dbug/user.r index 19de840d0ad..ef67ef7a7cf 100644 --- a/dbug/user.r +++ b/dbug/user.r @@ -32,6 +32,7 @@ .\" === Set line length .\".ll 6.5i .TL +.warn 0 D B U G .P 0 C Program Debugging Package diff --git a/strings/ctype.c b/strings/ctype.c index 548005f8463..8902cf958a0 100644 --- a/strings/ctype.c +++ b/strings/ctype.c @@ -327,7 +327,10 @@ my_string_repertoire(CHARSET_INFO *cs, const char *str, ulong length) { my_wc_t wc; int chlen; - for (; (chlen= cs->cset->mb_wc(cs, &wc, str, strend)) > 0; str+= chlen) + for (; (chlen= cs->cset->mb_wc(cs, &wc, + (const unsigned char *) str, + (const unsigned char *) strend)) > 0; + str+= chlen) { if (wc > 0x7F) return MY_REPERTOIRE_UNICODE30; From 898443572f721803f46855b127bb3d40c2345ecb Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Fri, 5 Jun 2009 16:44:38 +0300 Subject: [PATCH 2/7] Bug #45286: compilation warnings on mysql-5.0-bugteam on MacOSX Merged the 5.0 fix to 5.1 and fixed the 5.1 specific warnings. --- client/mysqldump.c | 4 ++-- include/my_sys.h | 2 +- storage/myisammrg/myrg_create.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index f7b894803bd..6b2c2a06834 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -4110,7 +4110,7 @@ static my_bool dump_all_views_in_db(char *database) for (numrows= 0 ; (table= getTableName(1)); ) { char *end= strmov(afterdot, table); - if (include_table((byte*) hash_key,end - hash_key)) + if (include_table((uchar*) hash_key,end - hash_key)) { numrows++; dynstr_append_checked(&query, quote_name(table, table_buff, 1)); @@ -4131,7 +4131,7 @@ static my_bool dump_all_views_in_db(char *database) while ((table= getTableName(0))) { char *end= strmov(afterdot, table); - if (include_table((byte*) hash_key, end - hash_key)) + if (include_table((uchar*) hash_key, end - hash_key)) get_view_structure(table, database); } if (opt_xml) diff --git a/include/my_sys.h b/include/my_sys.h index 01804cd089f..263b567684d 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -511,7 +511,7 @@ typedef int (*qsort2_cmp)(const void *, const void *, const void *); ((info)->write_pos + (Count) <=(info)->write_end ?\ (memcpy((info)->write_pos, (Buffer), (size_t)(Count)),\ ((info)->write_pos+=(Count)),0) : \ - (*(info)->write_function)((info),(Buffer),(Count))) + (*(info)->write_function)((info),(uchar *)(Buffer),(Count))) #define my_b_get(info) \ ((info)->read_pos != (info)->read_end ?\ diff --git a/storage/myisammrg/myrg_create.c b/storage/myisammrg/myrg_create.c index df81b730bfd..eaed470daec 100644 --- a/storage/myisammrg/myrg_create.c +++ b/storage/myisammrg/myrg_create.c @@ -46,7 +46,7 @@ int myrg_create(const char *name, const char **table_names, fn_same(buff,name,4); *(end=strend(buff))='\n'; end[1]=0; - if (my_write(file,(char*) buff,(uint) (end-buff+1), + if (my_write(file,(uchar*) buff,(uint) (end-buff+1), MYF(MY_WME | MY_NABP))) goto err; } From 9c7d7d4ea22e0f80101ef2d6dfa335f8d5d8ad46 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Fri, 5 Jun 2009 17:59:23 +0300 Subject: [PATCH 3/7] Bug #43532 : backport of the 5.1 code to 5.0 mysqltest --- client/mysqltest.c | 101 ++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 47 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 2f19fad9ea9..0bde230cfe2 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1340,23 +1340,25 @@ static int run_tool(const char *tool_path, DYNAMIC_STRING *ds_res, ...) not present. */ -int diff_check() +int diff_check(const char *diff_name) { - char buf[512]= {0}; - FILE *res_file; - const char *cmd = "diff -v"; - int have_diff = 0; + char buf[512]= {0}; + FILE *res_file; + char cmd[128]; + my_snprintf (cmd, sizeof(cmd), "%s -v", diff_name); + int have_diff = 0; if (!(res_file= popen(cmd, "r"))) die("popen(\"%s\", \"r\") failed", cmd); -/* if diff is not present, nothing will be in stdout to increment have_diff */ + /* if diff is not present, nothing will be in + * stdout to increment have_diff */ if (fgets(buf, sizeof(buf), res_file)) { have_diff += 1; } - pclose(res_file); - return have_diff; + pclose(res_file); + return have_diff; } /* @@ -1377,28 +1379,33 @@ void show_diff(DYNAMIC_STRING* ds, { DYNAMIC_STRING ds_tmp; - int have_diff = 0; + const char *diff_name = 0; if (init_dynamic_string(&ds_tmp, "", 256, 256)) die("Out of memory"); - + /* determine if we have diff on Windows - needs special processing due to return values - on that OS - This test is only done on Windows since it's only needed there - in order to correctly detect non-availibility of 'diff', and - the way it's implemented does not work with default 'diff' on Solaris. - */ + needs special processing due to return values + on that OS + This test is only done on Windows since it's only needed there + in order to correctly detect non-availibility of 'diff', and + the way it's implemented does not work with default 'diff' on Solaris. + */ #ifdef __WIN__ - have_diff = diff_check(); + if (diff_check("diff")) + diff_name = "diff"; + else if (diff_check("mtrdiff")) + diff_name = "mtrdiff"; + else + diff_name = 0; #else - have_diff = 1; + diff_name = "diff"; // Otherwise always assume it's called diff #endif - if (have_diff) + if (diff_name) { /* First try with unified diff */ - if (run_tool("diff", + if (run_tool(diff_name, &ds_tmp, /* Get output from diff in ds_tmp */ "-u", filename1, @@ -1409,7 +1416,7 @@ void show_diff(DYNAMIC_STRING* ds, dynstr_set(&ds_tmp, ""); /* Fallback to context diff with "diff -c" */ - if (run_tool("diff", + if (run_tool(diff_name, &ds_tmp, /* Get output from diff in ds_tmp */ "-c", filename1, @@ -1417,42 +1424,42 @@ void show_diff(DYNAMIC_STRING* ds, "2>&1", NULL) > 1) /* Most "diff" tools return >1 if error */ { - have_diff= 0; - } + diff_name= 0; + } } } -if (!(have_diff)) + if (!(diff_name)) { /* Fallback to dump both files to result file and inform about installing "diff" - */ - - dynstr_set(&ds_tmp, ""); + */ - dynstr_append(&ds_tmp, -"\n" -"The two files differ but it was not possible to execute 'diff' in\n" -"order to show only the difference, tried both 'diff -u' or 'diff -c'.\n" -"Instead the whole content of the two files was shown for you to diff manually. ;)\n\n" -"To get a better report you should install 'diff' on your system, which you\n" -"for example can get from http://www.gnu.org/software/diffutils/diffutils.html\n" + dynstr_set(&ds_tmp, ""); + + dynstr_append(&ds_tmp, + "\n" + "The two files differ but it was not possible to execute 'diff' in\n" + "order to show only the difference, tried both 'diff -u' or 'diff -c'.\n" + "Instead the whole content of the two files was shown for you to diff manually. ;)\n\n" + "To get a better report you should install 'diff' on your system, which you\n" + "for example can get from http://www.gnu.org/software/diffutils/diffutils.html\n" #ifdef __WIN__ -"or http://gnuwin32.sourceforge.net/packages/diffutils.htm\n" + "or http://gnuwin32.sourceforge.net/packages/diffutils.htm\n" #endif -"\n"); + "\n"); - dynstr_append(&ds_tmp, " --- "); - dynstr_append(&ds_tmp, filename1); - dynstr_append(&ds_tmp, " >>>\n"); - cat_file(&ds_tmp, filename1); - dynstr_append(&ds_tmp, "<<<\n --- "); - dynstr_append(&ds_tmp, filename1); - dynstr_append(&ds_tmp, " >>>\n"); - cat_file(&ds_tmp, filename2); - dynstr_append(&ds_tmp, "<<<<\n"); - } + dynstr_append(&ds_tmp, " --- "); + dynstr_append(&ds_tmp, filename1); + dynstr_append(&ds_tmp, " >>>\n"); + cat_file(&ds_tmp, filename1); + dynstr_append(&ds_tmp, "<<<\n --- "); + dynstr_append(&ds_tmp, filename1); + dynstr_append(&ds_tmp, " >>>\n"); + cat_file(&ds_tmp, filename2); + dynstr_append(&ds_tmp, "<<<<\n"); + } if (ds) { @@ -1464,7 +1471,7 @@ if (!(have_diff)) /* Print diff directly to stdout */ fprintf(stderr, "%s\n", ds_tmp.str); } - + dynstr_free(&ds_tmp); } From dd570869f483e5ce6dcd45f3b77e69df585c814a Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Fri, 5 Jun 2009 18:14:56 +0300 Subject: [PATCH 4/7] Bug #45286: compilation warnings on mysql-5.0-bugteam on MacOSX Implemented a way to circumvent the always true comparison by having nested macros (as suggested on review). --- cmd-line-utils/readline/chardefs.h | 3 ++- cmd-line-utils/readline/display.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd-line-utils/readline/chardefs.h b/cmd-line-utils/readline/chardefs.h index def3a111bd3..36fe7fdd7ac 100644 --- a/cmd-line-utils/readline/chardefs.h +++ b/cmd-line-utils/readline/chardefs.h @@ -59,7 +59,8 @@ #define largest_char 255 /* Largest character value. */ #define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0)) -#define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char) +#define META_BYTE(c) ((c) > meta_character_threshold) +#define META_CHAR(c) (META_BYTE(c) && (c) <= largest_char) #define CTRL(c) ((c) & control_character_mask) #define META(c) ((c) | meta_character_bit) diff --git a/cmd-line-utils/readline/display.c b/cmd-line-utils/readline/display.c index 54c56954f43..842a586b76b 100644 --- a/cmd-line-utils/readline/display.c +++ b/cmd-line-utils/readline/display.c @@ -1888,7 +1888,7 @@ rl_character_len (c, pos) uc = (unsigned char)c; - if (META_CHAR (c)) + if (META_BYTE (uc)) return ((_rl_output_meta_chars == 0) ? 4 : 1); if (uc == '\t') From 07f33a21d7f2d5378e5ce419c6951c9b9c8eb2b9 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Fri, 5 Jun 2009 19:23:44 +0300 Subject: [PATCH 5/7] Addendum to Bug #45286 : implement reviewer's remarks. --- client/mysqldump.c | 4 ++-- cmd-line-utils/readline/bind.c | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 2fd69a3d8c6..fa6c21ed273 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -3122,7 +3122,7 @@ static my_bool dump_all_views_in_db(char *database) for (numrows= 0 ; (table= getTableName(1)); ) { char *end= strmov(afterdot, table); - if (include_table((byte*) hash_key,end - hash_key)) + if (include_table(hash_key,end - hash_key)) { numrows++; dynstr_append_checked(&query, quote_name(table, table_buff, 1)); @@ -3143,7 +3143,7 @@ static my_bool dump_all_views_in_db(char *database) while ((table= getTableName(0))) { char *end= strmov(afterdot, table); - if (include_table((byte*) hash_key, end - hash_key)) + if (include_table(hash_key, end - hash_key)) get_view_structure(table, database); } if (opt_xml) diff --git a/cmd-line-utils/readline/bind.c b/cmd-line-utils/readline/bind.c index 9d0a803cc6c..fc7bebfd813 100644 --- a/cmd-line-utils/readline/bind.c +++ b/cmd-line-utils/readline/bind.c @@ -699,11 +699,9 @@ rl_function_of_keyseq (keyseq, map, type) for (i = 0; keyseq && keyseq[i]; i++) { - unsigned char uc = keyseq[i]; - int ic; + unsigned char ic = keyseq[i]; - ic= uc; - if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii) + if (META_BYTE (ic) && _rl_convert_meta_chars_to_ascii) { if (map[ESC].type == ISKMAP) { From 46a4685cdb29ea885ddbec6d500b6c64180706e9 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Fri, 5 Jun 2009 13:55:09 -0300 Subject: [PATCH 6/7] The valgrind suppression file (valgrind.supp) must be added to a binary distribution of the server as the MTR valgrind option relies on it to silence unmeaningful warnings. mysql-test/Makefile.am: Install valgrind.supp as part of the test suite. Remove reference to inexistent directory. --- mysql-test/Makefile.am | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mysql-test/Makefile.am b/mysql-test/Makefile.am index 5e3582d5e16..7a56584190d 100644 --- a/mysql-test/Makefile.am +++ b/mysql-test/Makefile.am @@ -25,6 +25,7 @@ test_SCRIPTS = mtr \ mysql-stress-test.pl nobase_test_DATA = \ + valgrind.supp \ lib/v1/mysql-test-run.pl \ lib/v1/mtr_cases.pl \ lib/v1/mtr_io.pl \ @@ -41,7 +42,6 @@ nobase_test_DATA = \ lib/v1/mtr_im.pl \ lib/v1/mtr_process.pl \ lib/v1/mtr_unique.pl \ -\ lib/mtr_cases.pm \ lib/mtr_gcov.pl \ lib/mtr_gprof.pl \ @@ -69,9 +69,8 @@ nobase_test_DATA = \ SUBDIRS = lib/My/SafeProcess EXTRA_DIST = README \ - valgrind.supp \ $(test_SCRIPTS) \ - $(nobase_test_DATA) + $(nobase_test_DATA) # List of directories containing test + result files and the # related test data files that should be copied @@ -93,7 +92,7 @@ TEST_DIRS = t r include std_data std_data/parts collections \ suite/jp suite/jp/t suite/jp/r suite/jp/std_data suite/jp/include \ suite/manual/t suite/manual/r \ suite/ndb_team suite/ndb_team/t suite/ndb_team/r \ - suite/rpl suite/rpl/data suite/rpl/include suite/rpl/r \ + suite/rpl suite/rpl/include suite/rpl/r \ suite/rpl/t \ suite/stress/include suite/stress/t suite/stress/r \ suite/ndb suite/ndb/t suite/ndb/r \ From 12f91b1d8c45bb84ee5bc7ee4b0b455fbb0e2a90 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Fri, 5 Jun 2009 19:16:54 -0300 Subject: [PATCH 7/7] Bug#44672: Assertion failed: thd->transaction.xid_state.xid.is_null() The problem is that when a optimization of read-only transactions (bypass 2-phase commit) was implemented, it removed the code that reseted the XID once a transaction wasn't active anymore: sql/sql_parse.cc: - bzero(&thd->transaction.stmt, sizeof(thd->transaction.stmt)); - if (!thd->active_transaction()) - thd->transaction.xid_state.xid.null(); + thd->transaction.stmt.reset(); This mostly worked fine as the transaction commit and rollback functions (in handler.cc) reset the XID once the transaction is ended. But those functions wouldn't reset the XID in case of a empty transaction, leading to a assertion when a new starting a new XA transaction. The solution is to ensure that the XID state is reset when empty transactions are ended (by either commit or rollback). This is achieved by reorganizing the code so that the transaction cleanup routine is invoked whenever a transaction is ended. mysql-test/r/xa.result: Add test case result for Bug#44672 mysql-test/t/xa.test: Add test case for Bug#44672 sql/handler.cc: Invoke transaction cleanup function whenever a transaction is ended. Move XID state reset logic to the transaction cleanup function. sql/sql_class.h: Add XID state reset logic. --- mysql-test/r/xa.result | 6 ++++++ mysql-test/t/xa.test | 11 ++++++++++ sql/handler.cc | 48 ++++++++++++++++++++++++------------------ sql/sql_class.h | 8 +++++++ 4 files changed, 53 insertions(+), 20 deletions(-) diff --git a/mysql-test/r/xa.result b/mysql-test/r/xa.result index 592cf07522b..92f52b402ec 100644 --- a/mysql-test/r/xa.result +++ b/mysql-test/r/xa.result @@ -75,3 +75,9 @@ xa rollback 'a','c'; xa start 'a','c'; drop table t1; End of 5.0 tests +xa start 'a'; +xa end 'a'; +xa rollback 'a'; +xa start 'a'; +xa end 'a'; +xa rollback 'a'; diff --git a/mysql-test/t/xa.test b/mysql-test/t/xa.test index 04ecf518577..a0d5aa60641 100644 --- a/mysql-test/t/xa.test +++ b/mysql-test/t/xa.test @@ -124,6 +124,17 @@ drop table t1; --echo End of 5.0 tests +# +# Bug#44672: Assertion failed: thd->transaction.xid_state.xid.is_null() +# + +xa start 'a'; +xa end 'a'; +xa rollback 'a'; +xa start 'a'; +xa end 'a'; +xa rollback 'a'; + # Wait till all disconnects are completed --source include/wait_until_count_sessions.inc diff --git a/sql/handler.cc b/sql/handler.cc index d22ee220dc1..9246c04ce7d 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1073,6 +1073,13 @@ int ha_commit_trans(THD *thd, bool all) user, or an implicit commit issued by a DDL. */ THD_TRANS *trans= all ? &thd->transaction.all : &thd->transaction.stmt; + /* + "real" is a nick name for a transaction for which a commit will + make persistent changes. E.g. a 'stmt' transaction inside a 'all' + transation is not 'real': even though it's possible to commit it, + the changes are not durable as they might be rolled back if the + enclosing 'all' transaction is rolled back. + */ bool is_real_trans= all || thd->transaction.all.ha_list == 0; Ha_trx_info *ha_info= trans->ha_list; my_xid xid= thd->transaction.xid_state.xid.get_my_xid(); @@ -1184,16 +1191,9 @@ end: if (rw_trans) start_waiting_global_read_lock(thd); } - else if (all) - { - /* - A COMMIT of an empty transaction. There may be savepoints. - Destroy them. If the transaction is not empty - savepoints are cleared in ha_commit_one_phase() - or ha_rollback_trans(). - */ + /* Free resources and perform other cleanup even for 'empty' transactions. */ + else if (is_real_trans) thd->transaction.cleanup(); - } #endif /* USING_TRANSACTIONS */ DBUG_RETURN(error); } @@ -1206,6 +1206,13 @@ int ha_commit_one_phase(THD *thd, bool all) { int error=0; THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt; + /* + "real" is a nick name for a transaction for which a commit will + make persistent changes. E.g. a 'stmt' transaction inside a 'all' + transation is not 'real': even though it's possible to commit it, + the changes are not durable as they might be rolled back if the + enclosing 'all' transaction is rolled back. + */ bool is_real_trans=all || thd->transaction.all.ha_list == 0; Ha_trx_info *ha_info= trans->ha_list, *ha_info_next; DBUG_ENTER("ha_commit_one_phase"); @@ -1227,8 +1234,6 @@ int ha_commit_one_phase(THD *thd, bool all) } trans->ha_list= 0; trans->no_2pc=0; - if (is_real_trans) - thd->transaction.xid_state.xid.null(); if (all) { #ifdef HAVE_QUERY_CACHE @@ -1236,8 +1241,9 @@ int ha_commit_one_phase(THD *thd, bool all) query_cache.invalidate(thd->transaction.changed_tables); #endif thd->variables.tx_isolation=thd->session_tx_isolation; - thd->transaction.cleanup(); } + if (is_real_trans) + thd->transaction.cleanup(); } #endif /* USING_TRANSACTIONS */ DBUG_RETURN(error); @@ -1249,6 +1255,13 @@ int ha_rollback_trans(THD *thd, bool all) int error=0; THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt; Ha_trx_info *ha_info= trans->ha_list, *ha_info_next; + /* + "real" is a nick name for a transaction for which a commit will + make persistent changes. E.g. a 'stmt' transaction inside a 'all' + transation is not 'real': even though it's possible to commit it, + the changes are not durable as they might be rolled back if the + enclosing 'all' transaction is rolled back. + */ bool is_real_trans=all || thd->transaction.all.ha_list == 0; DBUG_ENTER("ha_rollback_trans"); @@ -1294,18 +1307,13 @@ int ha_rollback_trans(THD *thd, bool all) } trans->ha_list= 0; trans->no_2pc=0; - if (is_real_trans) - { - if (thd->transaction_rollback_request) - thd->transaction.xid_state.rm_error= thd->main_da.sql_errno(); - else - thd->transaction.xid_state.xid.null(); - } + if (is_real_trans && thd->transaction_rollback_request) + thd->transaction.xid_state.rm_error= thd->main_da.sql_errno(); if (all) thd->variables.tx_isolation=thd->session_tx_isolation; } /* Always cleanup. Even if there nht==0. There may be savepoints. */ - if (all) + if (is_real_trans) thd->transaction.cleanup(); #endif /* USING_TRANSACTIONS */ if (all) diff --git a/sql/sql_class.h b/sql/sql_class.h index f4d55917b48..ae7f2a51428 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1464,6 +1464,14 @@ public: { changed_tables= 0; savepoints= 0; + /* + If rm_error is raised, it means that this piece of a distributed + transaction has failed and must be rolled back. But the user must + rollback it explicitly, so don't start a new distributed XA until + then. + */ + if (!xid_state.rm_error) + xid_state.xid.null(); #ifdef USING_TRANSACTIONS free_root(&mem_root,MYF(MY_KEEP_PREALLOC)); #endif