From 5d506d6b6255589dd4c28958ee03be59c690f4cf Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Jun 2006 20:55:21 +0200 Subject: [PATCH 1/2] Bug #19202 Incorrect errorhandling in select count(*) wrt temporary error --- sql/ha_ndbcluster.cc | 89 ++++++++++++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 27 deletions(-) diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index ffd5932a5c1..11fdd33fad9 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -270,6 +270,7 @@ void ha_ndbcluster::records_update() { Ndb *ndb= get_ndb(); Uint64 rows; + ndb->setDatabaseName(m_dbname); if(ndb_get_table_statistics(ndb, m_tabname, &rows, 0) == 0){ info->records= rows; } @@ -2876,6 +2877,7 @@ void ha_ndbcluster::info(uint flag) DBUG_VOID_RETURN; Ndb *ndb= get_ndb(); Uint64 rows= 100; + ndb->setDatabaseName(m_dbname); if (current_thd->variables.ndb_use_exact_count) ndb_get_table_statistics(ndb, m_tabname, &rows, 0); records= rows; @@ -5228,34 +5230,53 @@ ndb_get_table_statistics(Ndb* ndb, const char * table, { DBUG_ENTER("ndb_get_table_statistics"); DBUG_PRINT("enter", ("table: %s", table)); - NdbConnection* pTrans= ndb->startTransaction(); - do + NdbConnection* pTrans; + NdbError error; + int retries= 10; + int retry_sleep= 30 * 1000; /* 30 milliseconds */ + + do { - if (pTrans == NULL) - break; - - NdbScanOperation* pOp= pTrans->getNdbScanOperation(table); - if (pOp == NULL) - break; - - NdbResultSet* rs= pOp->readTuples(NdbOperation::LM_CommittedRead); - if (rs == 0) - break; - - int check= pOp->interpret_exit_last_row(); - if (check == -1) - break; - Uint64 rows, commits; + Uint64 sum_rows= 0; + Uint64 sum_commits= 0; + NdbScanOperation*pOp; + NdbResultSet *rs; + int check; + + if ((pTrans= ndb->startTransaction()) == NULL) + { + error= ndb->getNdbError(); + goto retry; + } + + if ((pOp= pTrans->getNdbScanOperation(table)) == NULL) + { + error= pTrans->getNdbError(); + goto retry; + } + + if ((rs= pOp->readTuples(NdbOperation::LM_CommittedRead)) == 0) + { + error= pOp->getNdbError(); + goto retry; + } + + if (pOp->interpret_exit_last_row() == -1) + { + error= pOp->getNdbError(); + goto retry; + } + pOp->getValue(NdbDictionary::Column::ROW_COUNT, (char*)&rows); pOp->getValue(NdbDictionary::Column::COMMIT_COUNT, (char*)&commits); - check= pTrans->execute(NoCommit, AbortOnError, TRUE); - if (check == -1) - break; + if (pTrans->execute(NoCommit, AbortOnError, TRUE) == -1) + { + error= pTrans->getNdbError(); + goto retry; + } - Uint64 sum_rows= 0; - Uint64 sum_commits= 0; while((check= rs->nextResult(TRUE, TRUE)) == 0) { sum_rows+= rows; @@ -5263,7 +5284,10 @@ ndb_get_table_statistics(Ndb* ndb, const char * table, } if (check == -1) - break; + { + error= pOp->getNdbError(); + goto retry; + } rs->close(TRUE); @@ -5274,11 +5298,22 @@ ndb_get_table_statistics(Ndb* ndb, const char * table, * commit_count= sum_commits; DBUG_PRINT("exit", ("records: %u commits: %u", sum_rows, sum_commits)); DBUG_RETURN(0); - } while(0); - ndb->closeTransaction(pTrans); - DBUG_PRINT("exit", ("failed")); - DBUG_RETURN(-1); +retry: + if (pTrans) + { + ndb->closeTransaction(pTrans); + pTrans= NULL; + } + if (error.status == NdbError::TemporaryError && retries--) + { + my_sleep(retry_sleep); + continue; + } + break; + } while(1); + DBUG_PRINT("exit", ("failed, error %u(%s)", error.code, error.message)); + ERR_RETURN(error); } /* From 868fee4dde4d73c2cd999f8a2ffc915f040e9e0b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 10 Jul 2006 00:26:26 +0300 Subject: [PATCH 2/2] BUG#20919 temp tables closing fails when binlog is off closing temp tables through end_thread had a flaw in binlog-off branch of close_temporary_tables where next table to close was reset via table->next for (table= thd->temporary_tables; table; table= table->next) which was wrong since the current table instance got destoyed at close_temporary(table, 1); The fix adapts binlog-on branch method to engage the loop's internal 'next' variable which holds table->next prior table's destoying. sql/sql_base.cc: no-binlog branch is fixed: scanning across temporary_tables must be careful to save next table since the current is being destroyed inside of close_temporary. binlog-is-open case is ok. --- sql/sql_base.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 98e4346eafc..0a9529d6067 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -496,11 +496,13 @@ void close_temporary_tables(THD *thd) TABLE *table; if (!thd->temporary_tables) return; - + if (!mysql_bin_log.is_open()) { - for (table= thd->temporary_tables; table; table= table->next) + TABLE *next; + for (table= thd->temporary_tables; table; table= next) { + next= table->next; close_temporary(table, 1); } thd->temporary_tables= 0; @@ -518,7 +520,7 @@ void close_temporary_tables(THD *thd) String s_query= String(buf, sizeof(buf), system_charset_info); bool found_user_tables= false; LINT_INIT(next); - + /* insertion sort of temp tables by pseudo_thread_id to build ordered list of sublists of equal pseudo_thread_id