From e6781590139d1b5a12556e8bf57eccca4b66062b Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 3 Jul 2007 14:12:27 +0200 Subject: [PATCH 1/8] ndb - bug#25901 handle undofile/logfile groups that were created while node was node storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp: Make sure that START_RECREQ is run on lgman/tsman even during initial node restart storage/ndb/src/kernel/blocks/lgman.cpp: Set state to LG_STARTING during node/system restart storage/ndb/src/kernel/blocks/lgman.hpp: add new state --- .../ndb/src/kernel/blocks/dblqh/DblqhMain.cpp | 22 +++++++++++-------- storage/ndb/src/kernel/blocks/lgman.cpp | 17 ++++++++++---- storage/ndb/src/kernel/blocks/lgman.hpp | 3 ++- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp b/storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp index e47fcf34471..e5adcf3f857 100644 --- a/storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp +++ b/storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp @@ -14215,15 +14215,6 @@ void Dblqh::execSTART_RECREQ(Signal* signal) * WE ALSO NEED TO SET CNEWEST_GCI TO ENSURE THAT LOG RECORDS ARE EXECUTED * WITH A PROPER GCI. *------------------------------------------------------------------------ */ - if(cstartType == NodeState::ST_INITIAL_NODE_RESTART){ - jam(); - cstartRecReq = 2; - StartRecConf * conf = (StartRecConf*)signal->getDataPtrSend(); - conf->startingNodeId = getOwnNodeId(); - sendSignal(cmasterDihBlockref, GSN_START_RECCONF, signal, - StartRecConf::SignalLength, JBB); - return; - }//if if (c_lcp_restoring_fragments.isEmpty()) { @@ -14276,6 +14267,19 @@ void Dblqh::execSTART_RECCONF(Signal* signal) jam(); csrExecUndoLogState = EULS_COMPLETED; + + if(cstartType == NodeState::ST_INITIAL_NODE_RESTART) + { + jam(); + cstartRecReq = 2; + + StartRecConf * conf = (StartRecConf*)signal->getDataPtrSend(); + conf->startingNodeId = getOwnNodeId(); + sendSignal(cmasterDihBlockref, GSN_START_RECCONF, signal, + StartRecConf::SignalLength, JBB); + return; + } + c_lcp_complete_fragments.first(fragptr); build_acc(signal, fragptr.i); return; diff --git a/storage/ndb/src/kernel/blocks/lgman.cpp b/storage/ndb/src/kernel/blocks/lgman.cpp index 25cdac89737..23738717580 100644 --- a/storage/ndb/src/kernel/blocks/lgman.cpp +++ b/storage/ndb/src/kernel/blocks/lgman.cpp @@ -346,6 +346,12 @@ Lgman::execCREATE_FILEGROUP_REQ(Signal* signal){ m_logfile_group_hash.add(ptr); m_logfile_group_list.add(ptr); + + if (getNodeState().getNodeRestartInProgress() || + getNodeState().getSystemRestartInProgress()) + { + ptr.p->m_state = Logfile_group::LG_STARTING; + } CreateFilegroupImplConf* conf= (CreateFilegroupImplConf*)signal->getDataPtr(); @@ -370,8 +376,6 @@ Lgman::execDROP_FILEGROUP_REQ(Signal* signal) { jamEntry(); - jamEntry(); - Uint32 errorCode = 0; DropFilegroupImplReq req = *(DropFilegroupImplReq*)signal->getDataPtr(); do @@ -717,7 +721,8 @@ Lgman::create_file_commit(Signal* signal, Uint32 senderData = ptr.p->m_create.m_senderData; bool first= false; - if(ptr.p->m_state == Undofile::FS_CREATING) + if(ptr.p->m_state == Undofile::FS_CREATING && + (lg_ptr.p->m_state & Logfile_group::LG_ONLINE)) { jam(); Local_undofile_list free(m_file_pool, lg_ptr.p->m_files); @@ -2082,13 +2087,17 @@ Lgman::execSTART_RECREQ(Signal* signal) void Lgman::find_log_head(Signal* signal, Ptr ptr) { + ndbrequire(ptr.p->m_state & + (Logfile_group::LG_STARTING | Logfile_group::LG_SORTING)); + if(ptr.p->m_meta_files.isEmpty() && ptr.p->m_files.isEmpty()) { jam(); /** * Logfile_group wo/ any files */ - + ptr.p->m_state &= ~(Uint32)Logfile_group::LG_STARTING; + ptr.p->m_state |= Logfile_group::LG_ONLINE; m_logfile_group_list.next(ptr); signal->theData[0] = LgmanContinueB::FIND_LOG_HEAD; signal->theData[1] = ptr.i; diff --git a/storage/ndb/src/kernel/blocks/lgman.hpp b/storage/ndb/src/kernel/blocks/lgman.hpp index b26c3219088..d2706818144 100644 --- a/storage/ndb/src/kernel/blocks/lgman.hpp +++ b/storage/ndb/src/kernel/blocks/lgman.hpp @@ -175,13 +175,14 @@ public: ,LG_SORTING = 0x002 // Sorting files ,LG_SEARCHING = 0x004 // Searching in last file ,LG_EXEC_THREAD = 0x008 // Execute thread is running - ,LG_READ_THREAD = 0x010 // Read thread is running + ,LG_READ_THREAD = 0x010 // Read thread is running ,LG_FORCE_SYNC_THREAD = 0x020 ,LG_SYNC_WAITERS_THREAD = 0x040 ,LG_CUT_LOG_THREAD = 0x080 ,LG_WAITERS_THREAD = 0x100 ,LG_FLUSH_THREAD = 0x200 ,LG_DROPPING = 0x400 + ,LG_STARTING = 0x800 }; static const Uint32 LG_THREAD_MASK = Logfile_group::LG_FORCE_SYNC_THREAD | From ac84ebf6847bb577b69d90032f11b00c1bb098af Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 3 Jul 2007 16:29:25 +0200 Subject: [PATCH 2/8] ndb - bug#28642 - Tablespace returning incorrect usage status make free 64 bit (as it represents free bytes, not free extents as originally designed) storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp: make free 64 bit (as it represents free bytes, not free extents as originally designed) --- storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp b/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp index 68ca4edb5d0..f2b3173beff 100644 --- a/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp +++ b/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp @@ -390,7 +390,7 @@ struct NdbFileImpl : public NdbDictObjectImpl { NdbFileImpl(NdbDictionary::Object::Type t); Uint64 m_size; - Uint32 m_free; + Uint64 m_free; BaseString m_path; BaseString m_filegroup_name; Uint32 m_filegroup_id; From a3715c9771451e87f3789c29c8a602e0482986ec Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 3 Jul 2007 16:56:35 +0200 Subject: [PATCH 3/8] ndb - bug#28720 - "Disk data meta information is not visible in mysqld but exists in ndbd" continue on unknown result (no contact) sql/ha_ndbcluster.cc: continue on unknown result (no contact) --- sql/ha_ndbcluster.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 7f94268f4f5..165d686abe8 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -10974,6 +10974,10 @@ static int ndbcluster_fill_files_table(handlerton *hton, { if (ndberr.classification == NdbError::SchemaError) continue; + + if (ndberr.classification == NdbError::UnknownResultError) + continue; + ERR_RETURN(ndberr); } NdbDictionary::Tablespace ts= dict->getTablespace(df.getTablespace()); From 5b14bc33bbed12a0b921fce109cdc81789f9f527 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 3 Jul 2007 17:22:57 +0200 Subject: [PATCH 4/8] ndb - bug#28720 fix also undo files --- sql/ha_ndbcluster.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 165d686abe8..818996f5fae 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -11057,6 +11057,8 @@ static int ndbcluster_fill_files_table(handlerton *hton, { if (ndberr.classification == NdbError::SchemaError) continue; + if (ndberr.classification == NdbError::UnknownResultError) + continue; ERR_RETURN(ndberr); } NdbDictionary::LogfileGroup lfg= From 1b84121688041f80d1fe63e7288842d7033d1cae Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jul 2007 20:16:42 +0200 Subject: [PATCH 5/8] backport compute hash --- storage/ndb/include/ndbapi/Ndb.hpp | 34 ++++++ storage/ndb/src/ndbapi/Ndb.cpp | 176 +++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+) diff --git a/storage/ndb/include/ndbapi/Ndb.hpp b/storage/ndb/include/ndbapi/Ndb.hpp index a6a3df92ddb..4d0219d1a3c 100644 --- a/storage/ndb/include/ndbapi/Ndb.hpp +++ b/storage/ndb/include/ndbapi/Ndb.hpp @@ -1280,6 +1280,16 @@ public: * @{ */ + /** + * Structure for passing in pointers to startTransaction + * + */ + struct Key_part_ptr + { + const void * ptr; + unsigned len; + }; + /** * Start a transaction * @@ -1300,6 +1310,30 @@ public: const char *keyData = 0, Uint32 keyLen = 0); + /** + * Compute hash value given table/keys + * + * @param hashvalueptr - OUT, is set to hashvalue if return value is 0 + * @param table Pointer to table object + * @param keyData Null-terminated array of pointers to keyParts that is + * part of distribution key. + * Length of resp. keyPart will be read from + * metadata and checked against passed value + * @param xfrmbuf Pointer to temporary buffer that will be used + * to calculate hashvalue + * @param xfrmbuflen Lengh of buffer + * + * @note if xfrmbuf is null (default) malloc/free will be made + * if xfrmbuf is not null but length is too short, method will fail + * + * @return 0 - ok - hashvalueptr is set + * else - fail, return error code + */ + static int computeHash(Uint32* hashvalueptr, + const NdbDictionary::Table*, + const struct Key_part_ptr * keyData, + void* xfrmbuf = 0, Uint32 xfrmbuflen = 0); + /** * Close a transaction. * diff --git a/storage/ndb/src/ndbapi/Ndb.cpp b/storage/ndb/src/ndbapi/Ndb.cpp index 9b8e4e86d30..bbeeed3ae70 100644 --- a/storage/ndb/src/ndbapi/Ndb.cpp +++ b/storage/ndb/src/ndbapi/Ndb.cpp @@ -37,6 +37,7 @@ Name: Ndb.cpp #include "API.hpp" #include #include +#include /**************************************************************************** void connect(); @@ -304,6 +305,181 @@ Return Value: Returns a pointer to a connection object. Return NULL otherwise. Remark: Start transaction. Synchronous. *****************************************************************************/ +int +Ndb::computeHash(Uint32 *retval, + const NdbDictionary::Table *table, + const struct Key_part_ptr * keyData, + void* buf, Uint32 bufLen) +{ + Uint32 j = 0; + Uint32 sumlen = 0; // Needed len + const NdbTableImpl* impl = &NdbTableImpl::getImpl(*table); + const NdbColumnImpl* const * cols = impl->m_columns.getBase(); + Uint32 len; + NdbTransaction* trans; + char* pos; + + Uint32 colcnt = impl->m_columns.size(); + Uint32 parts = impl->m_noOfDistributionKeys; + if (parts == 0) + { + parts = impl->m_noOfKeys; + } + + for (Uint32 i = 0; im_distributionKey) + { + // wl3717_todo + // char allowed now as dist key so this case should be tested + partcols[j++] = cols[i]; + } + } + + for (Uint32 i = 0; im_type, + keyData[i].ptr, + keyData[i].len, + lb, len))) + goto emalformedkey; + + if (unlikely(keyData[i].len < (lb + len))) + goto elentosmall; + + Uint32 maxlen = (partcols[i]->m_attrSize * partcols[i]->m_arraySize); + + if (unlikely(lb == 0 && keyData[i].len != maxlen)) + goto emalformedkey; + + if (partcols[i]->m_cs) + { + Uint32 xmul = partcols[i]->m_cs->strxfrm_multiply; + xmul = xmul ? xmul : 1; + len = xmul * (maxlen - lb); + } + + len = (lb + len + 3) & ~(Uint32)3; + sumlen += len; + + } + + if (buf) + { + UintPtr org = UintPtr(buf); + UintPtr use = (org + 7) & ~(UintPtr)7; + + buf = (void*)use; + bufLen -= (use - org); + + if (unlikely(sumlen > bufLen)) + goto ebuftosmall; + } + else + { + buf = malloc(sumlen); + if (unlikely(buf == 0)) + goto enomem; + bufLen = 0; + assert((UintPtr(buf) & 7) == 0); + } + + pos = (char*)buf; + for (Uint32 i = 0; im_type, + keyData[i].ptr, keyData[i].len, lb, len); + CHARSET_INFO* cs; + if ((cs = partcols[i]->m_cs)) + { + Uint32 xmul = cs->strxfrm_multiply; + if (xmul == 0) + xmul = 1; + /* + * Varchar end-spaces are ignored in comparisons. To get same hash + * we blank-pad to maximum length via strnxfrm. + */ + Uint32 maxlen = (partcols[i]->m_attrSize * partcols[i]->m_arraySize); + Uint32 dstLen = xmul * (maxlen - lb); + int n = NdbSqlUtil::strnxfrm_bug7284(cs, + (unsigned char*)pos, + dstLen, + ((unsigned char*)keyData[i].ptr)+lb, + len); + + if (unlikely(n == -1)) + goto emalformedstring; + + while ((n & 3) != 0) + { + pos[n++] = 0; + } + pos += n; + } + else + { + len += lb; + memcpy(pos, keyData[i].ptr, len); + while (len & 3) + { + * (pos + len++) = 0; + } + pos += len; + } + } + len = UintPtr(pos) - UintPtr(buf); + assert((len & 3) == 0); + + Uint32 values[4]; + md5_hash(values, (const Uint64*)buf, len >> 2); + + if (retval) + { + * retval = values[1]; + } + + if (bufLen == 0) + free(buf); + + return 0; + +enullptr: + return 4316; + +emissingnullptr: + return 4276; + +elentosmall: + return 4277; + +ebuftosmall: + return 4278; + +emalformedstring: + if (bufLen == 0) + free(buf); + + return 4279; + +emalformedkey: + return 4280; + +enomem: + return 4000; +} + NdbTransaction* Ndb::startTransaction(const NdbDictionary::Table *table, const char * keyData, Uint32 keyLen) From 7ebebf5e273056013a6c25ee474755000569f867 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jul 2007 22:39:55 +0200 Subject: [PATCH 6/8] ndb - bug#29354 - fix bug in bug fix, dont assert if 2 LCP's are being run during a node recovery --- ndb/src/kernel/blocks/dblqh/DblqhMain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp b/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp index 7dac07c28e9..1539b726c6a 100644 --- a/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp +++ b/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp @@ -11165,7 +11165,7 @@ void Dblqh::sendLCP_COMPLETE_REP(Signal* signal, Uint32 lcpId) sendEMPTY_LCP_CONF(signal, true); } - if (getNodeState().getNodeRestartInProgress()) + if (getNodeState().getNodeRestartInProgress() && cstartRecReq != 3) { jam(); ndbrequire(cstartRecReq == 2); From 4e825803bf2ed3ca28214978a6203d67646c4439 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Jul 2007 12:39:03 +0200 Subject: [PATCH 7/8] Bug #29570 original error lost in write_event on slave - make sure error gets propagated to thd->net by calling print_error - also print the full error message --- sql/log_event.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sql/log_event.cc b/sql/log_event.cc index 1241d0b02ed..6565278e6d3 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -6057,8 +6057,9 @@ int Rows_log_event::do_apply_event(RELAY_LOG_INFO const *rli) default: slave_print_msg(ERROR_LEVEL, rli, thd->net.last_errno, - "Error in %s event: row application failed", - get_type_str()); + "Error in %s event: row application failed. %s", + get_type_str(), + thd->net.last_error ? thd->net.last_error : ""); thd->query_error= 1; break; } @@ -6079,9 +6080,10 @@ int Rows_log_event::do_apply_event(RELAY_LOG_INFO const *rli) { /* error has occured during the transaction */ slave_print_msg(ERROR_LEVEL, rli, thd->net.last_errno, "Error in %s event: error during transaction execution " - "on table %s.%s", + "on table %s.%s. %s", get_type_str(), table->s->db.str, - table->s->table_name.str); + table->s->table_name.str, + thd->net.last_error ? thd->net.last_error : ""); /* If one day we honour --skip-slave-errors in row-based replication, and @@ -6997,7 +6999,12 @@ replace_record(THD *thd, TABLE *table, } if ((keynum= table->file->get_dup_key(error)) < 0) { - /* We failed to retrieve the duplicate key */ + table->file->print_error(error, MYF(0)); + /* + We failed to retrieve the duplicate key + - either because the error was not "duplicate key" error + - or because the information which key is not available + */ DBUG_RETURN(error); } From ba6c552b9b1dbab71c49e5c17b25bb09fb4c048f Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Jul 2007 09:35:27 +0200 Subject: [PATCH 8/8] Bug #29570 - correct result files --- mysql-test/r/rpl_row_tabledefs_2myisam.result | 2 +- mysql-test/r/rpl_row_tabledefs_3innodb.result | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/rpl_row_tabledefs_2myisam.result b/mysql-test/r/rpl_row_tabledefs_2myisam.result index 4eca19ff098..e41f8be055b 100644 --- a/mysql-test/r/rpl_row_tabledefs_2myisam.result +++ b/mysql-test/r/rpl_row_tabledefs_2myisam.result @@ -123,7 +123,7 @@ Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno 1105 -Last_Error Error in Write_rows event: error during transaction execution on table test.t1_nodef +Last_Error Error in Write_rows event: error during transaction execution on table test.t1_nodef. Unknown error Skip_Counter 0 Exec_Master_Log_Pos # Relay_Log_Space # diff --git a/mysql-test/r/rpl_row_tabledefs_3innodb.result b/mysql-test/r/rpl_row_tabledefs_3innodb.result index 687108e17e5..72c088d5a6b 100644 --- a/mysql-test/r/rpl_row_tabledefs_3innodb.result +++ b/mysql-test/r/rpl_row_tabledefs_3innodb.result @@ -123,7 +123,7 @@ Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno 1105 -Last_Error Error in Write_rows event: error during transaction execution on table test.t1_nodef +Last_Error Error in Write_rows event: error during transaction execution on table test.t1_nodef. Unknown error Skip_Counter 0 Exec_Master_Log_Pos # Relay_Log_Space #