From 4afb7365764b7a0e6a4ea4fa7022c8141663059a Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Wed, 16 Mar 2005 08:42:06 +0100 Subject: [PATCH] sql/handler.cc smarter xid-to-str routiine fixed assert crash in XA RECOVER sql/sql_parse.cc XA COMMIT/ROLLBACK did not send_ok in some cases --- sql/handler.cc | 26 ++++++++++++++++++++------ sql/sql_parse.cc | 8 ++++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index f33f987ef77..67a69201e3d 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -762,6 +762,14 @@ static char* xid_to_str(char *buf, XID *xid) for (i=0; i < xid->gtrid_length+xid->bqual_length; i++) { uchar c=(uchar)xid->data[i]; + bool is_next_dig; + if (i < XIDDATASIZE) + { + char ch=xid->data[i+1]; + is_next_dig=(c >= '0' && c <='9'); + } + else + is_next_dig=FALSE; if (i == xid->gtrid_length) { *s++='\''; @@ -774,9 +782,11 @@ static char* xid_to_str(char *buf, XID *xid) if (c < 32 || c > 126) { *s++='\\'; - *s++='x'; - *s++=_dig_vec_lower[c >> 4]; - *s++=_dig_vec_lower[c & 15]; + if (c > 077 || is_next_dig) + *s++=_dig_vec_lower[c >> 6]; + if (c > 007 || is_next_dig) + *s++=_dig_vec_lower[(c >> 3) & 7]; + *s++=_dig_vec_lower[c & 7]; } else { @@ -862,6 +872,10 @@ int ha_recover(HASH *commit_list) my_xid x=list[i].get_my_xid(); if (!x) // not "mine" - that is generated by external TM { +#ifndef DBUG_OFF + char buf[XIDDATASIZE*4+6]; // see xid_to_str + sql_print_information("ignore xid %s", xid_to_str(buf, list+i)); +#endif found_foreign_xids++; continue; } @@ -962,9 +976,9 @@ bool mysql_xa_recover(THD *thd) if (xid->get_my_xid()) continue; // skip "our" xids protocol->prepare_for_resend(); - protocol->store_long((longlong)xid->formatID); - protocol->store_long((longlong)xid->gtrid_length); - protocol->store_long((longlong)xid->bqual_length); + protocol->store_longlong((longlong)xid->formatID, FALSE); + protocol->store_longlong((longlong)xid->gtrid_length, FALSE); + protocol->store_longlong((longlong)xid->bqual_length, FALSE); protocol->store(xid->data, xid->gtrid_length+xid->bqual_length, &my_charset_bin); if (protocol->write()) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index d5ed8c8efb0..2e3b3d5ff0d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4382,6 +4382,8 @@ unsent_create_error: { if (!(res= !ha_commit_or_rollback_by_xid(&thd->lex->ident, 1))) my_error(ER_XAER_NOTA, MYF(0)); + else + send_ok(thd); break; } if (thd->transaction.xa_state == XA_IDLE && thd->lex->xa_opt == XA_ONE_PHASE) @@ -4390,9 +4392,7 @@ unsent_create_error: if ((r= ha_commit(thd))) my_error(r == 1 ? ER_XA_RBROLLBACK : ER_XAER_RMERR, MYF(0)); else - { send_ok(thd); - } } else if (thd->transaction.xa_state == XA_PREPARED && thd->lex->xa_opt == XA_NONE) @@ -4400,9 +4400,7 @@ unsent_create_error: if (ha_commit_one_phase(thd, 1)) my_error(ER_XAER_RMERR, MYF(0)); else - { send_ok(thd); - } } else { @@ -4419,6 +4417,8 @@ unsent_create_error: { if (!(res= !ha_commit_or_rollback_by_xid(&thd->lex->ident, 0))) my_error(ER_XAER_NOTA, MYF(0)); + else + send_ok(thd); break; } if (thd->transaction.xa_state != XA_IDLE &&