⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ndbdictionaryimpl.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    }        m_error.code= 0;        m_waiter.m_node = aNodeId;    m_waiter.m_state = wst;    m_waiter.wait(theWait);    m_transporter->unlock_mutex();        // End of Protected area          if(m_waiter.m_state == NO_WAIT && m_error.code == 0){      // Normal return      DBUG_RETURN(0);    }        /**     * Handle error codes     */    if(m_waiter.m_state == WAIT_NODE_FAILURE)      continue;    if(m_waiter.m_state == WST_WAIT_TIMEOUT)    {      m_error.code = 4008;      DBUG_RETURN(-1);    }        if ( (temporaryMask & m_error.code) != 0 ) {      continue;    }    if (errcodes) {      int doContinue = 0;      for (int j=0; j < noerrcodes; j++)	if(m_error.code == errcodes[j]) {	  doContinue = 1;	  break;	}      if (doContinue)	continue;    }    DBUG_RETURN(-1);  }  DBUG_RETURN(-1);}#if 0/*  Get dictionary information for a table using table id as reference  DESCRIPTION    Sends a GET_TABINFOREQ signal containing the table id */NdbTableImpl *NdbDictInterface::getTable(int tableId, bool fullyQualifiedNames){  NdbApiSignal tSignal(m_reference);  GetTabInfoReq* const req = CAST_PTR(GetTabInfoReq, tSignal.getDataPtrSend());  req->senderRef = m_reference;  req->senderData = 0;  req->requestType =    GetTabInfoReq::RequestById | GetTabInfoReq::LongSignalConf;  req->tableId = tableId;  tSignal.theReceiversBlockNumber = DBDICT;  tSignal.theVerId_signalNumber   = GSN_GET_TABINFOREQ;  tSignal.theLength = GetTabInfoReq::SignalLength;  return getTable(&tSignal, 0, 0, fullyQualifiedNames);}#endif/*  Get dictionary information for a table using table name as the reference  DESCRIPTION    Send GET_TABINFOREQ signal with the table name in the first    long section part*/NdbTableImpl *NdbDictInterface::getTable(const BaseString& name, bool fullyQualifiedNames){  NdbApiSignal tSignal(m_reference);  GetTabInfoReq* const req = CAST_PTR(GetTabInfoReq, tSignal.getDataPtrSend());  const Uint32 namelen= name.length() + 1; // NULL terminated  const Uint32 namelen_words= (namelen + 3) >> 2; // Size in words  req->senderRef= m_reference;  req->senderData= 0;  req->requestType=    GetTabInfoReq::RequestByName | GetTabInfoReq::LongSignalConf;  req->tableNameLen= namelen;  tSignal.theReceiversBlockNumber= DBDICT;  tSignal.theVerId_signalNumber= GSN_GET_TABINFOREQ;  tSignal.theLength= GetTabInfoReq::SignalLength;  // Copy name to m_buffer to get a word sized buffer  m_buffer.clear();  m_buffer.grow(namelen_words*4+4);  m_buffer.append(name.c_str(), namelen);#ifndef IGNORE_VALGRIND_WARNINGS  Uint32 pad = 0;  m_buffer.append(&pad, 4);#endif    LinearSectionPtr ptr[1];  ptr[0].p= (Uint32*)m_buffer.get_data();  ptr[0].sz= namelen_words;  return getTable(&tSignal, ptr, 1, fullyQualifiedNames);}NdbTableImpl *NdbDictInterface::getTable(class NdbApiSignal * signal,			   LinearSectionPtr ptr[3],			   Uint32 noOfSections, bool fullyQualifiedNames){  int errCodes[] = {GetTabInfoRef::Busy };  int r = dictSignal(signal,ptr,noOfSections,		     0/*do not use masternode id*/,		     100,		     WAIT_GET_TAB_INFO_REQ,		     WAITFOR_RESPONSE_TIMEOUT,		     errCodes, 1);  if (r) return 0;  NdbTableImpl * rt = 0;  m_error.code= parseTableInfo(&rt, 			       (Uint32*)m_buffer.get_data(), 			       m_buffer.length() / 4, fullyQualifiedNames);  if (rt != 0)    rt->buildColumnHash();  return rt;}voidNdbDictInterface::execGET_TABINFO_CONF(NdbApiSignal * signal, 				       LinearSectionPtr ptr[3]){  const GetTabInfoConf* conf = CAST_CONSTPTR(GetTabInfoConf, signal->getDataPtr());  if(signal->isFirstFragment()){    m_fragmentId = signal->getFragmentId();    m_buffer.grow(4 * conf->totalLen);  } else {    if(m_fragmentId != signal->getFragmentId()){      abort();    }  }    const Uint32 i = GetTabInfoConf::DICT_TAB_INFO;  m_buffer.append(ptr[i].p, 4 * ptr[i].sz);  if(!signal->isLastFragment()){    return;  }      m_waiter.signal(NO_WAIT);}voidNdbDictInterface::execGET_TABINFO_REF(NdbApiSignal * signal,				      LinearSectionPtr ptr[3]){  const GetTabInfoRef* ref = CAST_CONSTPTR(GetTabInfoRef, signal->getDataPtr());  m_error.code= ref->errorCode;  m_waiter.signal(NO_WAIT);}/***************************************************************** * Pack/Unpack tables */struct ApiKernelMapping {  Int32 kernelConstant;  Int32 apiConstant;};Uint32getApiConstant(Int32 kernelConstant, const ApiKernelMapping map[], Uint32 def){  int i = 0;  while(map[i].kernelConstant != kernelConstant){    if(map[i].kernelConstant == -1 &&       map[i].apiConstant == -1){      return def;    }    i++;  }  return map[i].apiConstant;}Uint32getKernelConstant(Int32 apiConstant, const ApiKernelMapping map[], Uint32 def){  int i = 0;  while(map[i].apiConstant != apiConstant){    if(map[i].kernelConstant == -1 &&       map[i].apiConstant == -1){      return def;    }    i++;  }  return map[i].kernelConstant;}static constApiKernelMapping fragmentTypeMapping[] = {  { DictTabInfo::AllNodesSmallTable,  NdbDictionary::Object::FragAllSmall },  { DictTabInfo::AllNodesMediumTable, NdbDictionary::Object::FragAllMedium },  { DictTabInfo::AllNodesLargeTable,  NdbDictionary::Object::FragAllLarge },  { DictTabInfo::SingleFragment,      NdbDictionary::Object::FragSingle },  { -1, -1 }};static constApiKernelMappingobjectTypeMapping[] = {  { DictTabInfo::SystemTable,        NdbDictionary::Object::SystemTable },  { DictTabInfo::UserTable,          NdbDictionary::Object::UserTable },  { DictTabInfo::UniqueHashIndex,    NdbDictionary::Object::UniqueHashIndex },  { DictTabInfo::OrderedIndex,       NdbDictionary::Object::OrderedIndex },  { DictTabInfo::HashIndexTrigger,   NdbDictionary::Object::HashIndexTrigger },  { DictTabInfo::IndexTrigger,       NdbDictionary::Object::IndexTrigger },  { DictTabInfo::SubscriptionTrigger,NdbDictionary::Object::SubscriptionTrigger },  { DictTabInfo::ReadOnlyConstraint ,NdbDictionary::Object::ReadOnlyConstraint },  { -1, -1 }};static constApiKernelMappingobjectStateMapping[] = {  { DictTabInfo::StateOffline,       NdbDictionary::Object::StateOffline },  { DictTabInfo::StateBuilding,      NdbDictionary::Object::StateBuilding },  { DictTabInfo::StateDropping,      NdbDictionary::Object::StateDropping },  { DictTabInfo::StateOnline,        NdbDictionary::Object::StateOnline },  { DictTabInfo::StateBackup,        NdbDictionary::Object::StateBackup },  { DictTabInfo::StateBroken,        NdbDictionary::Object::StateBroken },   { -1, -1 }};static constApiKernelMappingobjectStoreMapping[] = {  { DictTabInfo::StoreTemporary,     NdbDictionary::Object::StoreTemporary },  { DictTabInfo::StorePermanent,     NdbDictionary::Object::StorePermanent },  { -1, -1 }};static constApiKernelMappingindexTypeMapping[] = {  { DictTabInfo::UniqueHashIndex,    NdbDictionary::Index::UniqueHashIndex },    { DictTabInfo::OrderedIndex,       NdbDictionary::Index::OrderedIndex },  { -1, -1 }};intNdbDictInterface::parseTableInfo(NdbTableImpl ** ret,				 const Uint32 * data, Uint32 len,				 bool fullyQualifiedNames){  DBUG_ENTER("NdbDictInterface::parseTableInfo");  SimplePropertiesLinearReader it(data, len);  DictTabInfo::Table tableDesc; tableDesc.init();  SimpleProperties::UnpackStatus s;  s = SimpleProperties::unpack(it, &tableDesc, 			       DictTabInfo::TableMapping, 			       DictTabInfo::TableMappingSize, 			       true, true);    if(s != SimpleProperties::Break){    DBUG_RETURN(703);  }  const char * internalName = tableDesc.TableName;  const char * externalName = Ndb::externalizeTableName(internalName, fullyQualifiedNames);  NdbTableImpl * impl = new NdbTableImpl();  impl->m_tableId = tableDesc.TableId;  impl->m_version = tableDesc.TableVersion;  impl->m_status = NdbDictionary::Object::Retrieved;  impl->m_internalName.assign(internalName);  impl->m_externalName.assign(externalName);  impl->m_frm.assign(tableDesc.FrmData, tableDesc.FrmLen);    impl->m_fragmentType = (NdbDictionary::Object::FragmentType)    getApiConstant(tableDesc.FragmentType, 		   fragmentTypeMapping, 		   (Uint32)NdbDictionary::Object::FragUndefined);    impl->m_logging = tableDesc.TableLoggedFlag;  impl->m_kvalue = tableDesc.TableKValue;  impl->m_minLoadFactor = tableDesc.MinLoadFactor;  impl->m_maxLoadFactor = tableDesc.MaxLoadFactor;  impl->m_indexType = (NdbDictionary::Index::Type)    getApiConstant(tableDesc.TableType,		   indexTypeMapping,		   NdbDictionary::Index::Undefined);    if(impl->m_indexType == NdbDictionary::Index::Undefined){  } else {    const char * externalPrimary =       Ndb::externalizeTableName(tableDesc.PrimaryTable, fullyQualifiedNames);    impl->m_primaryTable.assign(externalPrimary);  }    Uint32 keyInfoPos = 0;  Uint32 keyCount = 0;  Uint32 blobCount = 0;  Uint32 distKeys = 0;    Uint32 i;  for(i = 0; i < tableDesc.NoOfAttributes; i++) {    DictTabInfo::Attribute attrDesc; attrDesc.init();    s = SimpleProperties::unpack(it, 				 &attrDesc, 				 DictTabInfo::AttributeMapping, 				 DictTabInfo::AttributeMappingSize, 				 true, true);    if(s != SimpleProperties::Break){      delete impl;      DBUG_RETURN(703);    }        NdbColumnImpl * col = new NdbColumnImpl();    col->m_attrId = attrDesc.AttributeId;    col->setName(attrDesc.AttributeName);    // check type and compute attribute size and array size    if (! attrDesc.translateExtType()) {      delete impl;      DBUG_RETURN(703);    }    col->m_type = (NdbDictionary::Column::Type)attrDesc.AttributeExtType;    col->m_precision = (attrDesc.AttributeExtPrecision & 0xFFFF);    col->m_scale = attrDesc.AttributeExtScale;    col->m_length = attrDesc.AttributeExtLength;    // charset in upper half of precision    unsigned cs_number = (attrDesc.AttributeExtPrecision >> 16);    // charset is defined exactly for char types    if (col->getCharType() != (cs_number != 0)) {      delete impl;      DBUG_RETURN(703);    }    if (col->getCharType()) {      col->m_cs = get_charset(cs_number, MYF(0));      if (col->m_cs == NULL) {        delete impl;        DBUG_RETURN(743);      }    }    col->m_attrSize = (1 << attrDesc.AttributeSize) / 8;    col->m_arraySize = attrDesc.AttributeArraySize;    if(attrDesc.AttributeSize == 0)    {      col->m_attrSize = 4;      col->m_arraySize = (attrDesc.AttributeArraySize + 31) >> 5;    }        col->m_pk = attrDesc.AttributeKeyFlag;    col->m_distributionKey = attrDesc.AttributeDKey;    col->m_nullable = attrDesc.AttributeNullableFlag;    col->m_autoIncrement = (attrDesc.AttributeAutoIncrement ? true : false);    col->m_autoIncrementInitialValue = ~0;    col->m_defaultValue.assign(attrDesc.AttributeDefaultValue);    if(attrDesc.AttributeKeyFlag){      col->m_keyInfoPos = keyInfoPos + 1;      keyInfoPos += ((col->m_attrSize * col->m_arraySize + 3) / 4);      keyCount++;            if(attrDesc.AttributeDKey)	distKeys++;    } else {      col->m_keyInfoPos = 0;    }    if (col->getBlobType())      blobCount++;    NdbColumnImpl * null = 0;    impl->m_columns.fill(attrDesc.AttributeId, null);    if(impl->m_columns[attrDesc.AttributeId] != 0){      delete col;      delete impl;      DBUG_RETURN(703);    }    impl->m_columns[attrDesc.AttributeId] = col;    it.next();  }  impl->m_noOfKeys = keyCount;  impl->m_keyLenInWords = keyInfoPos;  impl->m_noOfBlobs = blobCount;  impl->m_noOfDistributionKeys = distKeys;  if(tableDesc.FragmentDataLen > 0)  {    Uint32 replicaCount = tableDesc.FragmentData[0];    Uint32 fragCount = tableDesc.FragmentData[1];    impl->m_replicaCount = replicaCount;    impl->m_fragmentCount = fragCount;    for(i = 0; i<(fragCount*replicaCount); i++)    {      impl->m_fragments.push_back(tableDesc.FragmentData[i+2]);    }    Uint32 topBit = (1 << 31);    for(; topBit && !(fragCount & topBit); ){      topBit >>= 1;    }    impl->m_hashValueMask = topBit - 1;    impl->m_hashpointerValue = fragCount - (impl->m_hashValueMask + 1);  }  else  {    impl->m_fragmentCount = tableDesc.FragmentCount;    impl->m_replicaCount = 0;    impl->m_hashValueMask = 0;    impl->m_hashpointerValue = 0;  }  if(distKeys == 0)  {    for(i = 0; i < tableDesc.NoOfAttributes; i++)    {      if(impl->m_columns[i]->getPrimaryKey())	impl->m_columns[i]->m_distributionKey = true;    }  }    * ret = impl;  DBUG_RETURN(0);}/***************************************************************** * Create table and alter table */intNdbDictionaryImpl::createTable(NdbTableImpl &t){   if (m_receiver.createTable(m_ndb, t) != 0)    return -1;  if (t.m_noOfBlobs == 0)    return 0;  // update table def from DICT  Ndb_local_table_info *info=    get_local_table_info(t.m_internalName,false);  if (info == NULL) {    m_error.code= 709;    return -1;  }  if (createBlobTables(*(info->m_table_impl)) != 0) {    int save_code = m_error.code;    (void)dropTable(t);    m_error.code= save_code;    return -1;  }  return 0;}intNdbDictionaryImpl::createBlobTables(NdbTableImpl &t){  for (unsigned i = 0; i < t.m_columns.size(); i++) {    NdbColumnImpl & c = *t.m_columns[i];    if (! c.getBlobType() || c.getPartSize() == 0)      continue;    NdbTableImpl bt;    NdbBlob::getBlobTable(bt, &t, &c);    if (createTable(bt) != 0)      return -1;    // Save BLOB table handle    Ndb_local_table_info *info=      get_local_table_info(bt.m_internalName, false);    if (info == 0) {      return -1;    }    c.m_blobTable = info->m_table_impl;  }    return 0;}intNdbDictionaryImpl::addBlobTables(NdbTableImpl &t){  unsigned n= t.m_noOfBlobs;  // optimized for blob column being the last one  // and not looking for more than one if not neccessary  for (unsigned i = t.m_columns.size(); i > 0 && n > 0;) {    i--;    NdbColumnImpl & c = *t.m_columns[i];    if (! c.getBlobType() || c.getPartSize() == 0)      continue;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -