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

📄 ndbdictionaryimpl.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  m_globalHash->drop(&impl);  m_globalHash->unlock();  DBUG_RETURN(0);}intNdbDictionaryImpl::removeCachedObject(NdbTableImpl & impl){  const char * internalTableName = impl.m_internalName.c_str();  m_localHash.drop(internalTableName);    m_globalHash->lock();  m_globalHash->release(&impl);  m_globalHash->unlock();  return 0;}/***************************************************************** * Get index info */NdbIndexImpl*NdbDictionaryImpl::getIndexImpl(const char * externalName,				const BaseString& internalName){  Ndb_local_table_info * info = get_local_table_info(internalName,						     false);  if(info == 0){    m_error.code = 4243;    return 0;  }  NdbTableImpl * tab = info->m_table_impl;  if(tab->m_indexType == NdbDictionary::Index::Undefined){    // Not an index    m_error.code = 4243;    return 0;  }  NdbTableImpl* prim = getTable(tab->m_primaryTable.c_str());  if(prim == 0){    m_error.code = 4243;    return 0;  }  /**   * Create index impl   */  NdbIndexImpl* idx;  if(NdbDictInterface::create_index_obj_from_table(&idx, tab, prim) == 0){    idx->m_table = tab;    idx->m_externalName.assign(externalName);    idx->m_internalName.assign(internalName);    // TODO Assign idx to tab->m_index    // Don't do it right now since assign can't asign a table with index    // tab->m_index = idx;    return idx;  }  return 0;}intNdbDictInterface::create_index_obj_from_table(NdbIndexImpl** dst,					      NdbTableImpl* tab,					      const NdbTableImpl* prim){  NdbIndexImpl *idx = new NdbIndexImpl();  idx->m_version = tab->m_version;  idx->m_status = tab->m_status;  idx->m_indexId = tab->m_tableId;  idx->m_externalName.assign(tab->getName());  idx->m_tableName.assign(prim->m_externalName);  NdbDictionary::Index::Type type = idx->m_type = tab->m_indexType;  idx->m_logging = tab->m_logging;  // skip last attribute (NDB$PK or NDB$TNODE)  const Uint32 distKeys = prim->m_noOfDistributionKeys;  Uint32 keyCount = (distKeys ? distKeys : prim->m_noOfKeys);  unsigned i;  for(i = 0; i+1<tab->m_columns.size(); i++){    NdbColumnImpl* org = tab->m_columns[i];    NdbColumnImpl* col = new NdbColumnImpl;    // Copy column definition    *col = * org;    idx->m_columns.push_back(col);    /**     * reverse map     */    const NdbColumnImpl* primCol = prim->getColumn(col->getName());    int key_id = primCol->getColumnNo();    int fill = -1;    idx->m_key_ids.fill(key_id, fill);    idx->m_key_ids[key_id] = i;    col->m_keyInfoPos = key_id;    if(type == NdbDictionary::Index::OrderedIndex &&        (primCol->m_distributionKey ||	(distKeys == 0 && primCol->getPrimaryKey())))    {      keyCount--;      org->m_distributionKey = 1;    }  }  if(keyCount == 0)  {    tab->m_noOfDistributionKeys = (distKeys ? distKeys : prim->m_noOfKeys);  }  else   {    for(i = 0; i+1<tab->m_columns.size(); i++)      tab->m_columns[i]->m_distributionKey = 0;  }  * dst = idx;  return 0;}/***************************************************************** * Create index */intNdbDictionaryImpl::createIndex(NdbIndexImpl &ix){  NdbTableImpl* tab = getTable(ix.getTable());  if(tab == 0){    m_error.code = 4249;    return -1;  }    return m_receiver.createIndex(m_ndb, ix, * tab);}int NdbDictInterface::createIndex(Ndb & ndb,			      NdbIndexImpl & impl, 			      const NdbTableImpl & table){  //validate();  //aggregate();  unsigned i, err;  UtilBufferWriter w(m_buffer);  const size_t len = strlen(impl.m_externalName.c_str()) + 1;  if(len > MAX_TAB_NAME_SIZE) {    m_error.code = 4241;    return -1;  }  const BaseString internalName(    ndb.internalize_index_name(&table, impl.getName()));  impl.m_internalName.assign(internalName);  w.add(DictTabInfo::TableName, internalName.c_str());  w.add(DictTabInfo::TableLoggedFlag, impl.m_logging);  NdbApiSignal tSignal(m_reference);  tSignal.theReceiversBlockNumber = DBDICT;  tSignal.theVerId_signalNumber   = GSN_CREATE_INDX_REQ;  tSignal.theLength = CreateIndxReq::SignalLength;    CreateIndxReq * const req = CAST_PTR(CreateIndxReq, tSignal.getDataPtrSend());    req->setUserRef(m_reference);  req->setConnectionPtr(0);  req->setRequestType(CreateIndxReq::RT_USER);    Uint32 it = getKernelConstant(impl.m_type,				indexTypeMapping,				DictTabInfo::UndefTableType);    if(it == DictTabInfo::UndefTableType){    m_error.code = 4250;    return -1;  }  req->setIndexType((DictTabInfo::TableType) it);    req->setTableId(table.m_tableId);  req->setOnline(true);  AttributeList attributeList;  attributeList.sz = impl.m_columns.size();  for(i = 0; i<attributeList.sz; i++){    const NdbColumnImpl* col =       table.getColumn(impl.m_columns[i]->m_name.c_str());    if(col == 0){      m_error.code = 4247;      return -1;    }    // Copy column definition    *impl.m_columns[i] = *col;    // index key type check    if (it == DictTabInfo::UniqueHashIndex &&        (err = NdbSqlUtil::check_column_for_hash_index(col->m_type, col->m_cs))        ||        it == DictTabInfo::OrderedIndex &&        (err = NdbSqlUtil::check_column_for_ordered_index(col->m_type, col->m_cs)))    {      m_error.code = err;      return -1;    }    attributeList.id[i] = col->m_attrId;  }  LinearSectionPtr ptr[2];  ptr[0].p = (Uint32*)&attributeList;  ptr[0].sz = 1 + attributeList.sz;  ptr[1].p = (Uint32*)m_buffer.get_data();  ptr[1].sz = m_buffer.length() >> 2;                //BUG?  return createIndex(&tSignal, ptr);}intNdbDictInterface::createIndex(NdbApiSignal* signal, 			      LinearSectionPtr ptr[3]){  const int noErrCodes = 2;  int errCodes[noErrCodes] = {CreateIndxRef::Busy, CreateIndxRef::NotMaster};  return dictSignal(signal,ptr,2,		    1 /*use masternode id*/,		    100,		    WAIT_CREATE_INDX_REQ,		    -1,		    errCodes,noErrCodes);}voidNdbDictInterface::execCREATE_INDX_CONF(NdbApiSignal * signal,				       LinearSectionPtr ptr[3]){  //CreateTableConf* const conf = CAST_CONSTPTR(CreateTableConf, signal->getDataPtr());    m_waiter.signal(NO_WAIT);  }voidNdbDictInterface::execCREATE_INDX_REF(NdbApiSignal * signal,				      LinearSectionPtr ptr[3]){  const CreateIndxRef* const ref = CAST_CONSTPTR(CreateIndxRef, signal->getDataPtr());  m_error.code = ref->getErrorCode();  if(m_error.code == ref->NotMaster)    m_masterNodeId= ref->masterNodeId;  m_waiter.signal(NO_WAIT);  }/***************************************************************** * Drop index */intNdbDictionaryImpl::dropIndex(const char * indexName, 			     const char * tableName){  NdbIndexImpl * idx = getIndex(indexName, tableName);  if (idx == 0) {    m_error.code = 4243;    return -1;  }  int ret = dropIndex(*idx, tableName);  // If index stored in cache is incompatible with the one in the kernel  // we must clear the cache and try again  if (ret == INCOMPATIBLE_VERSION) {    const BaseString internalIndexName((tableName)      ?      m_ndb.internalize_index_name(getTable(tableName), indexName)      :      m_ndb.internalize_table_name(indexName)); // Index is also a table    m_localHash.drop(internalIndexName.c_str());    m_globalHash->lock();    idx->m_table->m_status = NdbDictionary::Object::Invalid;    m_globalHash->drop(idx->m_table);    m_globalHash->unlock();    return dropIndex(indexName, tableName);  }  return ret;}intNdbDictionaryImpl::dropIndex(NdbIndexImpl & impl, const char * tableName){  const char * indexName = impl.getName();  if (tableName || m_ndb.usingFullyQualifiedNames()) {    NdbTableImpl * timpl = impl.m_table;        if (timpl == 0) {      m_error.code = 709;      return -1;    }    const BaseString internalIndexName((tableName)      ?      m_ndb.internalize_index_name(getTable(tableName), indexName)      :      m_ndb.internalize_table_name(indexName)); // Index is also a table    if(impl.m_status == NdbDictionary::Object::New){      return dropIndex(indexName, tableName);    }    int ret = m_receiver.dropIndex(impl, *timpl);    if(ret == 0){      m_localHash.drop(internalIndexName.c_str());      m_globalHash->lock();      impl.m_table->m_status = NdbDictionary::Object::Invalid;      m_globalHash->drop(impl.m_table);      m_globalHash->unlock();    }    return ret;  }  m_error.code = 4243;  return -1;}intNdbDictInterface::dropIndex(const NdbIndexImpl & impl, 			    const NdbTableImpl & timpl){  NdbApiSignal tSignal(m_reference);  tSignal.theReceiversBlockNumber = DBDICT;  tSignal.theVerId_signalNumber   = GSN_DROP_INDX_REQ;  tSignal.theLength = DropIndxReq::SignalLength;  DropIndxReq * const req = CAST_PTR(DropIndxReq, tSignal.getDataPtrSend());  req->setUserRef(m_reference);  req->setConnectionPtr(0);  req->setRequestType(DropIndxReq::RT_USER);  req->setTableId(~0);  // DICT overwrites  req->setIndexId(timpl.m_tableId);  req->setIndexVersion(timpl.m_version);  return dropIndex(&tSignal, 0);}intNdbDictInterface::dropIndex(NdbApiSignal* signal, LinearSectionPtr ptr[3]){  const int noErrCodes = 2;  int errCodes[noErrCodes] = {DropIndxRef::Busy, DropIndxRef::NotMaster};  int r = dictSignal(signal,NULL,0,		     1/*Use masternode id*/,		     100,		     WAIT_DROP_INDX_REQ,		     WAITFOR_RESPONSE_TIMEOUT,		     errCodes,noErrCodes);  if(m_error.code == DropIndxRef::InvalidIndexVersion) {    // Clear caches and try again    return INCOMPATIBLE_VERSION;  }  return r;}voidNdbDictInterface::execDROP_INDX_CONF(NdbApiSignal * signal,				       LinearSectionPtr ptr[3]){  m_waiter.signal(NO_WAIT);  }voidNdbDictInterface::execDROP_INDX_REF(NdbApiSignal * signal,				      LinearSectionPtr ptr[3]){  const DropIndxRef* const ref = CAST_CONSTPTR(DropIndxRef, signal->getDataPtr());  m_error.code = ref->getErrorCode();  if(m_error.code == ref->NotMaster)    m_masterNodeId= ref->masterNodeId;  m_waiter.signal(NO_WAIT);  }/***************************************************************** * Create event */intNdbDictionaryImpl::createEvent(NdbEventImpl & evnt){  int i;  NdbTableImpl* tab = getTable(evnt.getTableName());  if(tab == 0){#ifdef EVENT_DEBUG    ndbout_c("NdbDictionaryImpl::createEvent: table not found: %s",	     evnt.getTableName());#endif    return -1;  }  evnt.m_tableId = tab->m_tableId;  evnt.m_tableImpl = tab;#ifdef EVENT_DEBUG  ndbout_c("Event on tableId=%d", evnt.m_tableId);#endif  NdbTableImpl &table = *evnt.m_tableImpl;  int attributeList_sz = evnt.m_attrIds.size();  for (i = 0; i < attributeList_sz; i++) {    NdbColumnImpl *col_impl = table.getColumn(evnt.m_attrIds[i]);    if (col_impl) {      evnt.m_facade->addColumn(*(col_impl->m_facade));    } else {      ndbout_c("Attr id %u in table %s not found", evnt.m_attrIds[i],	       evnt.getTableName());      m_error.code= 4713;      return -1;    }  }  evnt.m_attrIds.clear();  attributeList_sz = evnt.m_columns.size();#ifdef EVENT_DEBUG  ndbout_c("creating event %s", evnt.m_externalName.c_str());  ndbout_c("no of columns %d", evnt.m_columns.size());#endif  int pk_count = 0;  evnt.m_attrListBitmask.clear();  for(i = 0; i<attributeList_sz; i++){    const NdbColumnImpl* col =       table.getColumn(evnt.m_columns[i]->m_name.c_str());    if(col == 0){      m_error.code= 4247;      return -1;    }    // Copy column definition    *evnt.m_columns[i] = *col;        if(col->m_pk){      pk_count++;    }        evnt.m_attrListBitmask.set(col->m_attrId);  }    // Sort index attributes according to primary table (using insertion sort)  for(i = 1; i < attributeList_sz; i++) {    NdbColumnImpl* temp = evnt.m_columns[i];    unsigned int j = i;    while((j > 0) && (evnt.m_columns[j - 1]->m_attrId > temp->m_attrId)) {      evnt.m_columns[j] = evnt.m_columns[j - 1];      j--;    }    evnt.m_columns[j] = temp;  }  // Check for illegal duplicate attributes  for(i = 1; i<attributeList_sz; i++) {    if (evnt.m_columns[i-1]->m_attrId == evnt.m_columns[i]->m_attrId) {      m_error.code= 4258;      return -1;    }  }  #ifdef EVENT_DEBUG  char buf[128] = {0};  evnt.m_attrListBitmask.getText(buf);  ndbout_c("createEvent: mask = %s", buf);#endif  // NdbDictInterface m_receiver;  return m_receiver.createEvent(m_ndb, evnt, 0 /* getFlag unset */);}intNdbDictInterface::createEvent(class Ndb & ndb,			      NdbEventImpl & evnt,			      int getFlag){  NdbApiSignal tSignal(m_reference);  tSignal.theReceiversBlockNumber = DBDICT;  tSignal.theVerId_signalNumber   = GSN_CREATE_EVNT_REQ;  if (getFlag)    tSignal.theLength = CreateEvntReq::SignalLengthGet;  else    tSignal.theLength = CreateEvntReq::SignalLengthCreate;  CreateEvntReq * const req = CAST_PTR(CreateEvntReq, tSignal.getDataPtrSend());    req->setUserRef(m_reference);  req->setUserData(0);  if (getFlag) {    // getting event from Dictionary    req->setRequestType(CreateEvntReq::RT_USER_GET);  } else {    // creating event in Dictionary    req->setRequestType(CreateEvntReq::RT_USER_CREATE);    req->setTableId(evnt.m_tableId);    req->setAttrListBitmask(evnt.m_attrListBitmask);    req->setEventType(evnt.mi_type);  }  UtilBufferWriter w(m_buffer);  const size_t len = strlen(evnt.m_externalName.c_str()) + 1;  if(len > MAX_TAB_NAME_SIZE) {    m_error.code= 4241;    retur

⌨️ 快捷键说明

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